diff --git a/.github/workflows/container-image.yml b/.github/workflows/container-image.yml new file mode 100644 index 00000000..dc5a5bc7 --- /dev/null +++ b/.github/workflows/container-image.yml @@ -0,0 +1,141 @@ +name: Build Container Image + +concurrency: + group: ci-${{ github.run_id }} + cancel-in-progress: true + +on: + push: + branches: + - main + - v[0-9]+ + - v[0-9]+.[0-9]+ + - cryostat-v[0-9]+.[0-9]+ + +env: + OPENSUSE_UNOFFICIAL_LIBCONTAINERS_KEY_URL: "https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/unstable/xUbuntu_22.04/Release.key" + OPENSUSE_UNOFFICIAL_LIBCONTAINERS_SOURCE_URL: "https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/unstable/xUbuntu_22.04" + CI_USER: mwian + CI_REGISTRY: quay.io/miwan + CI_IMG: quay.io/miwan/quarkus-test + +jobs: + check-before-build: + runs-on: ubuntu-latest + steps: + - name: Fail if safe-to-test is not applied + if: (!contains(github.event.pull_request.labels.*.name, 'safe-to-test')) + run: exit 1 + + build-agent: + runs-on: ubuntu-latest + needs: [check-before-build] + outputs: + image-version: ${{ steps.get-agent-version.outputs.agent-version }} + steps: + - uses: actions/checkout@v4 + with: + submodules: true + fetch-depth: 0 + - id: get-agent-version + run: | + echo "agent-version=$(mvn -q -DforceStdout help:evaluate -Dexpression=project.version)" >> $GITHUB_OUTPUT + - uses: actions/setup-java@v4 + with: + java-version: '17' + distribution: 'temurin' + - uses: actions/cache@v4 + with: + path: ~/.m2 + key: ${{ runner.os }}-build-${{ hashFiles('**/pom.xml') }} + - run: mvn -B -U clean install + + build-quarkus-test-app: + needs: [build-agent] + runs-on: ubuntu-latest + strategy: + matrix: + java: ['17'] + permissions: + packages: write + contents: read + pull-requests: write + statuses: write + outputs: + quay-image: ${{ steps.quarkus-test-image.outputs.image }} + env: + agent-version: ${{ needs.build-agent.outputs.image-version }} + name: Build Java ${{ matrix.java }} + steps: + - uses: actions/checkout@v4 + with: + submodules: true + fetch-depth: 0 + - uses: actions/cache@v4 + with: + path: ~/.m2 + key: ${{ runner.os }}-build-${{ hashFiles('**/pom.xml') }} + restore-keys: | + ${{ runner.os }}-build- + ${{ runner.os }}- + - uses: actions/setup-java@v4 + with: + java-version: ${{ matrix.java }} + distribution: 'temurin' + cache: 'maven' + - uses: actions/checkout@v4 + with: + repository: ${{ github.repository_owner }}/quarkus-test + ref: main + submodules: true + fetch-depth: 0 + - name: maven-settings + uses: s4u/maven-settings-action@v2 + with: + servers: '[{"id": "github", "username": "dummy", "password": "${{ secrets.GITHUB_TOKEN }}"}]' + githubServer: false + - name: Build application + run: ./mvnw -B -U -Dio.cryostat.agent.version=${{ env.agent-version }} clean verify + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Build container images and manifest + id: buildah-build + uses: redhat-actions/buildah-build@v2 + with: + image: ${{ env.CI_IMG }} + archs: amd64 + tags: ${{ env.agent-version }} + containerfiles: | + ./src/main/docker/Dockerfile.jvm + - name: Push to quay.io + id: push-to-quay + uses: redhat-actions/push-to-registry@v2 + with: + image: quarkus-test + tags: ${{ steps.buildah-build.outputs.tags }} + registry: ${{ env.CI_REGISTRY }} + username: ${{ env.CI_USER }} + password: ${{ secrets.QUAY_PASSWORD }} + - name: store quarkus-test image as output + id: quarkus-test-image + run: echo "image=${{ steps.push-to-quay.outputs.registry-path }}" >> $GITHUB_OUTPUT + + comment-image: + runs-on: ubuntu-latest + needs: [build-quarkus-test-app] + env: + image: ${{ needs.build-quarkus-test-app.outputs.quay-image }} + permissions: + pull-requests: write + steps: + - name: Create markdown table + id: md-table + uses: petems/csv-to-md-table-action@v4.0.0 + with: + csvinput: | + ARCH, IMAGE + amd64, ${{ env.image }} + - uses: thollander/actions-comment-pull-request@v2 + with: + message: |- + ${{ steps.md-table.outputs.markdown-table }}