-
Notifications
You must be signed in to change notification settings - Fork 0
194 lines (164 loc) · 6.49 KB
/
build_push_release.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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
name: Build and Push Release
on:
push:
tags:
- 'v*'
permissions:
contents: write
jobs:
create_release:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set Env
run: |
VERSION=$(echo "${GITHUB_REF#refs/*/}" | sed 's/^v//')
echo "RELEASE_TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
echo "RELEASE_VERSION=${VERSION}" >> $GITHUB_ENV
- name: Create GitHub Release
id: create_release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if gh release view $RELEASE_TAG &>/dev/null; then
echo "Release $RELEASE_TAG exists. skipping"
else
echo "Release $RELEASE_TAG does not exists. creating..."
RELEASE_NOTES=$(sed -e "/^## ${RELEASE_TAG}/,/^## / ! d" CHANGELOG.md | tail -n +2 | head -n -1)
gh release create $RELEASE_TAG \
--generate-notes \
--title $RELEASE_TAG \
--notes "$RELEASE_NOTES"
fi
create_release_arm64:
runs-on: ubuntu-latest-4-cores-arm64
needs: create_release
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set Env
run: |
VERSION=$(echo "${GITHUB_REF#refs/*/}" | sed 's/^v//')
echo "RELEASE_TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
echo "RELEASE_VERSION=${VERSION}" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
install: true
- name: Build release artifacts for arm64
run: |
docker buildx build --platform linux/arm64/v8 --output type=local,dest=docker_output/ -t peridiod:${RELEASE_TAG} -f support/Containerfile-release.arm64 .
- name: Upload Release Asset
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
mv ./docker_output/arm64/peridiod-${RELEASE_VERSION}.tar.gz ./docker_output/peridiod-${RELEASE_VERSION}-arm64.tar.gz
gh release upload $RELEASE_TAG ./docker_output/peridiod-${RELEASE_VERSION}-arm64.tar.gz --clobber
- name: Load docker hub credentials
id: op-load-docker-hub-credentials
uses: 1password/load-secrets-action@v1
with:
export-env: false
env:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
DOCKER_HUB_USERNAME: op://ci-cd/docker-hub-machine/username
DOCKER_HUB_PASSWORD: op://ci-cd/docker-hub-machine/password
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ steps.op-load-docker-hub-credentials.outputs.DOCKER_HUB_USERNAME }}
password: ${{ steps.op-load-docker-hub-credentials.outputs.DOCKER_HUB_PASSWORD }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./Containerfile
platforms: linux/arm64/v8
push: false
tags: |
peridio/peridiod:${{ env.RELEASE_TAG }}
peridio/peridiod:latest
outputs: type=image,name=peridio/peridiod:${{ env.RELEASE_TAG }},buildinfo
create_release_amd64:
runs-on: ubuntu-latest
needs: create_release
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set Env
run: |
VERSION=$(echo "${GITHUB_REF#refs/*/}" | sed 's/^v//')
echo "RELEASE_TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
echo "RELEASE_VERSION=${VERSION}" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
install: true
- name: Build release artifacts for amd64
run: |
docker buildx build --platform linux/amd64 --output type=local,dest=docker_output/ -t peridiod:${RELEASE_TAG} -f support/Containerfile-release.amd64 .
- name: Upload Release Asset
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
mv ./docker_output/amd64/peridiod-${RELEASE_VERSION}.tar.gz ./docker_output/peridiod-${RELEASE_VERSION}-amd64.tar.gz
gh release upload $RELEASE_TAG ./docker_output/peridiod-${RELEASE_VERSION}-amd64.tar.gz --clobber
- name: Load docker hub credentials
id: op-load-docker-hub-credentials
uses: 1password/load-secrets-action@v1
with:
export-env: false
env:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
DOCKER_HUB_USERNAME: op://ci-cd/docker-hub-machine/username
DOCKER_HUB_PASSWORD: op://ci-cd/docker-hub-machine/password
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ steps.op-load-docker-hub-credentials.outputs.DOCKER_HUB_USERNAME }}
password: ${{ steps.op-load-docker-hub-credentials.outputs.DOCKER_HUB_PASSWORD }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./Containerfile
platforms: linux/amd64
push: false
tags: |
peridio/peridiod:${{ env.RELEASE_TAG }}
peridio/peridiod:latest
outputs: type=image,name=peridio/peridiod:${{ env.RELEASE_TAG }},buildinfo
push_container_images:
runs-on: ubuntu-latest
needs: [create_release_arm64, create_release_amd64]
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set Env
run: |
echo "RELEASE_TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
- name: Load docker hub credentials
id: op-load-docker-hub-credentials
uses: 1password/load-secrets-action@v1
with:
export-env: false
env:
OP_SERVICE_ACCOUNT_TOKEN: ${{ secrets.OP_SERVICE_ACCOUNT_TOKEN }}
DOCKER_HUB_USERNAME: op://ci-cd/docker-hub-machine/username
DOCKER_HUB_PASSWORD: op://ci-cd/docker-hub-machine/password
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ steps.op-load-docker-hub-credentials.outputs.DOCKER_HUB_USERNAME }}
password: ${{ steps.op-load-docker-hub-credentials.outputs.DOCKER_HUB_PASSWORD }}
- name: Create and Push Manifest
run: |
docker manifest create peridio/peridiod:${{ env.RELEASE_TAG }} \
--amend peridio/peridiod:${{ env.RELEASE_TAG }}-amd64 \
--amend peridio/peridiod:${{ env.RELEASE_TAG }}-arm64-v8
docker manifest create peridio/peridiod:latest \
--amend peridio/peridiod:latest-amd64 \
--amend peridio/peridiod:latest-arm64-v8
docker manifest push peridio/peridiod:${{ env.RELEASE_TAG }}
docker manifest push peridio/peridiod:latest