From c1b8d300d4775958d9da6da3c42b0674e16fb84d Mon Sep 17 00:00:00 2001 From: Jonas Bulcke Date: Thu, 5 Dec 2024 15:59:08 +0100 Subject: [PATCH] ci: add additional pipeline --- .github/workflows/build-image-only.yml | 194 +++++++++++++++++++++++++ .github/workflows/pr-merged.yml | 2 +- 2 files changed, 195 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/build-image-only.yml diff --git a/.github/workflows/build-image-only.yml b/.github/workflows/build-image-only.yml new file mode 100644 index 000000000..66abdc774 --- /dev/null +++ b/.github/workflows/build-image-only.yml @@ -0,0 +1,194 @@ +name: 2.b Build & Push Image Only + +on: + workflow_dispatch: + +env: + REGISTRY: ghcr.io + LDIO_IMAGE_NAME: ldi-orchestrator + DISCOVERER_IMAGE_NAME: ldes-discoverer + +jobs: + build: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + outputs: + version: ${{ steps.determine-version.outputs.version }} + steps: + - uses: actions/checkout@v4 + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + distribution: zulu + java-version: 21 + - name: Cache SonarCloud packages + uses: actions/cache@v4.1.2 + with: + path: ~/.sonar/cache + key: ${{ runner.os }}-sonar + restore-keys: ${{ runner.os }}-sonar + - name: Cache Maven packages + uses: actions/cache@v4.1.2 + with: + path: ~/.m2 + key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} + restore-keys: ${{ runner.os }}-m2 + # Maven + - name: Set up Maven Central Repository + uses: actions/setup-java@v4 + with: + java-version: 21 + distribution: 'zulu' + server-id: ossrh + server-username: MAVEN_USERNAME + server-password: MAVEN_PASSWORD + gpg-private-key: ${{ secrets.OSSRH_GPG_SECRET_KEY }} + gpg-passphrase: MAVEN_GPG_PASSPHRASE + + - name: Determine version + id: determine-version + run: | + export VERSION=$(mvn help:evaluate -Dexpression="project.version" -q -DforceStdout) + echo "version=$VERSION" >> $GITHUB_OUTPUT + - name: Analyse & publish package + run: | + mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=Informatievlaanderen_VSDS-Linked-Data-Interactions -Pcoverage,release -Dparallel=all -DperCoreThreadCount=true + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + MAVEN_USERNAME: ${{ secrets.OSSRH_USERNAME }} + MAVEN_PASSWORD: ${{ secrets.OSSRH_TOKEN }} + MAVEN_GPG_PASSPHRASE: ${{ secrets.OSSRH_GPG_SECRET_KEY_PASSWORD }} + + - name: Upload JARs + uses: actions/upload-artifact@v4 + with: + name: artifacts + path: | + **/*with-dependencies.jar + **/*application.jar + **/ldes-discoverer.jar + + + create-ldio-image: + name: Build and push LDIO image + runs-on: ubuntu-latest + needs: build + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Download JARs + uses: actions/download-artifact@v4 + with: + name: artifacts + path: .github + - name: Define docker variables + run: | + if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then + echo "IMAGE_TAG=${{ needs.build.outputs.version }}" >> $GITHUB_ENV + echo "IMAGES=ldes/${{ env.LDIO_IMAGE_NAME }}" >> $GITHUB_ENV + if [[ "${{ needs.build.outputs.version }}" != *"SNAPSHOT"* ]]; then + echo "LATEST=latest" >> $GITHUB_ENV + fi + else + echo "IMAGE_TAG=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV + echo "IMAGES=${{ env.REGISTRY }}/Informatievlaanderen/${{ env.LDIO_IMAGE_NAME }}" >> $GITHUB_ENV + echo "LATEST=latest" >> $GITHUB_ENV + fi + - name: Log in to the DockerHub Container registry + if: github.ref_name == 'main' + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USER }} + password: ${{ secrets.DOCKER_PASSWORD }} + - name: Log in to the GitHub Container registry + if: github.ref_name != 'main' + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: Informatievlaanderen + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.IMAGES }} + tags: | + type=raw,value=${{env.IMAGE_TAG}} + type=raw,value=${{env.LATEST}} + - name: Build and push Docker image + uses: docker/build-push-action@v3 + with: + context: .github + push: true + file: .github/ldio.Dockerfile + tags: ${{ steps.meta.outputs.tags }} + platforms: linux/amd64,linux/arm64 + + + create-discoverer-image: + name: Build and push LDES Discoverer image + runs-on: ubuntu-latest + needs: build + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Download JARs + uses: actions/download-artifact@v4 + with: + name: artifacts + path: .github + - name: Define docker variables + run: | + if [[ "${{ github.ref }}" == "refs/heads/main" ]]; then + echo "IMAGE_TAG=${{ needs.build.outputs.version }}" >> $GITHUB_ENV + echo "IMAGES=ldes/${{ env.DISCOVERER_IMAGE_NAME }}" >> $GITHUB_ENV + if [[ "${{ needs.build.outputs.version }}" != *"SNAPSHOT"* ]]; then + echo "LATEST=latest" >> $GITHUB_ENV + fi + else + echo "IMAGE_TAG=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV + echo "IMAGES=${{ env.REGISTRY }}/Informatievlaanderen/${{ env.DISCOVERER_IMAGE_NAME }}" >> $GITHUB_ENV + echo "LATEST=latest" >> $GITHUB_ENV + fi + - name: Log in to the DockerHub Container registry + if: github.ref_name == 'main' + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USER }} + password: ${{ secrets.DOCKER_PASSWORD }} + - name: Log in to the GitHub Container registry + if: github.ref_name != 'main' + uses: docker/login-action@v2 + with: + registry: ${{ env.REGISTRY }} + username: Informatievlaanderen + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.IMAGES }} + tags: | + type=raw,value=${{env.IMAGE_TAG}} + type=raw,value=${{env.LATEST}} + - name: Build and push Docker image + uses: docker/build-push-action@v3 + with: + context: .github + push: true + file: .github/ldes-discoverer.Dockerfile + tags: ${{ steps.meta.outputs.tags }} + platforms: linux/amd64,linux/arm64 \ No newline at end of file diff --git a/.github/workflows/pr-merged.yml b/.github/workflows/pr-merged.yml index 832781e42..d14e51fd0 100644 --- a/.github/workflows/pr-merged.yml +++ b/.github/workflows/pr-merged.yml @@ -58,7 +58,7 @@ jobs: id: determine-version run: | export VERSION=$(mvn help:evaluate -Dexpression="project.version" -q -DforceStdout) - echo "::set-output name=version::$VERSION" + echo "version=$VERSION" >> $GITHUB_OUTPUT - name: Analyse & publish package run: | mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar deploy -Dsonar.projectKey=Informatievlaanderen_VSDS-Linked-Data-Interactions -Pcoverage,release -Dparallel=all -DperCoreThreadCount=true