docker_image.yml 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. - 'irr/**.[ch]'
  19. - 'irr/**.cpp'
  20. - '**/CMakeLists.txt'
  21. - 'cmake/Modules/**'
  22. - 'util/ci/**'
  23. - 'misc/irrlichtmt_tag.txt'
  24. - 'Dockerfile'
  25. - '.dockerignore'
  26. - '.github/workflows/docker_image.yml'
  27. workflow_dispatch:
  28. inputs:
  29. use_cache:
  30. description: "Use build cache"
  31. required: true
  32. type: boolean
  33. default: true
  34. env:
  35. REGISTRY: ghcr.io
  36. # github.repository as <account>/<repo>
  37. IMAGE_NAME: ${{ github.repository }}
  38. jobs:
  39. publish:
  40. runs-on: ubuntu-latest
  41. permissions:
  42. contents: read
  43. packages: write
  44. steps:
  45. - name: Check out repository
  46. uses: actions/checkout@v4
  47. - name: Setup Docker buildx
  48. uses: docker/setup-buildx-action@v3.0.0
  49. # Login against the Docker registry except on PR
  50. # https://github.com/docker/login-action
  51. - name: Log into registry ${{ env.REGISTRY }}
  52. if: github.event_name != 'pull_request'
  53. uses: docker/login-action@v3.0.0
  54. with:
  55. registry: ${{ env.REGISTRY }}
  56. username: ${{ github.actor }}
  57. password: ${{ secrets.GITHUB_TOKEN }}
  58. # Extract metadata (tags, labels) for Docker
  59. # https://github.com/docker/metadata-action
  60. - name: Extract Docker metadata
  61. id: meta
  62. uses: docker/metadata-action@v5.5.0
  63. with:
  64. images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
  65. labels: |
  66. org.opencontainers.image.title=Luanti
  67. org.opencontainers.image.vendor=Luanti
  68. org.opencontainers.image.licenses=LGPL-2.1-only
  69. # Build and push Docker image
  70. # https://github.com/docker/build-push-action
  71. # No arm support for now. Require cross-compilation support in Dockerfile to not use QEMU.
  72. - name: Build and push Docker image
  73. uses: docker/build-push-action@v5.1.0
  74. with:
  75. context: .
  76. platforms: linux/amd64
  77. push: ${{ github.event_name != 'pull_request' }}
  78. load: true
  79. tags: ${{ steps.meta.outputs.tags }}
  80. labels: ${{ steps.meta.outputs.labels }}
  81. cache-from: type=gha
  82. cache-to: type=gha,mode=max
  83. no-cache: ${{ (github.event_name == 'workflow_dispatch' && !inputs.use_cache) || startsWith(github.ref, 'refs/tags/') }}
  84. - name: Test Docker Image
  85. run: |
  86. docker run --rm $(cut -d, -f1 <<<"$DOCKER_METADATA_OUTPUT_TAGS") luantiserver --version
  87. shell: bash