Skip to content

Commit

Permalink
feat: add different tags for testing rolling updates (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
kangasta authored Oct 5, 2023
1 parent 36b43ad commit 6cccbfd
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 16 deletions.
7 changes: 7 additions & 0 deletions .ci/build-container-and-validate-txt-response.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,10 @@ grep -q "^Hello! 👋$" out.txt
grep -q "^UpCloudLtd / hello-container at not-a-co$" out.txt

docker rm -f ${container_id}

EMOJI=🦁 HELLO=Moo NAME=horse bash -xe ./.ci/build-index-files.sh

grep -q "^Moo! 🦁$" out/index.txt
grep -q "^UpCloudLtd / hello-container $" out/index.txt

ls hello-horse.tar.gz
14 changes: 14 additions & 0 deletions .ci/build-index-files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh -xe

target=${1:-out}
name=${NAME:-hello}

rm -rf $target
mkdir -p $target
cp index.html index.txt SourceSans3.ttf $target

sed -i "s/build_version_note/${VERSION_NOTE:0:11}/" $target/index.*
sed -i "s/build_emoji/${EMOJI:-👋}/" $target/index.*
sed -i "s/build_hello/${HELLO:-Hello}/" $target/index.*

tar -czvf hello-$name.tar.gz -C $target .
65 changes: 60 additions & 5 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,28 @@ name: Release

on:
push:
branches:
- main
tags:
- "v*"

jobs:
build-and-push:
name: Build and push container image
name: Build and push container image (${{ matrix.args.name }})
runs-on: ubuntu-latest
strategy:
matrix:
args:
- emoji: 👋
hello: Hello
name: hello
- emoji: 🐅
hello: Roar
name: tiger
- emoji: 🐕
hello: Woof
name: dog
- emoji: 🐄
hello: Moo
name: cow
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -20,9 +35,49 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push container image to GitHub Container Registry
run: |
docker build . --tag hello-container --build-arg "VERSION_NOTE=at ${GITHUB_SHA}"
docker build . --tag hello-container \
--build-arg "VERSION_NOTE=at ${{ github.ref_name }}" \
--build-arg "EMOJI=${{ matrix.args.emoji }}" \
--build-arg "HELLO=${{ matrix.args.hello }}"
for tag in ${{ github.run_number }} latest; do
tags="${{ matrix.args.name }}-${{ github.ref_name }} ${{ matrix.args.name }}"
if [ "${{ matrix.args.name }}" = "hello" ]; then
tags="$tags latest"
fi
for tag in $tags; do
docker tag hello-container ghcr.io/upcloudltd/hello:$tag
docker push ghcr.io/upcloudltd/hello:$tag
done
- name: Build archive
run: bash -xe ./.ci/build-index-files.sh
env:
VERSION_NOTE: "at ${{ github.ref_name }}"
EMOJI: "${{ matrix.args.emoji }}"
HELLO: "${{ matrix.args.hello }}"
NAME: "${{ matrix.args.name }}"
- name: Stash archive
uses: actions/upload-artifact@v3
with:
name: hello-${{ matrix.args.name }}
path: hello-${{ matrix.args.name }}.tar.gz
upload-files-to-release:
name: Upload build results to release
needs: build-and-push
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Unstash archive
uses: actions/download-artifact@v3
with:
path: release/
- name: Upload archive to release
uses: svenstaro/upload-release-action@v2
with:
file: release/*/hello-*.tar.gz
file_glob: true
- name: Upload nginx configuration to release
uses: svenstaro/upload-release-action@v2
with:
file: index.conf
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Temporary test files
out.txt

# Build outputs
hello-*.tar.gz
out/
14 changes: 11 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
FROM nginx:stable-alpine
FROM alpine:latest as build

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

COPY index.html index.txt SourceSans3.ttf /usr/share/nginx/html/
RUN sed -i "s/docker_version_note/${VERSION_NOTE:0:11}/" /usr/share/nginx/html/index.*
ARG EMOJI="👋"
ARG HELLO="Hello"

WORKDIR /work
COPY .ci/build-index-files.sh index.* SourceSans3.ttf ./
RUN ./build-index-files.sh

FROM nginx:stable-alpine

RUN rm /etc/nginx/conf.d/*
COPY index.conf /etc/nginx/conf.d/

COPY --from=build /work/out/* /usr/share/nginx/html/
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# hello-container

Simple container for testing and demonstrating container and pod networking.
Simple container for testing and demonstrating

- container and pod networking, and
- (rolling) deployment updates.

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.

## Usage

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

# Or with version note
# With version note
docker build . -t hello-container --build-arg "VERSION_NOTE=at $(git rev-parse HEAD)"

# With custom emoji and greeting
docker build . -t hello-container \
--build-arg "VERSION_NOTE=at $(git rev-parse HEAD)" \
--build-arg "EMOJI=🐄" \
--build-arg "HELLO=Moo"
```

Run `hello-container` with:
Expand Down
8 changes: 4 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<html lang="en">
<head>
<title>Hello!</title>
<title>build_hello!</title>
<link
rel="icon"
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>"
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>"
/>
<meta charset="UTF-8" />
<style>
Expand Down Expand Up @@ -122,7 +122,7 @@
</header>
<main>
<div class="content">
<h1>Hello! 👋</h1>
<h1>build_hello! build_emoji</h1>
<table>
<tbody>
<tr>
Expand All @@ -143,7 +143,7 @@ <h1>Hello! 👋</h1>
href="https://github.com/UpCloudLtd/hello-container.git"
>UpCloudLtd / hello-container</a
>
docker_version_note
build_version_note
</footer>
</body>
</html>
4 changes: 2 additions & 2 deletions index.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Hello! 👋
build_hello! build_emoji

Hostname: nginx_hostname
Address: nginx_address

UpCloudLtd / hello-container docker_version_note
UpCloudLtd / hello-container build_version_note

0 comments on commit 6cccbfd

Please sign in to comment.