2
0

docker_image.yml 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. ---
  2. name: docker_image
  3. # https://docs.github.com/en/actions/publishing-packages/publishing-docker-images
  4. # https://docs.docker.com/build/ci/github-actions/multi-platform
  5. # https://github.com/opencontainers/image-spec/blob/main/annotations.md
  6. on:
  7. push:
  8. branches: [ "master" ]
  9. # Publish semver tags as releases.
  10. tags: [ "*.*.*" ]
  11. pull_request:
  12. # Build docker image on pull requests. (but do not publish)
  13. paths:
  14. - 'lib/**.[ch]'
  15. - 'lib/**.cpp'
  16. - 'src/**.[ch]'
  17. - 'src/**.cpp'
  18. - '**/CMakeLists.txt'
  19. - 'cmake/Modules/**'
  20. - 'util/ci/**'
  21. - 'misc/irrlichtmt_tag.txt'
  22. - 'Dockerfile'
  23. - '.dockerignore'
  24. - '.github/workflows/docker_image.yml'
  25. workflow_dispatch:
  26. env:
  27. REGISTRY: ghcr.io
  28. # github.repository as <account>/<repo>
  29. IMAGE_NAME: ${{ github.repository }}
  30. jobs:
  31. publish:
  32. runs-on: ubuntu-latest
  33. permissions:
  34. contents: read
  35. packages: write
  36. steps:
  37. - name: Check out repository
  38. uses: actions/checkout@v4
  39. - name: Setup Docker buildx
  40. uses: docker/setup-buildx-action@v3.0.0
  41. # Login against the Docker registry except on PR
  42. # https://github.com/docker/login-action
  43. - name: Log into registry ${{ env.REGISTRY }}
  44. if: github.event_name != 'pull_request'
  45. uses: docker/login-action@v3.0.0
  46. with:
  47. registry: ${{ env.REGISTRY }}
  48. username: ${{ github.actor }}
  49. password: ${{ secrets.GITHUB_TOKEN }}
  50. # Extract metadata (tags, labels) for Docker
  51. # https://github.com/docker/metadata-action
  52. - name: Extract Docker metadata
  53. id: meta
  54. uses: docker/metadata-action@v5.5.0
  55. with:
  56. images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
  57. labels: |
  58. org.opencontainers.image.title=Minetest
  59. org.opencontainers.image.vendor=Minetest
  60. org.opencontainers.image.licenses=LGPL-2.1-only
  61. # Build and push Docker image
  62. # https://github.com/docker/build-push-action
  63. # No arm support for now. Require cross-compilation support in Dockerfile to not use QEMU.
  64. - name: Build and push Docker image
  65. uses: docker/build-push-action@v5.1.0
  66. with:
  67. context: .
  68. platforms: linux/amd64
  69. push: ${{ github.event_name != 'pull_request' }}
  70. load: true
  71. tags: ${{ steps.meta.outputs.tags }}
  72. labels: ${{ steps.meta.outputs.labels }}
  73. cache-from: type=gha
  74. cache-to: type=gha,mode=max
  75. - name: Test Docker Image
  76. run: |
  77. docker run --rm $(cut -d, -f1 <<<"$DOCKER_METADATA_OUTPUT_TAGS") minetestserver --version
  78. shell: bash