|
| 1 | +name: Docker |
| 2 | +on: |
| 3 | + push: |
| 4 | + branches: |
| 5 | + - main |
| 6 | + pull_request: |
| 7 | + paths: |
| 8 | + - 'Dockerfile' |
| 9 | + - '.github/workflows/docker.yml' |
| 10 | + release: |
| 11 | + types: [ published ] |
| 12 | + |
| 13 | +jobs: |
| 14 | + buildx: |
| 15 | + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} |
| 16 | + runs-on: ubuntu-latest |
| 17 | + permissions: |
| 18 | + actions: write |
| 19 | + contents: read |
| 20 | + packages: write |
| 21 | + steps: |
| 22 | + - name: Cancel previous runs |
| 23 | + |
| 24 | + with: |
| 25 | + all_but_latest: true |
| 26 | + access_token: ${{ secrets.GITHUB_TOKEN }} |
| 27 | + - name: Checkout code |
| 28 | + uses: actions/checkout@v2 |
| 29 | + - name: Set up QEMU |
| 30 | + uses: docker/setup-qemu-action@v1 |
| 31 | + - name: Set up Docker Buildx |
| 32 | + id: buildx |
| 33 | + uses: docker/setup-buildx-action@v1 |
| 34 | + with: |
| 35 | + config-inline: | |
| 36 | + [worker.oci] |
| 37 | + max-parallelism = 2 |
| 38 | + - name: Inspect builder |
| 39 | + run: | |
| 40 | + echo "Name: ${{ steps.buildx.outputs.name }}" |
| 41 | + echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}" |
| 42 | + echo "Status: ${{ steps.buildx.outputs.status }}" |
| 43 | + echo "Flags: ${{ steps.buildx.outputs.flags }}" |
| 44 | + echo "Platforms: ${{ steps.buildx.outputs.platforms }}" |
| 45 | + - name: Login to Docker Hub |
| 46 | + uses: docker/login-action@v1 |
| 47 | + with: |
| 48 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 49 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 50 | + - name: Login to GitHub Container registry |
| 51 | + uses: docker/login-action@v1 |
| 52 | + with: |
| 53 | + registry: ghcr.io |
| 54 | + username: ${{ github.repository_owner }} |
| 55 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 56 | + - name: Build and push images |
| 57 | + uses: docker/build-push-action@v2 |
| 58 | + with: |
| 59 | + context: . |
| 60 | + platforms: linux/amd64,linux/arm64,linux/arm/v7 |
| 61 | + push: true |
| 62 | + tags: | |
| 63 | + unknwon/codenotify.run:latest |
| 64 | + ghcr.io/codenotify/codenotify.run:latest |
| 65 | + - name: Send email on failure |
| 66 | + uses: dawidd6/action-send-mail@v3 |
| 67 | + if: ${{ failure() }} |
| 68 | + with: |
| 69 | + server_address: smtp.mailgun.org |
| 70 | + server_port: 465 |
| 71 | + username: ${{ secrets.SMTP_USERNAME }} |
| 72 | + password: ${{ secrets.SMTP_PASSWORD }} |
| 73 | + subject: GitHub Actions (${{ github.repository }}) job result |
| 74 | + |
| 75 | + from: GitHub Actions (${{ github.repository }}) |
| 76 | + |
| 77 | + body: | |
| 78 | + The job "${{ github.job }}" of ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }} completed with "${{ job.status }}". |
| 79 | +
|
| 80 | + View the job run at: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |
| 81 | +
|
| 82 | + buildx-pull-request: |
| 83 | + if: ${{ github.event_name == 'pull_request'}} |
| 84 | + runs-on: ubuntu-latest |
| 85 | + permissions: |
| 86 | + contents: read |
| 87 | + steps: |
| 88 | + - name: Checkout code |
| 89 | + uses: actions/checkout@v2 |
| 90 | + - name: Set up Docker Buildx |
| 91 | + id: buildx |
| 92 | + uses: docker/setup-buildx-action@v1 |
| 93 | + with: |
| 94 | + config-inline: | |
| 95 | + [worker.oci] |
| 96 | + max-parallelism = 2 |
| 97 | + - name: Inspect builder |
| 98 | + run: | |
| 99 | + echo "Name: ${{ steps.buildx.outputs.name }}" |
| 100 | + echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}" |
| 101 | + echo "Status: ${{ steps.buildx.outputs.status }}" |
| 102 | + echo "Flags: ${{ steps.buildx.outputs.flags }}" |
| 103 | + echo "Platforms: ${{ steps.buildx.outputs.platforms }}" |
| 104 | + - name: Compute short commit SHA |
| 105 | + uses: benjlevesque/[email protected] |
| 106 | + - name: Build and push images |
| 107 | + uses: docker/build-push-action@v2 |
| 108 | + with: |
| 109 | + context: . |
| 110 | + platforms: linux/amd64 |
| 111 | + push: true |
| 112 | + tags: | |
| 113 | + ttl.sh/codenotify/codenotify.run-${{ env.SHA }}:1d |
| 114 | +
|
| 115 | + # Updates to the following section needs to be synced to all release branches within their lifecycles. |
| 116 | + buildx-release: |
| 117 | + if: ${{ github.event_name == 'release' }} |
| 118 | + runs-on: ubuntu-latest |
| 119 | + permissions: |
| 120 | + actions: write |
| 121 | + contents: read |
| 122 | + packages: write |
| 123 | + steps: |
| 124 | + - name: Compute image tag name |
| 125 | + run: echo "IMAGE_TAG=$(echo $GITHUB_REF_NAME | cut -c 2-)" >> $GITHUB_ENV |
| 126 | + - name: Checkout code |
| 127 | + uses: actions/checkout@v2 |
| 128 | + - name: Set up QEMU |
| 129 | + uses: docker/setup-qemu-action@v1 |
| 130 | + - name: Set up Docker Buildx |
| 131 | + id: buildx |
| 132 | + uses: docker/setup-buildx-action@v1 |
| 133 | + with: |
| 134 | + config-inline: | |
| 135 | + [worker.oci] |
| 136 | + max-parallelism = 2 |
| 137 | + - name: Inspect builder |
| 138 | + run: | |
| 139 | + echo "Name: ${{ steps.buildx.outputs.name }}" |
| 140 | + echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}" |
| 141 | + echo "Status: ${{ steps.buildx.outputs.status }}" |
| 142 | + echo "Flags: ${{ steps.buildx.outputs.flags }}" |
| 143 | + echo "Platforms: ${{ steps.buildx.outputs.platforms }}" |
| 144 | + - name: Login to Docker Hub |
| 145 | + uses: docker/login-action@v1 |
| 146 | + with: |
| 147 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 148 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 149 | + - name: Login to GitHub Container registry |
| 150 | + uses: docker/login-action@v1 |
| 151 | + with: |
| 152 | + registry: ghcr.io |
| 153 | + username: ${{ github.repository_owner }} |
| 154 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 155 | + - name: Build and push images |
| 156 | + uses: docker/build-push-action@v2 |
| 157 | + with: |
| 158 | + context: . |
| 159 | + platforms: linux/amd64,linux/arm64,linux/arm/v7 |
| 160 | + push: true |
| 161 | + tags: | |
| 162 | + unknwon/codenotify.run:${{ env.IMAGE_TAG }} |
| 163 | + ghcr.io/codenotify/codenotify.run:${{ env.IMAGE_TAG }} |
| 164 | + - name: Send email on failure |
| 165 | + uses: dawidd6/action-send-mail@v3 |
| 166 | + if: ${{ failure() }} |
| 167 | + with: |
| 168 | + server_address: smtp.mailgun.org |
| 169 | + server_port: 465 |
| 170 | + username: ${{ secrets.SMTP_USERNAME }} |
| 171 | + password: ${{ secrets.SMTP_PASSWORD }} |
| 172 | + subject: GitHub Actions (${{ github.repository }}) job result |
| 173 | + |
| 174 | + from: GitHub Actions (${{ github.repository }}) |
| 175 | + |
| 176 | + body: | |
| 177 | + The job "${{ github.job }}" of ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }} completed with "${{ job.status }}". |
| 178 | +
|
| 179 | + View the job run at: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |
0 commit comments