Skip to content

Commit 6cccbfd

Browse files
authored
feat: add different tags for testing rolling updates (#2)
1 parent 36b43ad commit 6cccbfd

File tree

8 files changed

+117
-16
lines changed

8 files changed

+117
-16
lines changed

.ci/build-container-and-validate-txt-response.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,10 @@ grep -q "^Hello! 👋$" out.txt
1212
grep -q "^UpCloudLtd / hello-container at not-a-co$" out.txt
1313

1414
docker rm -f ${container_id}
15+
16+
EMOJI=🦁 HELLO=Moo NAME=horse bash -xe ./.ci/build-index-files.sh
17+
18+
grep -q "^Moo! 🦁$" out/index.txt
19+
grep -q "^UpCloudLtd / hello-container $" out/index.txt
20+
21+
ls hello-horse.tar.gz

.ci/build-index-files.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh -xe
2+
3+
target=${1:-out}
4+
name=${NAME:-hello}
5+
6+
rm -rf $target
7+
mkdir -p $target
8+
cp index.html index.txt SourceSans3.ttf $target
9+
10+
sed -i "s/build_version_note/${VERSION_NOTE:0:11}/" $target/index.*
11+
sed -i "s/build_emoji/${EMOJI:-👋}/" $target/index.*
12+
sed -i "s/build_hello/${HELLO:-Hello}/" $target/index.*
13+
14+
tar -czvf hello-$name.tar.gz -C $target .

.github/workflows/release.yaml

Lines changed: 60 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,28 @@ name: Release
22

33
on:
44
push:
5-
branches:
6-
- main
5+
tags:
6+
- "v*"
77

88
jobs:
99
build-and-push:
10-
name: Build and push container image
10+
name: Build and push container image (${{ matrix.args.name }})
1111
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
args:
15+
- emoji: 👋
16+
hello: Hello
17+
name: hello
18+
- emoji: 🐅
19+
hello: Roar
20+
name: tiger
21+
- emoji: 🐕
22+
hello: Woof
23+
name: dog
24+
- emoji: 🐄
25+
hello: Moo
26+
name: cow
1227
steps:
1328
- name: Checkout
1429
uses: actions/checkout@v3
@@ -20,9 +35,49 @@ jobs:
2035
password: ${{ secrets.GITHUB_TOKEN }}
2136
- name: Build and push container image to GitHub Container Registry
2237
run: |
23-
docker build . --tag hello-container --build-arg "VERSION_NOTE=at ${GITHUB_SHA}"
38+
docker build . --tag hello-container \
39+
--build-arg "VERSION_NOTE=at ${{ github.ref_name }}" \
40+
--build-arg "EMOJI=${{ matrix.args.emoji }}" \
41+
--build-arg "HELLO=${{ matrix.args.hello }}"
2442
25-
for tag in ${{ github.run_number }} latest; do
43+
tags="${{ matrix.args.name }}-${{ github.ref_name }} ${{ matrix.args.name }}"
44+
if [ "${{ matrix.args.name }}" = "hello" ]; then
45+
tags="$tags latest"
46+
fi
47+
48+
for tag in $tags; do
2649
docker tag hello-container ghcr.io/upcloudltd/hello:$tag
2750
docker push ghcr.io/upcloudltd/hello:$tag
2851
done
52+
- name: Build archive
53+
run: bash -xe ./.ci/build-index-files.sh
54+
env:
55+
VERSION_NOTE: "at ${{ github.ref_name }}"
56+
EMOJI: "${{ matrix.args.emoji }}"
57+
HELLO: "${{ matrix.args.hello }}"
58+
NAME: "${{ matrix.args.name }}"
59+
- name: Stash archive
60+
uses: actions/upload-artifact@v3
61+
with:
62+
name: hello-${{ matrix.args.name }}
63+
path: hello-${{ matrix.args.name }}.tar.gz
64+
upload-files-to-release:
65+
name: Upload build results to release
66+
needs: build-and-push
67+
runs-on: ubuntu-latest
68+
steps:
69+
- name: Checkout
70+
uses: actions/checkout@v3
71+
- name: Unstash archive
72+
uses: actions/download-artifact@v3
73+
with:
74+
path: release/
75+
- name: Upload archive to release
76+
uses: svenstaro/upload-release-action@v2
77+
with:
78+
file: release/*/hello-*.tar.gz
79+
file_glob: true
80+
- name: Upload nginx configuration to release
81+
uses: svenstaro/upload-release-action@v2
82+
with:
83+
file: index.conf

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Temporary test files
2+
out.txt
3+
4+
# Build outputs
5+
hello-*.tar.gz
6+
out/

Dockerfile

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1-
FROM nginx:stable-alpine
1+
FROM alpine:latest as build
22

33
# Should be set to "at $COMMIT_SHA"
44
ARG VERSION_NOTE=""
55

6-
COPY index.html index.txt SourceSans3.ttf /usr/share/nginx/html/
7-
RUN sed -i "s/docker_version_note/${VERSION_NOTE:0:11}/" /usr/share/nginx/html/index.*
6+
ARG EMOJI="👋"
7+
ARG HELLO="Hello"
8+
9+
WORKDIR /work
10+
COPY .ci/build-index-files.sh index.* SourceSans3.ttf ./
11+
RUN ./build-index-files.sh
12+
13+
FROM nginx:stable-alpine
814

915
RUN rm /etc/nginx/conf.d/*
1016
COPY index.conf /etc/nginx/conf.d/
17+
18+
COPY --from=build /work/out/* /usr/share/nginx/html/

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# hello-container
22

3-
Simple container for testing and demonstrating container and pod networking.
3+
Simple container for testing and demonstrating
4+
5+
- container and pod networking, and
6+
- (rolling) deployment updates.
7+
8+
The container runs an nginx server that (from the `/` root route) returns either HTML or TXT response with `Hello! 👋` message as well as containers hostname and address.
49

510
## Usage
611

@@ -25,8 +30,14 @@ Build `hello-container` image with:
2530
```sh
2631
docker build . -t hello-container
2732

28-
# Or with version note
33+
# With version note
2934
docker build . -t hello-container --build-arg "VERSION_NOTE=at $(git rev-parse HEAD)"
35+
36+
# With custom emoji and greeting
37+
docker build . -t hello-container \
38+
--build-arg "VERSION_NOTE=at $(git rev-parse HEAD)" \
39+
--build-arg "EMOJI=🐄" \
40+
--build-arg "HELLO=Moo"
3041
```
3142

3243
Run `hello-container` with:

index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<html lang="en">
22
<head>
3-
<title>Hello!</title>
3+
<title>build_hello!</title>
44
<link
55
rel="icon"
6-
href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>👋</text></svg>"
6+
href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>build_emoji</text></svg>"
77
/>
88
<meta charset="UTF-8" />
99
<style>
@@ -122,7 +122,7 @@
122122
</header>
123123
<main>
124124
<div class="content">
125-
<h1>Hello! 👋</h1>
125+
<h1>build_hello! build_emoji</h1>
126126
<table>
127127
<tbody>
128128
<tr>
@@ -143,7 +143,7 @@ <h1>Hello! 👋</h1>
143143
href="https://github.com/UpCloudLtd/hello-container.git"
144144
>UpCloudLtd / hello-container</a
145145
>
146-
docker_version_note
146+
build_version_note
147147
</footer>
148148
</body>
149149
</html>

index.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
Hello! 👋
1+
build_hello! build_emoji
22

33
Hostname: nginx_hostname
44
Address: nginx_address
55

6-
UpCloudLtd / hello-container docker_version_note
6+
UpCloudLtd / hello-container build_version_note

0 commit comments

Comments
 (0)