From 9afa5adc5ef41c154efa9002193d4386297e79f8 Mon Sep 17 00:00:00 2001 From: Aaron Zielstorff Date: Fri, 6 Dec 2024 23:29:04 +0100 Subject: [PATCH] Adds GitHub action to automatically push snapshot images to dockerhub (#562) * Adds workflow for automatic push of snapshot images on PR merge * adds personal repo for push testing * fix the content path * removes build args * fixes file path * Adds registries to docker push action * fixes registry pathes * Adds final name as build arg * adds fix to determine final name * adds fix to final name * adds fix for registry jar file location * fix the modules root * updates dockerfiles * fixes path to registry jar * applies another fix to jar path * adss docker namespace variable --- .github/workflows/docker-snapshot-release.yml | 138 ++++++++++++++++++ .../src/main/docker/Dockerfile | 5 +- .../src/main/docker/Dockerfile | 5 +- .../src/main/docker/Dockerfile | 5 +- .../src/main/docker/Dockerfile | 5 +- .../src/main/docker/Dockerfile | 5 +- .../src/main/docker/Dockerfile | 5 +- .../src/main/docker/Dockerfile | 5 +- .../src/main/docker/Dockerfile | 5 +- 9 files changed, 162 insertions(+), 16 deletions(-) create mode 100644 .github/workflows/docker-snapshot-release.yml diff --git a/.github/workflows/docker-snapshot-release.yml b/.github/workflows/docker-snapshot-release.yml new file mode 100644 index 000000000..1428e5f82 --- /dev/null +++ b/.github/workflows/docker-snapshot-release.yml @@ -0,0 +1,138 @@ +name: Build and Push Docker Images on PR Merge + +on: + push: + branches: + - main + paths-ignore: + - '.github/ISSUE_TEMPLATE/**' + - '.github/CODE_OF_CONDUCT.md' + - '.github/CODING_CONVENTIONS.md' + - '.github/CONTRIBUTING.md' + - '.github/dependabot.yml' + - '.github/pull_request_template.md' + - '.github/SECURITY.md' + - 'docs/**' + - 'examples/**' + - 'README.md' + - '.gitattributes' + - '.gitignore' + - 'LICENSE' + - 'NOTICE' + +env: + DOCKER_NAMESPACE: eclipsebasyx + +jobs: + build-and-push-prerelease: + runs-on: ubuntu-latest + strategy: + matrix: + include: + - name: aas-environment + path: basyx.aasenvironment/basyx.aasenvironment.component + - name: aas-repository + path: basyx.aasrepository/basyx.aasrepository.component + - name: submodel-repository + path: basyx.submodelrepository/basyx.submodelrepository.component + - name: conceptdescription-repository + path: basyx.conceptdescriptionrepository/basyx.conceptdescriptionrepository.component + - name: aas-discovery + path: basyx.aasdiscoveryservice/basyx.aasdiscoveryservice.component + - name: aasxfileserver + path: basyx.aasxfileserver/basyx.aasxfileserver.component + - name: aas-registry-kafka-mem + path: basyx.aasregistry/basyx.aasregistry-service-release-kafka-mem/src/main/docker + - name: aas-registry-kafka-mongodb + path: basyx.aasregistry/basyx.aasregistry-service-release-kafka-mongodb/src/main/docker + - name: aas-registry-log-mem + path: basyx.aasregistry/basyx.aasregistry-service-release-log-mem/src/main/docker + - name: aas-registry-log-mongodb + path: basyx.aasregistry/basyx.aasregistry-service-release-log-mongodb/src/main/docker + - name: submodel-registry-kafka-mem + path: basyx.submodelregistry/basyx.submodelregistry-service-release-kafka-mem/src/main/docker + - name: submodel-registry-kafka-mongodb + path: basyx.submodelregistry/basyx.submodelregistry-service-release-kafka-mongodb/src/main/docker + - name: submodel-registry-log-mem + path: basyx.submodelregistry/basyx.submodelregistry-service-release-log-mem/src/main/docker + - name: submodel-registry-log-mongodb + path: basyx.submodelregistry/basyx.submodelregistry-service-release-log-mongodb/src/main/docker + + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + with: + platforms: linux/amd64,linux/arm64,linux/arm/v7 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_HUB_USER }} + password: ${{ secrets.DOCKER_HUB_TOKEN }} + + - name: Set up JDK 17 + uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + cache: maven + + # Build the project + # For registry modules, we activate the dockerbuild profile and specify the module with --pl + - name: Build BaSyx + run: | + if [[ "${{ matrix.name }}" == *"registry"* ]]; then + # Derive the module's artifactId from the path + module_root=$(dirname "$(dirname "$(dirname "${{ matrix.path }}")")") + artifact_id=$(basename "$module_root") + # Run with dockerbuild profile and namespace + mvn clean install -DskipTests -Pdockerbuild "-Ddocker.namespace=${{ env.DOCKER_NAMESPACE }}" --pl "org.eclipse.digitaltwin.basyx:${artifact_id}" + else + mvn clean install -DskipTests + fi + + - name: Prepare Registry JAR for Docker + if: contains(matrix.name, 'registry') + run: | + # Go three levels up from src/main/docker to get the module root + module_root=$(dirname "$(dirname "$(dirname "${{ matrix.path }}")")") + + # Adjust the path to where the dockerbuild profile places the JAR + JAR_FILE=$(ls "$module_root/target/docker/${{ env.DOCKER_NAMESPACE }}/${{ matrix.name }}/2.0.0-SNAPSHOT/build/maven/"*.jar | head -n 1) + if [ -z "$JAR_FILE" ]; then + echo "No repackaged JAR found in $module_root/target/docker/${{ env.DOCKER_NAMESPACE }}/${{ matrix.name }}/2.0.0-SNAPSHOT/build/maven. Check your build." + exit 1 + fi + + # Create the maven directory inside the Docker context and copy the JAR there + mkdir -p "${{ matrix.path }}/maven" + cp "$JAR_FILE" "${{ matrix.path }}/maven/" + + # Extract the final name without .jar extension + FINAL_NAME=$(basename "$JAR_FILE" .jar) + echo "FINAL_ARGS=FINAL_NAME=${FINAL_NAME}" >> $GITHUB_ENV + + - name: No-Op for Non-Registry Modules + if: "!contains(matrix.name, 'registry')" + run: echo "FINAL_ARGS=" >> $GITHUB_ENV + + - name: Build and Push Docker Image + uses: docker/build-push-action@v6 + with: + context: ${{ matrix.path }} + file: ${{ matrix.path }}/Dockerfile + push: true + platforms: linux/amd64,linux/arm64,linux/arm/v7 + tags: | + ${{ env.DOCKER_NAMESPACE }}/${{ matrix.name }}:2.0.0-SNAPSHOT + build-args: ${{ env.FINAL_ARGS }} + + - name: Verify Docker Image + run: | + docker pull ${{ env.DOCKER_NAMESPACE }}/${{ matrix.name }}:2.0.0-SNAPSHOT diff --git a/basyx.aasregistry/basyx.aasregistry-service-release-kafka-mem/src/main/docker/Dockerfile b/basyx.aasregistry/basyx.aasregistry-service-release-kafka-mem/src/main/docker/Dockerfile index bbddc1da9..a5cb3a888 100644 --- a/basyx.aasregistry/basyx.aasregistry-service-release-kafka-mem/src/main/docker/Dockerfile +++ b/basyx.aasregistry/basyx.aasregistry-service-release-kafka-mem/src/main/docker/Dockerfile @@ -1,6 +1,7 @@ FROM eclipse-temurin:17 as builder -COPY maven/${project.build.finalName}.jar ./ -RUN java -Djarmode=layertools -jar ${project.build.finalName}.jar extract +ARG FINAL_NAME=${project.build.finalName} +COPY maven/${FINAL_NAME}.jar ./ +RUN java -Djarmode=layertools -jar ${FINAL_NAME}.jar extract FROM eclipse-temurin:17 RUN mkdir /workspace diff --git a/basyx.aasregistry/basyx.aasregistry-service-release-kafka-mongodb/src/main/docker/Dockerfile b/basyx.aasregistry/basyx.aasregistry-service-release-kafka-mongodb/src/main/docker/Dockerfile index 7e157b1ca..d408d753e 100644 --- a/basyx.aasregistry/basyx.aasregistry-service-release-kafka-mongodb/src/main/docker/Dockerfile +++ b/basyx.aasregistry/basyx.aasregistry-service-release-kafka-mongodb/src/main/docker/Dockerfile @@ -1,6 +1,7 @@ FROM eclipse-temurin:17 as builder -COPY maven/${project.build.finalName}.jar ./ -RUN java -Djarmode=layertools -jar ${project.build.finalName}.jar extract +ARG FINAL_NAME=${project.build.finalName} +COPY maven/${FINAL_NAME}.jar ./ +RUN java -Djarmode=layertools -jar ${FINAL_NAME}.jar extract FROM eclipse-temurin:17 RUN mkdir /workspace diff --git a/basyx.aasregistry/basyx.aasregistry-service-release-log-mem/src/main/docker/Dockerfile b/basyx.aasregistry/basyx.aasregistry-service-release-log-mem/src/main/docker/Dockerfile index d2f36e7ad..8ba0cf83a 100644 --- a/basyx.aasregistry/basyx.aasregistry-service-release-log-mem/src/main/docker/Dockerfile +++ b/basyx.aasregistry/basyx.aasregistry-service-release-log-mem/src/main/docker/Dockerfile @@ -1,6 +1,7 @@ FROM eclipse-temurin:17 as builder -COPY maven/${project.build.finalName}.jar ./ -RUN java -Djarmode=layertools -jar ${project.build.finalName}.jar extract +ARG FINAL_NAME=${project.build.finalName} +COPY maven/${FINAL_NAME}.jar ./ +RUN java -Djarmode=layertools -jar ${FINAL_NAME}.jar extract FROM eclipse-temurin:17 RUN mkdir /workspace diff --git a/basyx.aasregistry/basyx.aasregistry-service-release-log-mongodb/src/main/docker/Dockerfile b/basyx.aasregistry/basyx.aasregistry-service-release-log-mongodb/src/main/docker/Dockerfile index 3acf47076..df632dacc 100644 --- a/basyx.aasregistry/basyx.aasregistry-service-release-log-mongodb/src/main/docker/Dockerfile +++ b/basyx.aasregistry/basyx.aasregistry-service-release-log-mongodb/src/main/docker/Dockerfile @@ -1,6 +1,7 @@ FROM eclipse-temurin:17 as builder -COPY maven/${project.build.finalName}.jar ./ -RUN java -Djarmode=layertools -jar ${project.build.finalName}.jar extract +ARG FINAL_NAME=${project.build.finalName} +COPY maven/${FINAL_NAME}.jar ./ +RUN java -Djarmode=layertools -jar ${FINAL_NAME}.jar extract FROM eclipse-temurin:17 RUN mkdir /workspace diff --git a/basyx.submodelregistry/basyx.submodelregistry-service-release-kafka-mem/src/main/docker/Dockerfile b/basyx.submodelregistry/basyx.submodelregistry-service-release-kafka-mem/src/main/docker/Dockerfile index bbddc1da9..a5cb3a888 100644 --- a/basyx.submodelregistry/basyx.submodelregistry-service-release-kafka-mem/src/main/docker/Dockerfile +++ b/basyx.submodelregistry/basyx.submodelregistry-service-release-kafka-mem/src/main/docker/Dockerfile @@ -1,6 +1,7 @@ FROM eclipse-temurin:17 as builder -COPY maven/${project.build.finalName}.jar ./ -RUN java -Djarmode=layertools -jar ${project.build.finalName}.jar extract +ARG FINAL_NAME=${project.build.finalName} +COPY maven/${FINAL_NAME}.jar ./ +RUN java -Djarmode=layertools -jar ${FINAL_NAME}.jar extract FROM eclipse-temurin:17 RUN mkdir /workspace diff --git a/basyx.submodelregistry/basyx.submodelregistry-service-release-kafka-mongodb/src/main/docker/Dockerfile b/basyx.submodelregistry/basyx.submodelregistry-service-release-kafka-mongodb/src/main/docker/Dockerfile index 7e157b1ca..d408d753e 100644 --- a/basyx.submodelregistry/basyx.submodelregistry-service-release-kafka-mongodb/src/main/docker/Dockerfile +++ b/basyx.submodelregistry/basyx.submodelregistry-service-release-kafka-mongodb/src/main/docker/Dockerfile @@ -1,6 +1,7 @@ FROM eclipse-temurin:17 as builder -COPY maven/${project.build.finalName}.jar ./ -RUN java -Djarmode=layertools -jar ${project.build.finalName}.jar extract +ARG FINAL_NAME=${project.build.finalName} +COPY maven/${FINAL_NAME}.jar ./ +RUN java -Djarmode=layertools -jar ${FINAL_NAME}.jar extract FROM eclipse-temurin:17 RUN mkdir /workspace diff --git a/basyx.submodelregistry/basyx.submodelregistry-service-release-log-mem/src/main/docker/Dockerfile b/basyx.submodelregistry/basyx.submodelregistry-service-release-log-mem/src/main/docker/Dockerfile index d2f36e7ad..8ba0cf83a 100644 --- a/basyx.submodelregistry/basyx.submodelregistry-service-release-log-mem/src/main/docker/Dockerfile +++ b/basyx.submodelregistry/basyx.submodelregistry-service-release-log-mem/src/main/docker/Dockerfile @@ -1,6 +1,7 @@ FROM eclipse-temurin:17 as builder -COPY maven/${project.build.finalName}.jar ./ -RUN java -Djarmode=layertools -jar ${project.build.finalName}.jar extract +ARG FINAL_NAME=${project.build.finalName} +COPY maven/${FINAL_NAME}.jar ./ +RUN java -Djarmode=layertools -jar ${FINAL_NAME}.jar extract FROM eclipse-temurin:17 RUN mkdir /workspace diff --git a/basyx.submodelregistry/basyx.submodelregistry-service-release-log-mongodb/src/main/docker/Dockerfile b/basyx.submodelregistry/basyx.submodelregistry-service-release-log-mongodb/src/main/docker/Dockerfile index 3acf47076..df632dacc 100644 --- a/basyx.submodelregistry/basyx.submodelregistry-service-release-log-mongodb/src/main/docker/Dockerfile +++ b/basyx.submodelregistry/basyx.submodelregistry-service-release-log-mongodb/src/main/docker/Dockerfile @@ -1,6 +1,7 @@ FROM eclipse-temurin:17 as builder -COPY maven/${project.build.finalName}.jar ./ -RUN java -Djarmode=layertools -jar ${project.build.finalName}.jar extract +ARG FINAL_NAME=${project.build.finalName} +COPY maven/${FINAL_NAME}.jar ./ +RUN java -Djarmode=layertools -jar ${FINAL_NAME}.jar extract FROM eclipse-temurin:17 RUN mkdir /workspace