action.yml 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. # SPDX-FileCopyrightText: Andrei Gherzan <andrei.gherzan@huawei.com>
  2. #
  3. # SPDX-License-Identifier: MIT
  4. name: "Build a docker image"
  5. inputs:
  6. docker_image:
  7. required: true
  8. description: "The name of the docker image"
  9. id:
  10. required: true
  11. description: "Namespace for the image"
  12. runs:
  13. using: "composite"
  14. steps:
  15. - name: Build the ${{ inputs.docker_image }} docker image
  16. shell: bash
  17. # We run this unconditionally even if the change doesn't touch the
  18. # relevant docker files because there is a chance that another PR (or
  19. # something else) rebuilt the local image. For example if the first
  20. # version of the PR included change for the relevant docker image but a
  21. # subsequent push to the PR branch dropped them. In this way we rebuild
  22. # the image to avoid using the changes from the previous push.
  23. run: |
  24. cd .github/workflows/docker-images/
  25. # We build a temporary image namespaced by the PR number so we can
  26. # handle multiple runners on the same host using the same docker
  27. # storage.
  28. tries=3
  29. n=1
  30. until [ "$n" -gt "$tries" ]; do
  31. echo "Building the docker image ${{ inputs.docker_image }}-${{ inputs.id }}... try $n..."
  32. if docker build . -f "${{ inputs.docker_image }}/Dockerfile" -t "${{ inputs.docker_image }}-${{ inputs.id }}"; then
  33. # This can fail if a dangling images cleaning job runs in
  34. # parallel. So we try this a couple of times to minimize
  35. # conflict. This is because while building, docker creates a
  36. # untagged image first (dangling) before tagging it at the end.
  37. # If between these two operations a dangling cleanup happens,
  38. # build fails.
  39. break
  40. fi
  41. n=$((n+1))
  42. done
  43. [ "$n" -lt "$tries" ]
  44. echo "Temporary image built in ${{ inputs.docker_image }}."