diff --git a/.ci/build-container-and-validate-txt-response.sh b/.ci/build-container-and-validate-txt-response.sh index 114f9a8..8ab62e7 100755 --- a/.ci/build-container-and-validate-txt-response.sh +++ b/.ci/build-container-and-validate-txt-response.sh @@ -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 diff --git a/.ci/build-index-files.sh b/.ci/build-index-files.sh new file mode 100755 index 0000000..69d1b9c --- /dev/null +++ b/.ci/build-index-files.sh @@ -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 . diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index e58ca0b..23ba968 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -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 @@ -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 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3d9b284 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +# Temporary test files +out.txt + +# Build outputs +hello-*.tar.gz +out/ diff --git a/Dockerfile b/Dockerfile index 55fbe27..6edf0da 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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/ diff --git a/README.md b/README.md index 2ea369e..7f1e281 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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: diff --git a/index.html b/index.html index 113b8fc..44c6f86 100644 --- a/index.html +++ b/index.html @@ -1,9 +1,9 @@ - Hello! + build_hello!