docker.yml 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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/cancel-workflow-action@0.9.1
  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/short-sha@v1.2
  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