|
8 | 8 | docker:
|
9 | 9 | runs-on: ubuntu-latest
|
10 | 10 | steps:
|
11 |
| - - uses: actions/checkout@v2 |
| 11 | + - uses: actions/checkout@v3 |
12 | 12 | with:
|
13 | 13 | fetch-depth: 0
|
14 | 14 |
|
15 |
| - - name: Build |
16 |
| - run: | |
17 |
| - docker build \ |
18 |
| - --label commit=$GITHUB_SHA \ |
19 |
| - --label build_date=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \ |
20 |
| - --label tag=${GITHUB_REF##*/} \ |
21 |
| - --tag ghcr.io/hyperledger/firefly-dataexchange-https:${GITHUB_REF##*/} \ |
22 |
| - --tag ghcr.io/hyperledger/firefly-dataexchange-https:head \ |
23 |
| - . |
24 |
| -
|
25 |
| - - name: Tag release |
| 15 | + - name: Set up QEMU |
| 16 | + uses: docker/setup-qemu-action@v2 |
| 17 | + |
| 18 | + - name: Set up Docker Buildx |
| 19 | + id: buildx |
| 20 | + uses: docker/setup-buildx-action@v2 |
| 21 | + |
| 22 | + - name: Docker login |
| 23 | + uses: docker/login-action@v1 |
| 24 | + with: |
| 25 | + registry: ghcr.io |
| 26 | + username: ${{ github.actor }} |
| 27 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 28 | + |
| 29 | + - name: Set latest tag |
26 | 30 | if: github.event.action == 'released'
|
27 |
| - run: docker tag ghcr.io/hyperledger/firefly-dataexchange-https:${GITHUB_REF##*/} ghcr.io/hyperledger/firefly-dataexchange-https:latest |
| 31 | + run: | |
| 32 | + echo "DOCKER_TAGS=${{ env.DOCKER_TAGS }},ghcr.io/${{ github.repository }}:latest" >> $GITHUB_ENV |
28 | 33 |
|
29 |
| - - name: Push docker image |
| 34 | + - name: Set alpha tag |
| 35 | + if: github.event.action == 'prereleased' && contains(github.ref, 'alpha') |
30 | 36 | run: |
|
31 |
| - echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin |
32 |
| - docker push ghcr.io/hyperledger/firefly-dataexchange-https:${GITHUB_REF##*/} |
33 |
| - |
34 |
| - - name: Push head tag |
| 37 | + echo "DOCKER_TAGS=${{ env.DOCKER_TAGS }},ghcr.io/${{ github.repository }}:alpha" >> $GITHUB_ENV |
| 38 | +
|
| 39 | + - name: Set beta tag |
| 40 | + if: github.event.action == 'prereleased' && contains(github.ref, 'beta') |
35 | 41 | run: |
|
36 |
| - echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin |
37 |
| - docker push ghcr.io/hyperledger/firefly-dataexchange-https:head |
| 42 | + echo "DOCKER_TAGS=${{ env.DOCKER_TAGS }},ghcr.io/${{ github.repository }}:beta" >> $GITHUB_ENV |
38 | 43 |
|
39 |
| - - name: Push latest tag |
40 |
| - if: github.event.action == 'released' |
| 44 | + - name: Set rc tag |
| 45 | + if: github.event.action == 'prereleased' && contains(github.ref, 'rc') |
| 46 | + run: | |
| 47 | + echo "DOCKER_TAGS=${{ env.DOCKER_TAGS }},ghcr.io/${{ github.repository }}:rc" >> $GITHUB_ENV |
| 48 | +
|
| 49 | + - name: Set build tag |
| 50 | + id: build_tag_generator |
41 | 51 | run: |
|
42 |
| - echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin |
43 |
| - docker push ghcr.io/hyperledger/firefly-dataexchange-https:latest |
| 52 | + RELEASE_TAG=$(curl https://api.github.com/repos/${{ github.repository }}/releases/latest -s | jq .tag_name -r) |
| 53 | + BUILD_TAG=$RELEASE_TAG-$(date +"%Y%m%d")-$GITHUB_RUN_NUMBER |
| 54 | + BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") |
| 55 | + echo "BUILD_TAG=$BUILD_TAG" >> $GITHUB_OUTPUT |
| 56 | + echo "BUILD_DATE=$BUILD_DATE" >> $GITHUB_OUTPUT |
| 57 | + echo "RELEASE_TAG=$RELEASE_TAG" >> $GITHUB_OUTPUT |
| 58 | +
|
| 59 | + - name: Build and push |
| 60 | + uses: docker/build-push-action@v4 |
| 61 | + with: |
| 62 | + context: ./ |
| 63 | + file: ./Dockerfile |
| 64 | + builder: ${{ steps.buildx.outputs.name }} |
| 65 | + push: true |
| 66 | + platforms: linux/amd64,linux/arm64 |
| 67 | + tags: ghcr.io/${{ github.repository }}:${{ github.ref_name }},ghcr.io/${{ github.repository }}:head,${{ env.DOCKER_TAGS }} |
| 68 | + labels: | |
| 69 | + commit=${{ github.sha }} |
| 70 | + build_date=${{ steps.build_tag_generator.outputs.BUILD_DATE }} |
| 71 | + tag=${{ steps.build_tag_generator.outputs.RELEASE_TAG }} |
| 72 | + cache-from: type=registry,ref=ghcr.io/${{ github.repository }}:buildcache |
| 73 | + cache-to: type=registry,ref=ghcr.io/${{ github.repository }}:buildcache,mode=max |
| 74 | + build-args: | |
| 75 | + BUILD_VERSION=${{ steps.build_tag_generator.outputs.RELEASE_TAG }} |
| 76 | + GIT_REF=${{ github.ref }} |
0 commit comments