docker.yml 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. name: Docker
  2. on:
  3. schedule:
  4. - cron: '0 4 * * *' # everyday at 4 am UTC
  5. push:
  6. branches:
  7. - master
  8. tags:
  9. - v*
  10. pull_request:
  11. jobs:
  12. build:
  13. name: Build
  14. runs-on: ubuntu-latest
  15. steps:
  16. - name: Checkout
  17. uses: actions/checkout@v2
  18. - name: Repo metadata
  19. id: repo
  20. uses: actions/github-script@v3
  21. with:
  22. script: |
  23. const repo = await github.repos.get(context.repo)
  24. return repo.data
  25. - name: Gather image information
  26. id: info
  27. run: |
  28. DOCKER_IMAGE=ghcr.io/drakkan/sftpgo
  29. VERSION=noop
  30. if [ "${{ github.event_name }}" = "schedule" ]; then
  31. VERSION=nightly
  32. elif [[ $GITHUB_REF == refs/tags/* ]]; then
  33. VERSION=${GITHUB_REF#refs/tags/}
  34. elif [[ $GITHUB_REF == refs/heads/* ]]; then
  35. VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
  36. if [ "${{ github.event.repository.default_branch }}" = "$VERSION" ]; then
  37. VERSION=edge
  38. fi
  39. elif [[ $GITHUB_REF == refs/pull/* ]]; then
  40. VERSION=pr-${{ github.event.number }}
  41. fi
  42. TAGS="${DOCKER_IMAGE}:${VERSION}"
  43. if [[ $GITHUB_REF == refs/tags/* ]]; then
  44. TAGS="$TAGS,${DOCKER_IMAGE}:latest"
  45. fi
  46. echo ::set-output name=version::${VERSION}
  47. echo ::set-output name=tags::${TAGS}
  48. echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
  49. echo ::set-output name=sha::${GITHUB_SHA::8}
  50. - name: Set up QEMU
  51. uses: docker/setup-qemu-action@v1
  52. - name: Set up Docker Buildx
  53. uses: docker/setup-buildx-action@v1
  54. - name: Login to GitHub Container Registry
  55. uses: docker/login-action@v1
  56. with:
  57. registry: ghcr.io
  58. username: ${{ github.repository_owner }}
  59. password: ${{ secrets.CR_PAT }}
  60. if: github.event_name != 'pull_request'
  61. - name: Build and push
  62. uses: docker/build-push-action@v2
  63. with:
  64. push: ${{ github.event_name != 'pull_request' }}
  65. tags: ${{ steps.info.outputs.tags }}
  66. build-args: |
  67. COMMIT_SHA=${{ steps.info.outputs.sha }}
  68. platforms: linux/amd64,linux/arm64
  69. labels: |
  70. org.opencontainers.image.title=${{ fromJson(steps.repo.outputs.result).name }}
  71. org.opencontainers.image.description=Fully featured and highly configurable SFTP server with optional FTP/S and WebDAV support
  72. org.opencontainers.image.url=${{ fromJson(steps.repo.outputs.result).html_url }}
  73. org.opencontainers.image.documentation=${{ fromJson(steps.repo.outputs.result).html_url }}/blob/${{ github.sha }}/docker/README.md
  74. org.opencontainers.image.source=${{ fromJson(steps.repo.outputs.result).clone_url }}
  75. org.opencontainers.image.version=${{ steps.info.outputs.version }}
  76. org.opencontainers.image.created=${{ steps.info.outputs.created }}
  77. org.opencontainers.image.revision=${{ github.sha }}
  78. org.opencontainers.image.licenses=${{ fromJson(steps.repo.outputs.result).license.spdx_id }}