docker.yml 3.2 KB

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