-
-
Notifications
You must be signed in to change notification settings - Fork 13
207 lines (174 loc) · 6.78 KB
/
build.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
195
196
197
198
199
200
201
202
203
204
205
206
207
name: Docker
on:
# schedule:
# - cron: '0 10 1 * *'
push:
branches: [ master ]
# Publish semver tags as releases.
tags: [ '*.*.*' ]
pull_request:
branches: [ master ]
env:
# github.repository as <account>/<repo>
IMAGE_NAME: byjg/easy-haproxy
jobs:
Test:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install requirements
run: |
cd src/
pip install -r requirements.txt
- name: Run tests
run: |
cd src/
pytest -s tests/ -vv
Build:
runs-on: ubuntu-latest
needs: Test
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log into registry
if: github.event_name != 'pull_request' || github.event.inputs.push == 'true'
uses: docker/login-action@v3
with:
registry: ${{ secrets.DOCKER_REGISTRY }}
username: ${{ secrets.DOCKER_REGISTRY_USER }}
password: ${{ secrets.DOCKER_REGISTRY_TOKEN }}
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ secrets.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}
- uses: actions/github-script@v6
id: tags
with:
script: |
tags = `${{ join(steps.meta.outputs.tags, ',') }}`
result = []
tags.split("\n").forEach(function (item) {
short_tag = item.trim().split(":")[1];
if (short_tag == "master" || short_tag == "main") {
result.push("latest");
} else if (short_tag != "latest") {
result.push(short_tag);
}
})
return result.join(",");
result-encoding: string
- name: Get Tags
run: |
echo "${{ steps.tags.outputs.result }}"
- uses: actions/github-script@v6
id: normalized
with:
script: |
tags = `${{ join(steps.meta.outputs.tags, ',') }}`
result = []
tags.split("\n").forEach(function (item) {
short_tag = item.trim().split(":")[1];
if (short_tag == "master" || short_tag == "main") {
result.push("${{ env.IMAGE_NAME }}:latest");
} else if (short_tag != "latest") {
result.push("${{ env.IMAGE_NAME }}:" + short_tag);
}
})
return result.join(",");
result-encoding: string
- name: Get Normalized Docker Image
run: |
echo "${{ steps.normalized.outputs.result }}"
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: build/Dockerfile
build-args: |
RELEASE_VERSION_ARG="${{ steps.tags.outputs.result }}"
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' || github.event.inputs.push == 'true' }}
tags: ${{ steps.normalized.outputs.result }}
labels: ${{ steps.meta.outputs.labels }}
outputs:
tags: "${{ steps.tags.outputs.result }}"
# - name: Docker Hub Description
# if: github.event_name != 'pull_request' || github.event.inputs.push == 'true'
# run: |
# wget -q https://github.com/christian-korneck/docker-pushrm/releases/download/v1.8.0/docker-pushrm_linux_amd64 -O $HOME/.docker/cli-plugins/docker-pushrm
# chmod +x $HOME/.docker/cli-plugins/docker-pushrm
# docker pushrm ${{ env.IMAGE_NAME }}
Helm:
runs-on: 'ubuntu-latest'
needs: Build
if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')
env:
DOC_GITHUB_TOKEN: '${{ secrets.DOC_TOKEN }}'
steps:
- uses: actions/checkout@v4
if: startsWith(github.ref, 'refs/tags/')
with:
ref: master
- uses: actions/checkout@v4
if: github.ref == 'refs/heads/master'
- name: Get result
run: echo "${{ needs.Build.outputs.tags }}"
- name: Update versions
if: startsWith(github.ref, 'refs/tags/')
run: |
TAG="${{ needs.Build.outputs.tags }}"
CURRENT_VERSION=$(grep "appVersion: " helm/easyhaproxy/Chart.yaml | sed 's#appVersion: "\(.*\)"#\1#g')
if [ "$TAG" = "$CURRENT_VERSION" ]; then
echo "Skipping version $CURRENT_VERSION..."
elif [ "$TAG" = "latest" ]; then
echo "Skipping latest version..."
else
sed -i "s#easy-haproxy:[a-zA-Z0-9\.-]*#easy-haproxy:$TAG#g" deploy/docker/docker-compose.yml
sed -i "s#version: \"[a-zA-Z0-9\.-]*\"#version: \"$TAG\"#g" deploy/kubernetes/easyhaproxy-*.yml
sed -i "s#easy-haproxy:[a-zA-Z0-9\.-]*#easy-haproxy:$TAG#g" deploy/kubernetes/easyhaproxy-*.yml
sed -i "s#easy-haproxy/[a-zA-Z0-9\.-]*/#easy-haproxy/$TAG/#g" docs/kubernetes.md
sed -i "s#appVersion: \"[a-zA-Z0-9\.-]*\"#appVersion: \"$TAG\"#g" helm/easyhaproxy/Chart.yaml
find examples -type f -name '*.yml' -exec sed -i "s#\(byjg/easy-haproxy:\)[a-zA-Z0-9\.-]*#\1$TAG#g" {} \; -print
VERSION=$(grep "version: " helm/easyhaproxy/Chart.yaml | sed 's#version: ##g')
NEW_VERSION=$(echo $VERSION | awk -F. '/[0-9]+\./{$NF++;print}' OFS=.)
sed -i "s#version: [a-zA-Z0-9\.]*#version: $NEW_VERSION#g" helm/easyhaproxy/Chart.yaml
sed -i "s#chart: easyhaproxy-[a-zA-Z0-9\.]*#chart: easyhaproxy-$NEW_VERSION#g" deploy/kubernetes/easyhaproxy-*.yml
git add .
git config --global user.name "$GITHUB_ACTOR CI/CD"
git config --global user.email "[email protected]"
git commit -m "[skip ci] Update from $CURRENT_VERSION to $TAG"
git push
fi
HelmDeploy:
if: github.ref == 'refs/heads/master'
needs: Helm
uses: byjg/byjg.github.io/.github/workflows/add-helm.yaml@master
with:
repo: ${{ github.event.repository.name }}
folder: helm
project: easyhaproxy
secrets: inherit
Documentation:
if: github.ref == 'refs/heads/master'
needs: HelmDeploy
uses: byjg/byjg.github.io/.github/workflows/add-doc.yaml@master
with:
folder: devops
project: ${{ github.event.repository.name }}
secrets: inherit