Skip to content

Commit 10707a5

Browse files
committed
fix(ui): Provide prebuilt UI assets in release
In #5113 I removed the build artifacts from our source repo. This complicated the packaging process for downstream maintainers significantly. We will still not check the artifacts into our repo directly, since this is a burden to the review process and opens us up to attacks such as the https://en.wikipedia.org/wiki/XZ_Utils_backdoor . Instead we provide two new mechanisms to obtain the artifacts: * alertmanager-web-ui-(file <VERSION).tar.gz will provide the `dist` folder needed for calling `make build`. * We will upload artifacts via actions/upload-artifact. These can then be easily retrieved for 90 days using `gh`. Finally, this commit also ensures that `ui/app/dist` is always available during build steps. The reason is that caching `npm` dependencies is not sufficient: `Elm` will download its files again anyway, since it stores them in `~/.elm`. This causes unnecessary network calls. Technical approach: * By moving the validation `.build_stamp` to `dist/`, we don't have to upload that file seperately. `embed` will exclude that file. * Storing artifacts in `.tarballs` is our method for including files in the release. This approach was directly taken from `prometheus/prometheus`. Relates-to: #5173 Fixes: #5163 Signed-off-by: Solomon Jacobs <solomonjacobs@protonmail.com>
1 parent c769adc commit 10707a5

4 files changed

Lines changed: 33 additions & 12 deletions

File tree

.github/workflows/ci.yml

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,29 @@ jobs:
2222
- run: make assets
2323
- run: make apiv2
2424
- run: git diff --exit-code
25+
- run: make assets-tarball
26+
- uses: prometheus/promci-artifacts/save@f9a587dbc0b2c78a0c54f8ad1cde71ea29a4b76f # v0.1.0
27+
with:
28+
directory: .tarballs
29+
- uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v4.6.2
30+
with:
31+
name: ui-dist
32+
path: ui/app/dist
33+
include-hidden-files: true
2534

2635
build:
2736
name: Build Alertmanager for common architectures
37+
needs: [test_frontend]
2838
runs-on: ubuntu-latest
2939
strategy:
3040
matrix:
3141
thread: [0, 1, 2]
3242
steps:
3343
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v4.0.0
44+
- uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
45+
with:
46+
name: ui-dist
47+
path: ui/app/dist
3448
- uses: prometheus/promci/build@42c3c84c865e5c1ab78543b929f7341eb2ef6123 # v0.6.1
3549
with:
3650
promu_opts: "-p linux/amd64 -p windows/amd64 -p linux/arm64 -p darwin/amd64 -p darwin/arm64 -p linux/386"
@@ -40,6 +54,7 @@ jobs:
4054
test:
4155
name: Test
4256
runs-on: ubuntu-latest
57+
needs: [test_frontend]
4358
# Whenever the Go version is updated here, .promu.yml
4459
# should also be updated.
4560
container:
@@ -58,14 +73,10 @@ jobs:
5873
EMAIL_AUTH_CONFIG: testdata/auth.yml
5974
steps:
6075
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
61-
- id: cache-paths
62-
run: echo "npm-cache=$(npm config get cache)" >> $GITHUB_OUTPUT
63-
- uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5.0.4
76+
- uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
6477
with:
65-
path: ${{ steps.cache-paths.outputs.npm-cache }}
66-
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
67-
restore-keys: |
68-
${{ runner.os }}-node-
78+
name: ui-dist
79+
path: ui/app/dist
6980
- uses: prometheus/promci-setup@5af30ba8c199a91d6c04ebdc3c48e630e355f62d # v0.1.0
7081
- run: make
7182
- run: git diff --exit-code

.github/workflows/release.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ jobs:
1818
needs: ci
1919
steps:
2020
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
21+
- uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4.1.8
22+
with:
23+
name: ui-dist
24+
path: ui/app/dist
2125
- uses: prometheus/promci/build@42c3c84c865e5c1ab78543b929f7341eb2ef6123 # v0.6.1
2226
with:
2327
parallelism: 12

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ lint: ui-elm common-lint
3838
.PHONY: assets
3939
assets: $(FRONTEND_DIR)/src/Data ui-elm template/email.tmpl
4040

41+
.PHONY: assets-tarball
42+
assets-tarball: ui-elm
43+
mkdir -p .tarballs
44+
tar cf ".tarballs/alertmanager-web-ui-$(file <VERSION).tar" -C ui/app dist
45+
4146
.PHONY: ui-elm
4247
ui-elm:
4348
cd $(FRONTEND_DIR) && $(MAKE) build

ui/app/Makefile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,13 @@ else
8282
endif
8383

8484
.PHONY: build
85-
build: .build_stamp
85+
build: dist/.build_stamp
8686

87-
.build_stamp: $(ELM_FILES) index.html vite.config.mjs node_modules
87+
dist/.build_stamp: $(ELM_FILES) index.html vite.config.mjs package-lock.json
8888
@echo ">> building frontend"
89+
$(MAKE) node_modules
8990
$(NPM) run build
90-
@touch .build_stamp
91+
@touch dist/.build_stamp
9192

9293
src/Data: ../../api/v2/openapi.yaml
9394
-rm -rf src/Data src/DateTime.elm
@@ -98,8 +99,8 @@ src/Data: ../../api/v2/openapi.yaml
9899
-v ${PWD}/src:/output/src \
99100
$(OPENAPI_GEN_IMAGE) \
100101
-c 'java -jar /opt/openapi-generator/modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i /local/api/v2/openapi.yaml -g elm -o /tmp/openapi-gen && cp -r /tmp/openapi-gen/src/Data /output/src/Data && cp /tmp/openapi-gen/src/DateTime.elm /output/src/DateTime.elm'
101-
make format
102+
$(MAKE) format
102103

103104
.PHONY: clean
104105
clean:
105-
- @rm -rf .build_stamp dist elm-stuff src/Data src/DateTime.elm openapi-* elm-*
106+
- @rm -rf dist node_modules elm-stuff src/Data src/DateTime.elm openapi-* elm-*

0 commit comments

Comments
 (0)