Repository navigation
116 lines (95 loc) · 3.32 KB
/
Copy pathdeploy.yml
File metadata and controls
116 lines (95 loc) · 3.32 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
name: Deploy
on:
workflow_run:
workflows: ["CI"]
types: [completed]
branches: [main]
workflow_dispatch:
concurrency:
group: deploy-production
cancel-in-progress: false
permissions:
contents: read
env:
IMAGE_NAME: registry.dokku.djbender.com/lizard
GIT_SHA: ${{ github.sha }}
jobs:
build:
runs-on: ${{ matrix.runner }}
if: github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success'
environment: production
strategy:
matrix:
include:
- arch: amd64
runner: ubuntu-24.04
- arch: arm64
runner: ubuntu-24.04-arm
steps:
- uses: actions/checkout@v7
with:
ref: ${{ github.event.workflow_run.head_sha || github.sha }}
- name: Set short SHA
run: echo "GIT_SHA_SHORT=${GIT_SHA::7}" >> "$GITHUB_ENV"
- uses: docker/setup-buildx-action@v4
- uses: docker/login-action@v4.6.0
with:
registry: registry.dokku.djbender.com
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Build and push
uses: docker/build-push-action@v7
with:
context: .
platforms: linux/${{ matrix.arch }}
push: true
tags: ${{ env.IMAGE_NAME }}:${{ env.GIT_SHA_SHORT }}-${{ matrix.arch }}
build-args: |
GIT_SHA=${{ env.GIT_SHA_SHORT }}
cache-from: type=gha,scope=build-${{ matrix.arch }}
cache-to: type=gha,scope=build-${{ matrix.arch }},mode=max
merge:
runs-on: ubuntu-latest
needs: build
environment: production
steps:
- name: Set short SHA
run: echo "GIT_SHA_SHORT=${GIT_SHA::7}" >> "$GITHUB_ENV"
- uses: docker/setup-buildx-action@v4
- uses: docker/login-action@v4.6.0
with:
registry: registry.dokku.djbender.com
username: ${{ secrets.REGISTRY_USERNAME }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Create multi-arch manifest
run: |
docker buildx imagetools create \
-t ${{ env.IMAGE_NAME }}:${{ env.GIT_SHA_SHORT }} \
-t ${{ env.IMAGE_NAME }}:latest \
${{ env.IMAGE_NAME }}:${{ env.GIT_SHA_SHORT }}-amd64 \
${{ env.IMAGE_NAME }}:${{ env.GIT_SHA_SHORT }}-arm64
- name: Remove intermediate arch tags
run: |
for arch in amd64 arm64; do
skopeo delete "docker://${{ env.IMAGE_NAME }}:${{ env.GIT_SHA_SHORT }}-$arch" || true
done
deploy:
runs-on: ubuntu-latest
needs: merge
environment: production
steps:
- name: Set short SHA
run: echo "GIT_SHA_SHORT=${GIT_SHA::7}" >> "$GITHUB_ENV"
- uses: webfactory/ssh-agent@v0.10.0
with:
ssh-private-key: ${{ secrets.DOKKU_SSH_PRIVATE_KEY }}
- name: Add Dokku to known_hosts
run: ssh-keyscan -p ${{ secrets.DOKKU_PORT }} -H ${{ secrets.DOKKU_HOST }} >> ~/.ssh/known_hosts
- name: Deploy to Dokku
run: |
output=$(ssh -p ${{ secrets.DOKKU_PORT }} dokku@${{ secrets.DOKKU_HOST }} git:from-image lizard ${{ env.IMAGE_NAME }}:${{ env.GIT_SHA_SHORT }} 2>&1 | tee /dev/stderr) && exit 0
if echo "$output" | grep -q "No changes detected"; then
exit 0
else
exit 1
fi