|
| 1 | +name: Build and push Docker image |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - 'master' |
| 7 | + - 'release/*' |
| 8 | + tags: |
| 9 | + - 'v*.*' |
| 10 | + |
| 11 | +env: |
| 12 | + # Platforms to build the image for amd64 and arm64. |
| 13 | + BUILD_PLATFORMS: linux/amd64,linux/arm64 |
| 14 | + DOCKERHUB_REPO: ${{ github.repository_owner }}/esp32-arduino-lib-builder |
| 15 | + |
| 16 | +jobs: |
| 17 | + docker: |
| 18 | + # Disable the job in forks |
| 19 | + if: ${{ github.repository_owner == 'espressif' }} |
| 20 | + |
| 21 | + runs-on: ubuntu-latest |
| 22 | + steps: |
| 23 | + # Depending on the branch/tag, set CLONE_BRANCH_OR_TAG variable (used in the Dockerfile |
| 24 | + # as a build arg) and TAG_NAME (used when tagging the image). |
| 25 | + # |
| 26 | + # The following 3 steps cover the alternatives (tag, release branch, master branch): |
| 27 | + - name: Set variables (tags) |
| 28 | + if: ${{ github.ref_type == 'tag' }} |
| 29 | + run: | |
| 30 | + echo "CLONE_BRANCH_OR_TAG=$GITHUB_REF_NAME" >> $GITHUB_ENV |
| 31 | + echo "TAG_NAME=$GITHUB_REF_NAME" >> $GITHUB_ENV |
| 32 | + - name: Set variables (release branches) |
| 33 | + if: ${{ github.ref_type == 'branch' && startsWith(github.ref_name, 'release/') }} |
| 34 | + run: | |
| 35 | + echo "CLONE_BRANCH_OR_TAG=$GITHUB_REF_NAME" >> $GITHUB_ENV |
| 36 | + echo "TAG_NAME=release-${GITHUB_REF_NAME##release/}" >> $GITHUB_ENV |
| 37 | + - name: Set variables (main branch) |
| 38 | + if: ${{ github.ref_type == 'branch' && github.ref_name == 'master' }} |
| 39 | + run: | |
| 40 | + echo "CLONE_BRANCH_OR_TAG=master" >> $GITHUB_ENV |
| 41 | + echo "TAG_NAME=latest" >> $GITHUB_ENV |
| 42 | +
|
| 43 | + # Display the variables set above, just in case. |
| 44 | + - name: Check variables |
| 45 | + run: | |
| 46 | + echo "CLONE_BRANCH_OR_TAG: $CLONE_BRANCH_OR_TAG" |
| 47 | + echo "CHECKOUT_REF: $CHECKOUT_REF" |
| 48 | + echo "TAG_NAME: $TAG_NAME" |
| 49 | +
|
| 50 | + # The following steps are the standard boilerplate from |
| 51 | + # https://github.com/marketplace/actions/build-and-push-docker-images |
| 52 | + - name: Checkout |
| 53 | + uses: actions/checkout@v4 |
| 54 | + - name: Login to Docker Hub |
| 55 | + uses: docker/login-action@v3 |
| 56 | + with: |
| 57 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 58 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 59 | + - name: Set up QEMU for multiarch builds |
| 60 | + uses: docker/setup-qemu-action@v3 |
| 61 | + - name: Set up Docker Buildx |
| 62 | + uses: docker/setup-buildx-action@v3 |
| 63 | + - name: Build and push |
| 64 | + uses: docker/build-push-action@v5 |
| 65 | + with: |
| 66 | + context: tools/docker |
| 67 | + push: true |
| 68 | + tags: ${{ env.DOCKERHUB_REPO }}:${{ env.TAG_NAME }} |
| 69 | + platforms: ${{ env.BUILD_PLATFORMS }} |
| 70 | + cache-from: type=registry,ref=${{ env.DOCKERHUB_REPO }}:${{ env.TAG_NAME }} |
| 71 | + cache-to: type=inline |
| 72 | + build-args: | |
| 73 | + LIBBUILDER_CLONE_URL=${{ github.server_url }}/${{ github.repository }}.git |
| 74 | + LIBBUILDER_CLONE_BRANCH_OR_TAG=${{ env.CLONE_BRANCH_OR_TAG }} |
| 75 | +
|
| 76 | + - name: Update Docker Hub repository description (master branch) |
| 77 | + if: ${{ github.ref_type == 'branch' && github.ref_name == 'master' }} |
| 78 | + uses: peter-evans/dockerhub-description@v4 |
| 79 | + with: |
| 80 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 81 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 82 | + repository: ${{ env.DOCKERHUB_REPO }} |
| 83 | + readme-filepath: ./tools/docker/README.md |
0 commit comments