snowdrop / release-manager

Jira Java Client Tool
3 stars 6 forks source link

Refactor github workflow to only build image on main branch commits #130

Closed cmoulliard closed 3 years ago

cmoulliard commented 3 years ago

Suggestion

Refactor the github workflow to only build an image on main branch commits and not not for PR.

Example of code

name: "CI - JDK 11 Build"

on:
    push:
        branches: [ main ]
        tags: ['*.*']
    pull_request:
        branches: [ main ]

jobs:
    build-jdk11:
        name: "JDK 11 Build"
        runs-on: ubuntu-latest

        steps:
            -   uses: actions/checkout@v2
            -   name: Setup AdoptOpenJDK
                uses: joschi/setup-jdk@v2.3.0
                with:
                    java-version: 11

            -   name: Build
                run: ./mvnw clean package -X

    build-container:
        name: "Build container image"
        runs-on: ubuntu-latest
        if: github.event_name != 'push'
        steps:
            -   uses: actions/checkout@v2
            -   name: Container meta
                id: container_meta
                uses: crazy-max/ghaction-docker-meta@v2
                with:
                    # list of Docker images to use as base name for tags
                    images: |
                        quay.io/snowdrop/release-manager
                    # generate Docker tags based on the following events/attributes
                    tags: |
                        type=semver,pattern={{version}}
                        type=semver,pattern={{major}}.{{minor}}
                        type=semver,pattern={{major}}
                        type=sha
                        type=ref,event=tag

            -   name: Login to DockerHub
                uses: docker/login-action@v1
                with:
                  registry: quay.io
                  username: ${{ secrets.QUAY_USERNAME }}
                  password: ${{ secrets.QUAY_ROBOT_TOKEN }}

            -   name: Build and push
                id: container_build
                uses: docker/build-push-action@v2
                with:
                    context: .
                    file: ./ci/Dockerfile.jvm
                    push: ${{ github.event_name != 'pull_request' }}
                    # tags: quay.io/snowdrop/release-manager:latest
                    tags: ${{ steps.container_meta.outputs.tags }}
                    labels: ${{ steps.container_meta.outputs.labels }}

            -   name: Image digest
                run: echo ${{ steps.container_build.outputs.digest }}

WDYT: @jacobdotcosta @aureamunoz

aureamunoz commented 3 years ago

Yes, I agree with that!

cmoulliard commented 3 years ago

I will push the change and we will see if job will not be called for next PR push

cmoulliard commented 3 years ago

If condition is wrong as only one job was executed and no container image was build : https://github.com/snowdrop/release-manager/actions/runs/785457835 To be checked: @aureamunoz @jacobdotcosta

aureamunoz commented 3 years ago

Look at this: https://github.com/snowdrop/release-manager/actions/runs/785517134 https://github.com/snowdrop/release-manager/commit/e33299d6f7378b189a0aeb10a5baa2a68588a06f However, the image built failed @cmoulliard

cmoulliard commented 3 years ago

There is still an issue as the files resulting of the application built (= jar, lib, ...) are uploaded here

/home/runner/work/release-manager/release-manager

while docker buildx is looking to find them here

#5 [3/4] COPY target/lib/* /deployments/lib/
#5 sha256:cb1baa6abc82dff111ea8381b0a3b0752ef545ebaaf20cd856308f4d567a0e54
#5 ERROR: lstat /var/lib/docker/tmp/buildkit-mount250359445/target/lib: no such file or directory
------
 > [3/4] COPY target/lib/* /deployments/lib/:
------
error: failed to solve: rpc error: code = Unknown desc = lstat /var/lib/docker/tmp/buildkit-mount250359445/target/lib: no such file or directory
cmoulliard commented 3 years ago

Problem reported within the previous commit has been fixed: https://github.com/snowdrop/release-manager/actions/runs/785782147