aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/docker.yml
blob: 576558225b7917c02ac4cbe0bfd5195d7579615a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
name: Docker
on:
  push:
    branches:
      - main
  pull_request:
    paths:
      - 'Dockerfile'
      - 'docker/**'
      - '.github/workflows/docker.yml'

jobs:
  buildx:
    runs-on: ubuntu-latest
    permissions:
      actions: write
      contents: read
      packages: write
    steps:
      - name: Canel previous runs on main
        if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
        uses: styfle/cancel-workflow-action@0.9.1
        with:
          all_but_latest: true
          access_token: ${{ secrets.GITHUB_TOKEN }}
      - name: Checkout code
        uses: actions/checkout@v2
      - name: Set up QEMU
        if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
        uses: docker/setup-qemu-action@v1
      - name: Set up Docker Buildx
        id: buildx
        uses: docker/setup-buildx-action@v1
        with:
          config-inline: |
            [worker.oci]
              max-parallelism = 2
      - name: Inspect builder
        run: |
          echo "Name:      ${{ steps.buildx.outputs.name }}"
          echo "Endpoint:  ${{ steps.buildx.outputs.endpoint }}"
          echo "Status:    ${{ steps.buildx.outputs.status }}"
          echo "Flags:     ${{ steps.buildx.outputs.flags }}"
          echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
      - name: Login to Docker Hub
        uses: docker/login-action@v1
        with:
          username: ${{ secrets.DOCKERHUB_USERNAME }}
          password: ${{ secrets.DOCKERHUB_TOKEN }}
      - name: Login to GitHub Container registry
        if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
        uses: docker/login-action@v1
        with:
          registry: ghcr.io
          username: ${{ github.repository_owner }}
          password: ${{ secrets.GITHUB_TOKEN }}
      - name: Get short commit SHA
        uses: benjlevesque/short-sha@v1.2
      - name: Build and push images on pull requests
        if: ${{ github.event_name == 'pull_request' }}
        uses: docker/build-push-action@v2
        with:
          context: .
          platforms: linux/amd64
          push: true
          tags: |
            gogs/gogs:commit-${{ env.SHA }}
      - name: Build and push images on main
        if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }}
        uses: docker/build-push-action@v2
        with:
          context: .
          platforms: linux/amd64,linux/arm64,linux/arm/v7
          push: true
          tags: |
            gogs/gogs:latest
            ghcr.io/gogs/gogs:latest
      - name: Send email on failure
        uses: dawidd6/action-send-mail@v3
        if: ${{ failure() && github.event_name == 'push' && github.ref == 'refs/heads/main' }}
        with:
          server_address: smtp.mailgun.org
          server_port: 465
          username: ${{ secrets.SMTP_USERNAME }}
          password: ${{ secrets.SMTP_PASSWORD }}
          subject: GitHub Actions (${{ github.repository }}) job result
          to: github-actions-8ce6454@unknwon.io
          from: GitHub Actions (${{ github.repository }})
          reply_to: noreply@unknwon.io
          body: |
            The job "${{ github.job }}" of ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }} completed with "${{ job.status }}".

            View the job run at: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}