-
Notifications
You must be signed in to change notification settings - Fork 16
276 lines (257 loc) · 9.9 KB
/
build-promtail-release.yaml
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
name: Build Promtail releases
on:
# Manual trigger
workflow_call:
inputs:
release:
required: true
type: string
permissions:
contents: write
jobs:
build-dynamic:
name: Build dynamically-linked Promtail
runs-on: ${{ matrix.config.uses }}
strategy:
matrix:
config:
- arch: amd64
uses: ubuntu-20.04
- arch: arm64
uses: Ubuntu_ARM64_4C_16G_01
steps:
- name: Checkout grafana/loki, tag ${{inputs.release}}
uses: actions/checkout@v2
with:
repository: grafana/loki
ref: ${{inputs.release}}
fetch-depth: 1
path: ./loki-upstream
- name: Checkout ${{github.repository}}
uses: actions/checkout@v2
with:
fetch-depth: 0
path: ./loki-k8s-operator
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21.8'
- name: Install systemd dependencies
run: |
sudo apt-get update
sudo apt-get install libsystemd-dev -y
- name: Install build-essential
run: |
sudo apt-get update
sudo apt-get install build-essential -y
- name: Build Promtail
working-directory: loki-upstream
run: |
GOHOSTOS=linux GOARCH=${{matrix.config.arch}} make promtail
ldd clients/cmd/promtail/promtail
file clients/cmd/promtail/promtail
- name: Attach promtail-dynamic-${{matrix.config.arch}} artifact to run
uses: actions/upload-artifact@v3
with:
name: promtail-dynamic-${{matrix.config.arch}}
path: ./loki-upstream/clients/cmd/promtail/promtail
test-dynamic:
name: Test dynamically-linked Promtail
runs-on: ${{ matrix.config.uses }}
needs: build-dynamic
# TODO: Also run tests on arm64
strategy:
matrix:
config:
- arch: amd64
uses: ubuntu-20.04
- arch: arm64
uses: Ubuntu_ARM64_4C_16G_01
base: [debian, ubuntu]
steps:
- name: Checkout ${{github.repository}}
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Download the promtail-dynamic-${{matrix.config.arch}} artifact
uses: actions/download-artifact@v3
with:
name: promtail-dynamic-${{matrix.config.arch}}
path: ./dist/
- name: Set up Docker
run: |
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
- name: Build and test ${{matrix.base}} image
# If promtail is borked on this base, the `docker run` invocation will fail
run: |
export DOCKER_BUILDKIT=1
sudo -E docker build . -f promtail-build/dynamic/test/Dockerfile.${{matrix.base}} -t promtail-dynamic-${{matrix.base}}
sudo -E docker run promtail-dynamic-${{matrix.base}}
build-static:
name: Build statically-linked Promtail
runs-on: ubuntu-latest
strategy:
matrix:
arch: [amd64, arm64]
steps:
- name: Checkout grafana/loki, tag ${{inputs.release}}
uses: actions/checkout@v2
with:
repository: grafana/loki
ref: ${{inputs.release}}
fetch-depth: 1
path: ./loki-upstream
- name: Checkout ${{github.repository}}
uses: actions/checkout@v2
with:
fetch-depth: 0
path: ./loki-k8s-operator
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.21.8'
- name: Build Promtail
# We run the make-based build with CGO_ENABLED=0
# because we want statically-linked binaries and
# cross-build for the specified architecture
working-directory: loki-upstream
run: |
CGO_ENABLED=0 GOHOSTOS=linux GOARCH=${{matrix.arch}} make clients/cmd/promtail/promtail
file clients/cmd/promtail/promtail
- name: Attach promtail-static-${{matrix.arch}} artifact to run
uses: actions/upload-artifact@v3
with:
name: promtail-static-${{matrix.arch}}
path: ./loki-upstream/clients/cmd/promtail/promtail
test-static:
name: Test statically-linked Promtail
runs-on: ${{ matrix.config.uses }}
needs: build-static
strategy:
matrix:
config:
- arch: amd64
uses: ubuntu-20.04
- arch: arm64
uses: Ubuntu_ARM64_4C_16G_01
base: [ubuntu]
steps:
- name: Checkout ${{github.repository}}
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Download the promtail-static-${{matrix.config.arch}} artifact
uses: actions/download-artifact@v3
with:
name: promtail-static-${{matrix.config.arch}}
path: ./dist/
- name: Set up Docker
run: |
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
- name: Build and test ${{matrix.base}} image
# If promtail is borked on this base, the `docker run` invocation will fail
run: |
export DOCKER_BUILDKIT=1
sudo -E docker build . -f promtail-build/static/test/Dockerfile.${{matrix.base}} -t promtail-static-${{matrix.base}}
sudo -E docker run promtail-static-${{matrix.base}}
tag:
name: Publish Promtail release to ${{github.repository}}
runs-on: ubuntu-latest
needs: [test-dynamic, test-static]
env:
RELEASE: promtail-${{inputs.release}}
steps:
- name: Checkout grafana/loki, tag ${{inputs.release}}
uses: actions/checkout@v2
with:
repository: grafana/loki
ref: ${{inputs.release}}
fetch-depth: 1
path: ./loki-upstream
- name: Checkout ${{github.repository}}, ${{github.ref}}
uses: actions/checkout@v2
with:
fetch-depth: 0
path: ./loki-k8s-operator
- name: Create shallow tag
# We rebase the commit from the release tag from the upstream loki
# repository on the initial commit of canonical/loki-k8s-operator,
# because GitHub does not allow us to push a shallow tag (tag to a
# commit with no parent), so we "reconcile" the history of the
# two repositories to have the initial commit of canonical/loki-k8s-operator
# as common history.
#
# We also remove the build automation from the tag, as that is not something
# we use, and if we left the .github folder, the pushing of the tag
# to canonical/loki-k8s-operator would fail with:
#
# refusing to allow a GitHub App to create or update workflow \
# `.github/workflows/backport.yml` without `workflows` permission
run: |
initial_operator_commit=$(cd ./loki-k8s-operator && git log ${{github.ref}} --oneline | tail -1 | awk '{ print $1 }')
cd ./loki-upstream
git config user.name github-actions
git config user.email [email protected]
git remote add charm ../loki-k8s-operator
git fetch charm
git rebase "${initial_operator_commit}" --strategy-option ours
echo "Removing build automation from the commit"
git rm -rf .github || true
git rm -rf .circleci || true
git rm -rf .drone || true
git rm .golangci.yml || true
echo "Creating the new commit"
git commit --amend --no-edit
echo "Creating the new tag"
git tag "${RELEASE}"
echo "Pushing the tag to the local ${{github.repository}} clone"
git push charm "${RELEASE}"
echo "Pushing the tag to the upstream ${{github.repository}} repository"
cd ../loki-k8s-operator
git push origin "${RELEASE}"
release:
runs-on: ubuntu-latest
needs: tag
steps:
- name: Download the artifacts
uses: actions/download-artifact@v3
with:
path: artifacts
- name: List artifacts
run: |
find .
- name: Prepare artifacts for release
run: |
mkdir release
for f in artifacts/promtail-*; do cp "${f}/promtail" "release/$(basename ${f})"; done
cd release
for f in *; do gzip ${f}; done
- name: Create GitHub release
uses: ncipollo/release-action@v1
with:
name: "Promtail ${{inputs.release}}"
body: |
Dynamically- and statically-linked builds for Promtail, based on the [upstream '${{inputs.release}}'](https://github.com/grafana/loki/releases/tag/${{inputs.release}}) release of the `grafana/loki` project.
artifacts: release/*
tag: promtail-${{inputs.release}}
token: ${{ secrets.GITHUB_TOKEN }}