|
| 1 | +name: Build and Push Docker Images on Release |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + |
| 7 | +env: |
| 8 | + DOCKER_NAMESPACE: eclipsebasyx |
| 9 | + |
| 10 | +jobs: |
| 11 | + build-and-push-milestone-release: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + strategy: |
| 14 | + matrix: |
| 15 | + include: |
| 16 | + - name: aas-environment |
| 17 | + path: basyx.aasenvironment/basyx.aasenvironment.component |
| 18 | + - name: aas-repository |
| 19 | + path: basyx.aasrepository/basyx.aasrepository.component |
| 20 | + - name: submodel-repository |
| 21 | + path: basyx.submodelrepository/basyx.submodelrepository.component |
| 22 | + - name: conceptdescription-repository |
| 23 | + path: basyx.conceptdescriptionrepository/basyx.conceptdescriptionrepository.component |
| 24 | + - name: aas-discovery |
| 25 | + path: basyx.aasdiscoveryservice/basyx.aasdiscoveryservice.component |
| 26 | + - name: aasxfileserver |
| 27 | + path: basyx.aasxfileserver/basyx.aasxfileserver.component |
| 28 | + - name: aas-registry-kafka-mem |
| 29 | + path: basyx.aasregistry/basyx.aasregistry-service-release-kafka-mem/src/main/docker |
| 30 | + - name: aas-registry-kafka-mongodb |
| 31 | + path: basyx.aasregistry/basyx.aasregistry-service-release-kafka-mongodb/src/main/docker |
| 32 | + - name: aas-registry-log-mem |
| 33 | + path: basyx.aasregistry/basyx.aasregistry-service-release-log-mem/src/main/docker |
| 34 | + - name: aas-registry-log-mongodb |
| 35 | + path: basyx.aasregistry/basyx.aasregistry-service-release-log-mongodb/src/main/docker |
| 36 | + - name: submodel-registry-kafka-mem |
| 37 | + path: basyx.submodelregistry/basyx.submodelregistry-service-release-kafka-mem/src/main/docker |
| 38 | + - name: submodel-registry-kafka-mongodb |
| 39 | + path: basyx.submodelregistry/basyx.submodelregistry-service-release-kafka-mongodb/src/main/docker |
| 40 | + - name: submodel-registry-log-mem |
| 41 | + path: basyx.submodelregistry/basyx.submodelregistry-service-release-log-mem/src/main/docker |
| 42 | + - name: submodel-registry-log-mongodb |
| 43 | + path: basyx.submodelregistry/basyx.submodelregistry-service-release-log-mongodb/src/main/docker |
| 44 | + |
| 45 | + steps: |
| 46 | + - name: Checkout Code |
| 47 | + uses: actions/checkout@v4 |
| 48 | + |
| 49 | + - name: Set up QEMU |
| 50 | + uses: docker/setup-qemu-action@v3 |
| 51 | + with: |
| 52 | + platforms: linux/amd64,linux/arm64,linux/arm/v7 |
| 53 | + |
| 54 | + - name: Set up Docker Buildx |
| 55 | + uses: docker/setup-buildx-action@v3 |
| 56 | + |
| 57 | + - name: Log in to Docker Hub |
| 58 | + uses: docker/login-action@v3 |
| 59 | + with: |
| 60 | + username: ${{ secrets.DOCKER_HUB_USER }} |
| 61 | + password: ${{ secrets.DOCKER_HUB_TOKEN }} |
| 62 | + |
| 63 | + - name: Set up JDK 17 |
| 64 | + uses: actions/setup-java@v4 |
| 65 | + with: |
| 66 | + java-version: '17' |
| 67 | + distribution: 'temurin' |
| 68 | + cache: maven |
| 69 | + |
| 70 | + - name: Build all modules first |
| 71 | + run: mvn clean install -DskipTests |
| 72 | + |
| 73 | + - name: Extract Release Tag |
| 74 | + id: extract_tag |
| 75 | + run: | |
| 76 | + # Extract the release tag from the GitHub context |
| 77 | + TAG_NAME=${GITHUB_REF#refs/tags/} |
| 78 | + echo "TAG_NAME=${TAG_NAME}" >> $GITHUB_ENV |
| 79 | +
|
| 80 | + # Build the project |
| 81 | + # For registry modules, we activate the dockerbuild profile and specify the module with --pl |
| 82 | + - name: Build BaSyx |
| 83 | + run: | |
| 84 | + if [[ "${{ matrix.name }}" == *"registry"* ]]; then |
| 85 | + # Derive the module's artifactId from the path |
| 86 | + module_root=$(dirname "$(dirname "$(dirname "${{ matrix.path }}")")") |
| 87 | + artifact_id=$(basename "$module_root") |
| 88 | + # Run with dockerbuild profile and namespace |
| 89 | + mvn clean install -DskipTests -Pdockerbuild "-Ddocker.namespace=${{ env.DOCKER_NAMESPACE }}" --pl "org.eclipse.digitaltwin.basyx:${artifact_id}" |
| 90 | + else |
| 91 | + echo "Non-registry module - already built in the previous step." |
| 92 | + fi |
| 93 | +
|
| 94 | + - name: Prepare Registry JAR for Docker |
| 95 | + if: contains(matrix.name, 'registry') |
| 96 | + run: | |
| 97 | + # Go three levels up from src/main/docker to get the module root |
| 98 | + module_root=$(dirname "$(dirname "$(dirname "${{ matrix.path }}")")") |
| 99 | +
|
| 100 | + # Adjust the path to where the dockerbuild profile places the JAR |
| 101 | + JAR_FILE=$(ls "$module_root/target/docker/${{ env.DOCKER_NAMESPACE }}/${{ matrix.name }}/${{ env.TAG_NAME }}/build/maven/"*.jar | head -n 1) |
| 102 | + if [ -z "$JAR_FILE" ]; then |
| 103 | + echo "No repackaged JAR found in $module_root/target/docker/${{ env.DOCKER_NAMESPACE }}/${{ matrix.name }}/${{ env.TAG_NAME }}/build/maven. Check your build." |
| 104 | + exit 1 |
| 105 | + fi |
| 106 | +
|
| 107 | + # Create the maven directory inside the Docker context and copy the JAR there |
| 108 | + mkdir -p "${{ matrix.path }}/maven" |
| 109 | + cp "$JAR_FILE" "${{ matrix.path }}/maven/" |
| 110 | +
|
| 111 | + # Extract the final name without .jar extension |
| 112 | + FINAL_NAME=$(basename "$JAR_FILE" .jar) |
| 113 | + echo "FINAL_ARGS=FINAL_NAME=${FINAL_NAME}" >> $GITHUB_ENV |
| 114 | +
|
| 115 | + - name: No-Op for Non-Registry Modules |
| 116 | + if: "!contains(matrix.name, 'registry')" |
| 117 | + run: echo "FINAL_ARGS=" >> $GITHUB_ENV |
| 118 | + |
| 119 | + - name: Set short SHA |
| 120 | + run: echo "SHORT_SHA=${GITHUB_SHA:0:7}" >> $GITHUB_ENV |
| 121 | + |
| 122 | + - name: Build and Push Docker Image |
| 123 | + uses: docker/build-push-action@v6 |
| 124 | + with: |
| 125 | + context: ${{ matrix.path }} |
| 126 | + file: ${{ matrix.path }}/Dockerfile |
| 127 | + push: true |
| 128 | + platforms: linux/amd64,linux/arm64,linux/arm/v7 |
| 129 | + tags: | |
| 130 | + ${{ env.DOCKER_NAMESPACE }}/${{ matrix.name }}:${{ env.TAG_NAME }} |
| 131 | + build-args: ${{ env.FINAL_ARGS }} |
| 132 | + |
| 133 | + - name: Verify Docker Image |
| 134 | + run: | |
| 135 | + docker pull ${{ env.DOCKER_NAMESPACE }}/${{ matrix.name }}:${{ env.TAG_NAME }} |
0 commit comments