From ecee769803bba5426fe36d4a0c2ae8a68821d970 Mon Sep 17 00:00:00 2001 From: Nicko Guyer Date: Fri, 17 Feb 2023 16:25:59 -0500 Subject: [PATCH] Update GitHub Actions and enable multi-arch builds Signed-off-by: Nicko Guyer --- .github/workflows/docker_main.yml | 62 +++++++++++++-------- .github/workflows/docker_release.yml | 81 +++++++++++++++++++--------- .github/workflows/test.yml | 12 ++--- 3 files changed, 102 insertions(+), 53 deletions(-) diff --git a/.github/workflows/docker_main.yml b/.github/workflows/docker_main.yml index 4ee11c9..d776994 100644 --- a/.github/workflows/docker_main.yml +++ b/.github/workflows/docker_main.yml @@ -9,32 +9,48 @@ jobs: docker: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 + with: + fetch-depth: 0 - - name: Set build tag - id: build_tag_generator - run: | - RELEASE_TAG=$(curl https://api.github.com/repos/hyperledger/firefly-tokens-erc20-erc721/releases/latest -s | jq .tag_name -r) - BUILD_TAG=$RELEASE_TAG-$(date +"%Y%m%d")-$GITHUB_RUN_NUMBER - echo ::set-output name=BUILD_TAG::$BUILD_TAG + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 - - name: Build - run: | - docker build \ - --label commit=$GITHUB_SHA \ - --label build_date=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \ - --label tag=${{ steps.build_tag_generator.outputs.BUILD_TAG }} \ - --tag ghcr.io/hyperledger/firefly-tokens-erc20-erc721:${{ steps.build_tag_generator.outputs.BUILD_TAG }} . + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v2 - - name: Tag release - run: docker tag ghcr.io/hyperledger/firefly-tokens-erc20-erc721:${{ steps.build_tag_generator.outputs.BUILD_TAG }} ghcr.io/hyperledger/firefly-tokens-erc20-erc721:head + - name: Docker login + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} - - name: Push docker image + - name: Set build tag + id: build_tag_generator run: | - echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin - docker push ghcr.io/hyperledger/firefly-tokens-erc20-erc721:${{ steps.build_tag_generator.outputs.BUILD_TAG }} + RELEASE_TAG=$(curl https://api.github.com/repos/${{ github.repository }}/releases/latest -s | jq .tag_name -r) + BUILD_TAG=$RELEASE_TAG-$(date +"%Y%m%d")-$GITHUB_RUN_NUMBER + BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") + echo "BUILD_TAG=$BUILD_TAG" >> $GITHUB_OUTPUT + echo "name=BUILD_DATE=$BUILD_DATE" >> $GITHUB_OUTPUT - - name: Push head tag - run: | - echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin - docker push ghcr.io/hyperledger/firefly-tokens-erc20-erc721:head + - name: Build and push + uses: docker/build-push-action@v4 + with: + context: ./ + file: ./Dockerfile + builder: ${{ steps.buildx.outputs.name }} + push: true + platforms: linux/amd64,linux/arm64 + tags: ghcr.io/${{ github.repository }}:${{ steps.build_tag_generator.outputs.BUILD_TAG }},ghcr.io/${{ github.repository }}:head + labels: | + commit=${{ github.sha }} + build_date=${{ steps.build_tag_generator.outputs.BUILD_DATE }} + tag=${{ steps.build_tag_generator.outputs.BUILD_TAG }} + cache-from: type=registry,ref=ghcr.io/${{ github.repository }}:buildcache + cache-to: type=registry,ref=ghcr.io/${{ github.repository }}:buildcache,mode=max + build-args: | + BUILD_VERSION=${{ steps.build_tag_generator.outputs.BUILD_TAG }} + GIT_REF=${{ github.ref }} diff --git a/.github/workflows/docker_release.yml b/.github/workflows/docker_release.yml index 185e1c4..3fbdaea 100644 --- a/.github/workflows/docker_release.yml +++ b/.github/workflows/docker_release.yml @@ -8,36 +8,69 @@ jobs: docker: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 0 - - name: Build - run: | - docker build \ - --label commit=$GITHUB_SHA \ - --label build_date=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \ - --label tag=${GITHUB_REF##*/} \ - --tag ghcr.io/hyperledger/firefly-tokens-erc20-erc721:${GITHUB_REF##*/} \ - --tag ghcr.io/hyperledger/firefly-tokens-erc20-erc721:head \ - . - - - name: Tag release + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v2 + + - name: Docker login + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set latest tag if: github.event.action == 'released' - run: docker tag ghcr.io/hyperledger/firefly-tokens-erc20-erc721:${GITHUB_REF##*/} ghcr.io/hyperledger/firefly-tokens-erc20-erc721:latest + run: | + echo "DOCKER_TAGS=${{ env.DOCKER_TAGS }},ghcr.io/${{ github.repository }}:latest" >> $GITHUB_ENV - - name: Push docker image + - name: Set alpha tag + if: github.event.action == 'prereleased' && contains(github.ref, 'alpha') run: | - echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin - docker push ghcr.io/hyperledger/firefly-tokens-erc20-erc721:${GITHUB_REF##*/} - - - name: Push head tag + echo "DOCKER_TAGS=${{ env.DOCKER_TAGS }},ghcr.io/${{ github.repository }}:alpha" >> $GITHUB_ENV + + - name: Set beta tag + if: github.event.action == 'prereleased' && contains(github.ref, 'beta') run: | - echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin - docker push ghcr.io/hyperledger/firefly-tokens-erc20-erc721:head + echo "DOCKER_TAGS=${{ env.DOCKER_TAGS }},ghcr.io/${{ github.repository }}:beta" >> $GITHUB_ENV - - name: Push latest tag - if: github.event.action == 'released' + - name: Set rc tag + if: github.event.action == 'prereleased' && contains(github.ref, 'rc') + run: | + echo "DOCKER_TAGS=${{ env.DOCKER_TAGS }},ghcr.io/${{ github.repository }}:rc" >> $GITHUB_ENV + + - name: Set build tag + id: build_tag_generator run: | - echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin - docker push ghcr.io/hyperledger/firefly-tokens-erc20-erc721:latest + RELEASE_TAG=$(curl https://api.github.com/repos/${{ github.repository }}/releases/latest -s | jq .tag_name -r) + BUILD_TAG=$RELEASE_TAG-$(date +"%Y%m%d")-$GITHUB_RUN_NUMBER + BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") + echo "BUILD_TAG=$BUILD_TAG" >> $GITHUB_OUTPUT + echo "BUILD_DATE=$BUILD_DATE" >> $GITHUB_OUTPUT + echo "RELEASE_TAG=$RELEASE_TAG" >> $GITHUB_OUTPUT + + - name: Build and push + uses: docker/build-push-action@v4 + with: + context: ./ + file: ./Dockerfile + builder: ${{ steps.buildx.outputs.name }} + push: true + platforms: linux/amd64,linux/arm64 + tags: ghcr.io/${{ github.repository }}:${{ github.ref_name }},ghcr.io/${{ github.repository }}:head,${{ env.DOCKER_TAGS }} + labels: | + commit=${{ github.sha }} + build_date=${{ steps.build_tag_generator.outputs.BUILD_DATE }} + tag=${{ steps.build_tag_generator.outputs.RELEASE_TAG }} + cache-from: type=registry,ref=ghcr.io/${{ github.repository }}:buildcache + cache-to: type=registry,ref=ghcr.io/${{ github.repository }}:buildcache,mode=max + build-args: | + BUILD_VERSION=${{ steps.build_tag_generator.outputs.RELEASE_TAG }} + GIT_REF=${{ github.ref }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d695676..04e4312 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,9 +8,9 @@ jobs: test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Use Node.js - uses: actions/setup-node@v2 + uses: actions/setup-node@v3 with: node-version: '16.x' - run: npm ci @@ -19,9 +19,9 @@ jobs: solidity-test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Use Node.js - uses: actions/setup-node@v2 + uses: actions/setup-node@v3 with: node-version: '16.x' - run: npm ci @@ -33,6 +33,6 @@ jobs: docker: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - name: Docker build - run: docker build --tag ghcr.io/hyperledger/firefly-tokens-erc20-erc721 . \ No newline at end of file + run: docker build --tag ghcr.io/hyperledger/firefly-tokens-erc20-erc721 .