-
Notifications
You must be signed in to change notification settings - Fork 29
175 lines (156 loc) · 6.15 KB
/
bake-images.yml
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
name: Publish image
on:
schedule:
- cron: '0 2 * * *'
workflow_dispatch:
push:
tags:
- v*
jobs:
build-and-push:
name: Build and push image
strategy:
matrix:
os: [self-hosted-arm64,ubuntu-latest]
platform: [linux/amd64, linux/arm64]
service_name: [frappe, rqdash, nginx]
exclude:
- os: ubuntu-latest
platform: linux/arm64
- os: self-hosted-arm64
platform: linux/amd64
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Checkout latest tag when job is schedule or push
if: github.event_name == 'schedule' || github.event_name == 'push'
id: set-tag
run: |
latest_tag=$(git describe --abbrev=0 --tags)
if [[ "${{ github.ref == 'refs/tags/v*' }}" == 'true' ]]; then
latest-tag=${GITHUB_REF/refs\/tags\//}
fi
echo "Checkout $latest_tag"
git checkout "$latest_tag"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
platforms: ${{ matrix.platform }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ secrets.GHCR_USER }}
password: ${{ secrets.GHCR_TOKEN }}
- name: Set image names (non-frappe)
if: matrix.service_name != 'frappe'
run: |
owner=$( echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]' )
tag=$( cat "$GITHUB_WORKSPACE/frappe_manager/images-tag.json" | jq -rc .${{ matrix.service_name }})
echo "Image tag $tag"
echo "image_name=ghcr.io/${owner}/frappe-manager-${{ matrix.service_name }}:$(basename ${{ matrix.platform }})-${tag}" >> $GITHUB_ENV
- name: Set image names
if: matrix.service_name == 'frappe'
run: |
owner=$( echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]' )
tag=$( cat "$GITHUB_WORKSPACE/frappe_manager/images-tag.json" | jq -rc .${{ matrix.service_name }})
echo "prebake_image_name=ghcr.io/${owner}/frappe-manager-prebake:$(basename ${{ matrix.platform }})-${tag}" >> $GITHUB_ENV
echo "fm_image_name=ghcr.io/${owner}/frappe-manager-${{ matrix.service_name }}:$(basename ${{ matrix.platform }})-${tag}" >> $GITHUB_ENV
- name: Build and push Docker image (non-frappe)
if: matrix.service_name != 'frappe'
uses: docker/build-push-action@v4
with:
context: Docker/${{ matrix.service_name }}/.
push: true
platforms: ${{ matrix.platform }}
tags: ${{ env.image_name }}
provenance: false
- name: Build and push prebake image
if: matrix.service_name == 'frappe'
uses: docker/build-push-action@v4
with:
context: Docker/${{ matrix.service_name }}/.
push: true
platforms: ${{ matrix.platform }}
tags: ${{ env.prebake_image_name }}
target: prebake_image
provenance: false
- name: Build and push fm image
if: matrix.service_name == 'frappe'
uses: docker/build-push-action@v4
with:
context: Docker/${{ matrix.service_name }}/.
push: true
platforms: ${{ matrix.platform }}
tags: ${{ env.fm_image_name }}
target: fm_image
provenance: false
combine:
name: Combine both platform images
needs: build-and-push
strategy:
matrix:
os: [ubuntu-latest]
service_name: [frappe, rqdash, nginx]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Checkout latest tag when job is schedule or push
if: github.event_name == 'schedule' || github.event_name == 'push'
id: set-tag
run: |
latest_tag=$(git describe --abbrev=0 --tags)
if [[ "${{ github.ref == 'refs/tags/v*' }}" == 'true' ]]; then
latest-tag=${GITHUB_REF/refs\/tags\//}
fi
echo "Checkout $latest_tag"
git checkout "$latest_tag"
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ secrets.GHCR_USER }}
password: ${{ secrets.GHCR_TOKEN }}
- name: Combine manifest and push
run: |
tag=$( cat "$GITHUB_WORKSPACE/frappe_manager/images-tag.json" | jq -rc .${{ matrix.service_name }})
owner=$( echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]' )
if [[ "${{ matrix.service_name }}" == "frappe" ]]; then
# Handle prebake image
prebake_img="ghcr.io/${owner}/frappe-manager-prebake"
rm -rf ~/.docker/manifests
docker pull "$prebake_img:amd64-${tag}"
docker pull "$prebake_img:arm64-${tag}"
docker manifest create "$prebake_img":"${tag}" \
--amend "$prebake_img":amd64-${tag} \
--amend "$prebake_img":arm64-${tag}
docker manifest push "$prebake_img:${tag}"
# Handle fm image
fm_img="ghcr.io/${owner}/frappe-manager-${{ matrix.service_name }}"
rm -rf ~/.docker/manifests
docker pull "$fm_img:amd64-${tag}"
docker pull "$fm_img:arm64-${tag}"
docker manifest create "$fm_img":"${tag}" \
--amend "$fm_img":amd64-${tag} \
--amend "$fm_img":arm64-${tag}
docker manifest push "$fm_img:${tag}"
else
# Handle other services normally
img="ghcr.io/${owner}/frappe-manager-${{ matrix.service_name }}"
rm -rf ~/.docker/manifests
docker pull "$img:amd64-${tag}"
docker pull "$img:arm64-${tag}"
docker manifest create "$img":"${tag}" \
--amend "$img":amd64-${tag} \
--amend "$img":arm64-${tag}
docker manifest push "$img:${tag}"
fi
- name: Cleanup
run: |
rm -rf ~/.docker/manifests