From 2b28b7cd954aaf1a073c6ddf9f0e88fdf8a43829 Mon Sep 17 00:00:00 2001 From: Felix Date: Sat, 21 Sep 2024 14:20:46 +0200 Subject: [PATCH] Using seperate build and deploy images --- .github/workflows/buildAndPushImage.yml | 32 +++++++++++++++++++------ Dockerfile | 26 ++++++++++++++------ 2 files changed, 44 insertions(+), 14 deletions(-) diff --git a/.github/workflows/buildAndPushImage.yml b/.github/workflows/buildAndPushImage.yml index 5f4e5bc..99e996a 100644 --- a/.github/workflows/buildAndPushImage.yml +++ b/.github/workflows/buildAndPushImage.yml @@ -22,12 +22,30 @@ jobs: - uses: actions/checkout@v4 with: submodules: 'true' - - - name: Login to GitHub Container Registry - run: echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u well5a --password-stdin - - name: Build the Docker image - run: docker build . --file Dockerfile --tag $IMAGE_URL/$IMAGE_NAME:$IMAGE_TAG + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + with: + platforms: linux/amd64 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + with: + platforms: linux/amd64 + + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} - - name: Push the Docker image - run: docker push $IMAGE_URL/$IMAGE_NAME:$IMAGE_TAG + - name: Build and push + uses: docker/build-push-action@v6 + with: + context: . + file: ./Dockerfile + platforms: linux/amd64 + push: true + tags: ${{ env.IMAGE_URL }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} + provenance: false diff --git a/Dockerfile b/Dockerfile index 9952e3b..07b68c0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,28 @@ -FROM alpine:latest +# Stage 1: Build the application using Maven with Eclipse Temurin JDK 11 +FROM maven:3.8.6-eclipse-temurin-11 AS build -RUN apk upgrade --no-cache \ - && apk add --no-cache bash curl gcompat libstdc++ maven openjdk11 - -RUN mkdir -p /app/target +# Set the working directory for the build stage WORKDIR /app +# Copy the Maven project file and source code into the container COPY pom.xml . COPY src ./src COPY mps-transformation-terraform ./mps-transformation-terraform + +# Create the necessary directory for transformation input RUN mkdir -p /app/mps-transformation-terraform/transformationInput -RUN mvn clean package -DskipTests +# Build the project, using multiple threads and skipping tests +RUN mvn -T 2C -q clean package -DskipTests + +# Stage 2: Create a minimal runtime image using OpenJDK 11 JRE +FROM openjdk:11-jre-slim + +# Set the working directory for the runtime stage +WORKDIR /app + +# Copy all built files from the build stage to the runtime stage +COPY --from=build /app /app -CMD java -jar target/terraform-mps-plugin-0.0.1-SNAPSHOT.jar +# Set the command to run the application +CMD ["java", "-jar", "/app/target/terraform-mps-plugin-0.0.1-SNAPSHOT.jar"]