docker.yml 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. packages: write
  18. steps:
  19. - name: Canel previous runs on main
  20. if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
  21. uses: styfle/[email protected]
  22. with:
  23. all_but_latest: true
  24. access_token: ${{ secrets.GITHUB_TOKEN }}
  25. - name: Checkout code
  26. uses: actions/checkout@v2
  27. - name: Set up QEMU
  28. if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
  29. uses: docker/setup-qemu-action@v1
  30. - name: Set up Docker Buildx
  31. id: buildx
  32. uses: docker/setup-buildx-action@v1
  33. with:
  34. config-inline: |
  35. [worker.oci]
  36. max-parallelism = 2
  37. - name: Inspect builder
  38. run: |
  39. echo "Name: ${{ steps.buildx.outputs.name }}"
  40. echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
  41. echo "Status: ${{ steps.buildx.outputs.status }}"
  42. echo "Flags: ${{ steps.buildx.outputs.flags }}"
  43. echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
  44. - name: Login to Docker Hub
  45. uses: docker/login-action@v1
  46. with:
  47. username: ${{ secrets.DOCKERHUB_USERNAME }}
  48. password: ${{ secrets.DOCKERHUB_TOKEN }}
  49. - name: Login to GitHub Container registry
  50. if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
  51. uses: docker/login-action@v1
  52. with:
  53. registry: ghcr.io
  54. username: ${{ github.repository_owner }}
  55. password: ${{ secrets.GITHUB_TOKEN }}
  56. - name: Get short commit SHA
  57. uses: benjlevesque/[email protected]
  58. - name: Build and push images on pull requests
  59. if: ${{ github.event_name == 'pull_request' }}
  60. uses: docker/build-push-action@v2
  61. with:
  62. context: .
  63. platforms: linux/amd64
  64. push: true
  65. tags: |
  66. gogs/gogs:commit-${{ env.SHA }}
  67. - name: Build and push images on main
  68. if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
  69. uses: docker/build-push-action@v2
  70. with:
  71. context: .
  72. platforms: linux/amd64,linux/arm64,linux/arm/v7
  73. push: true
  74. tags: |
  75. gogs/gogs:latest
  76. ghcr.io/gogs/gogs:latest
  77. - name: Send email on failure
  78. uses: dawidd6/action-send-mail@v3
  79. if: ${{ failure() && github.event_name == 'push' && github.ref == 'refs/heads/main' }}
  80. with:
  81. server_address: smtp.mailgun.org
  82. server_port: 465
  83. username: ${{ secrets.SMTP_USERNAME }}
  84. password: ${{ secrets.SMTP_PASSWORD }}
  85. subject: GitHub Actions (${{ github.repository }}) job result
  86. to: [email protected]
  87. from: GitHub Actions (${{ github.repository }})
  88. reply_to: [email protected]
  89. body: |
  90. The job "${{ github.job }}" of ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }} completed with "${{ job.status }}".
  91. View the job run at: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}