docker.yml 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. name: Docker
  2. on:
  3. push:
  4. branches:
  5. - main
  6. pull_request:
  7. paths:
  8. - 'Dockerfile'
  9. - 'docker/**'
  10. - '.github/workflows/docker.yml'
  11. jobs:
  12. buildx:
  13. runs-on: ubuntu-latest
  14. steps:
  15. - name: Canel previous runs on main
  16. if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
  17. uses: styfle/cancel-workflow-action@0.9.1
  18. with:
  19. all_but_latest: true
  20. access_token: ${{ secrets.GITHUB_TOKEN }}
  21. - name: Checkout code
  22. uses: actions/checkout@v2
  23. - name: Set up QEMU
  24. if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
  25. uses: docker/setup-qemu-action@v1
  26. - name: Set up Docker Buildx
  27. id: buildx
  28. uses: docker/setup-buildx-action@v1
  29. with:
  30. config-inline: |
  31. [worker.oci]
  32. max-parallelism = 2
  33. - name: Inspect builder
  34. run: |
  35. echo "Name: ${{ steps.buildx.outputs.name }}"
  36. echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
  37. echo "Status: ${{ steps.buildx.outputs.status }}"
  38. echo "Flags: ${{ steps.buildx.outputs.flags }}"
  39. echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
  40. - name: Login to Docker Hub
  41. uses: docker/login-action@v1
  42. with:
  43. username: ${{ secrets.DOCKERHUB_USERNAME }}
  44. password: ${{ secrets.DOCKERHUB_TOKEN }}
  45. - name: Login to GitHub Container registry
  46. if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
  47. uses: docker/login-action@v1
  48. with:
  49. registry: ghcr.io
  50. username: ${{ github.repository_owner }}
  51. password: ${{ secrets.GITHUB_TOKEN }}
  52. - name: Get short commit SHA
  53. uses: benjlevesque/short-sha@v1.2
  54. - name: Build and push images on pull requests
  55. if: ${{ github.event_name == 'pull_request' }}
  56. uses: docker/build-push-action@v2
  57. with:
  58. context: .
  59. platforms: linux/amd64
  60. push: true
  61. tags: |
  62. gogs/gogs:commit-${{ env.SHA }}
  63. - name: Build and push images on main
  64. if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
  65. uses: docker/build-push-action@v2
  66. with:
  67. context: .
  68. platforms: linux/amd64,linux/arm64,linux/arm/v7
  69. push: true
  70. tags: |
  71. gogs/gogs:latest
  72. ghcr.io/gogs/gogs:latest