|
| 1 | +--- |
| 2 | +name: Application Container Image |
| 3 | + |
| 4 | +on: |
| 5 | + # We are deliberately *not* running on push events here to avoid double runs. |
| 6 | + # Instead, push events will trigger from the base image and maven unit tests via workflow_call. |
| 7 | + workflow_call: |
| 8 | + pull_request: |
| 9 | + branches: |
| 10 | + - develop |
| 11 | + - master |
| 12 | + paths: |
| 13 | + - 'src/main/docker/**' |
| 14 | + - '.github/workflows/container_app_push.yml' |
| 15 | + |
| 16 | +env: |
| 17 | + IMAGE_TAG: unstable |
| 18 | + BASE_IMAGE_TAG: unstable |
| 19 | + REGISTRY: "" # Empty means default to Docker Hub |
| 20 | + PLATFORMS: "linux/amd64,linux/arm64" |
| 21 | + |
| 22 | +jobs: |
| 23 | + build: |
| 24 | + name: Build & deploy |
| 25 | + runs-on: ubuntu-latest |
| 26 | + permissions: |
| 27 | + contents: read |
| 28 | + packages: write |
| 29 | + pull-requests: write |
| 30 | + # Only run in upstream repo - avoid unnecessary runs in forks |
| 31 | + if: ${{ github.repository_owner == 'IQSS' }} |
| 32 | + |
| 33 | + steps: |
| 34 | + - name: Checkout repository |
| 35 | + uses: actions/checkout@v3 |
| 36 | + |
| 37 | + - name: Set up JDK 11 |
| 38 | + uses: actions/setup-java@v3 |
| 39 | + with: |
| 40 | + java-version: "11" |
| 41 | + distribution: 'adopt' |
| 42 | + - name: Cache Maven packages |
| 43 | + uses: actions/cache@v3 |
| 44 | + with: |
| 45 | + path: ~/.m2 |
| 46 | + key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} |
| 47 | + restore-keys: ${{ runner.os }}-m2 |
| 48 | + |
| 49 | + - name: Build app container image with local architecture |
| 50 | + run: mvn -Pct package |
| 51 | + |
| 52 | + # Note: Accessing, pushing tags etc. to DockerHub or GHCR will only succeed in upstream because secrets. |
| 53 | + |
| 54 | + # Run this when triggered via push or schedule as reused workflow from base / maven unit tests |
| 55 | + - if: ${{ github.event_name != 'pull_request' && github.ref_name == 'develop' }} |
| 56 | + name: Push description to DockerHub |
| 57 | + uses: peter-evans/dockerhub-description@v3 |
| 58 | + with: |
| 59 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 60 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 61 | + repository: gdcc/dataverse |
| 62 | + short-description: "Dataverse Application Container Image providing the executable" |
| 63 | + readme-filepath: ./src/main/docker/README.md |
| 64 | + |
| 65 | + - if: ${{ github.event_name != 'pull_request' }} |
| 66 | + name: Log in to Docker Hub registry |
| 67 | + uses: docker/login-action@v2 |
| 68 | + with: |
| 69 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 70 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 71 | + - if: ${{ github.event_name == 'pull_request' }} |
| 72 | + name: Login to Github Container Registry |
| 73 | + uses: docker/login-action@v2 |
| 74 | + with: |
| 75 | + registry: ghcr.io |
| 76 | + username: ${{ secrets.GHCR_USERNAME }} |
| 77 | + password: ${{ secrets.GHCR_TOKEN }} |
| 78 | + |
| 79 | + - name: Set up QEMU for multi-arch builds |
| 80 | + uses: docker/setup-qemu-action@v2 |
| 81 | + |
| 82 | + - name: Re-set image tag based on branch (if master) |
| 83 | + if: ${{ github.ref_name == 'master' }} |
| 84 | + run: | |
| 85 | + echo "IMAGE_TAG=alpha" >> $GITHUB_ENV |
| 86 | + echo "BASE_IMAGE_TAG=alpha" >> $GITHUB_ENV |
| 87 | + - name: Re-set image tag and container registry when on PR |
| 88 | + if: ${{ github.event_name == 'pull_request' }} |
| 89 | + run: | |
| 90 | + echo "IMAGE_TAG=$(echo "$GITHUB_HEAD_REF" | tr '\\/_:&+,;#*' '-')" >> $GITHUB_ENV |
| 91 | + echo "REGISTRY='-Ddocker.registry=ghcr.io'" >> $GITHUB_ENV |
| 92 | +
|
| 93 | + - name: Deploy multi-arch application container image |
| 94 | + run: mvn -Pct deploy -Dapp.image.tag=${{ env.IMAGE_TAG }} -Dbase.image.tag=${{ env.BASE_IMAGE_TAG }} ${{ env.REGISTRY }} -Ddocker.platforms=${{ env.PLATFORMS }} |
| 95 | + |
| 96 | + - uses: marocchino/sticky-pull-request-comment@v2 |
| 97 | + if: ${{ github.event_name == 'pull_request' }} |
| 98 | + with: |
| 99 | + header: app-registry-push |
| 100 | + message: | |
| 101 | + Pushed preview application image as [`ghcr.io/gdcc/dataverse:${{ env.IMAGE_TAG }}`](https://github.com/orgs/gdcc/packages/container/package/dataverse). |
| 102 | + Use it by referencing it with its full name as printed above. |
0 commit comments