docker.yml 2.5 KB

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