From b1d579851e71bc36fc748bf9c606ed41de512302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20M=C3=BCller?= Date: Fri, 14 Oct 2022 23:52:16 +0200 Subject: [PATCH 1/8] added multiarch support --- .github/workflows/build-and-publish-container-image.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/build-and-publish-container-image.yaml b/.github/workflows/build-and-publish-container-image.yaml index 67fb06a9..0510d909 100644 --- a/.github/workflows/build-and-publish-container-image.yaml +++ b/.github/workflows/build-and-publish-container-image.yaml @@ -17,6 +17,11 @@ jobs: CONTAINER_IMAGE: paulbouwer/hello-kubernetes steps: + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + with: + platforms: linux/amd64,linux/arm64 + install: true - name: Checkout code uses: actions/checkout@v2 From 0cf29a59a911dba91d0441bbc4bd084231235c9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20M=C3=BCller?= Date: Sat, 15 Oct 2022 00:02:15 +0200 Subject: [PATCH 2/8] added arm64 platform --- .github/workflows/build-and-publish-container-image.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-publish-container-image.yaml b/.github/workflows/build-and-publish-container-image.yaml index 0510d909..126c4c65 100644 --- a/.github/workflows/build-and-publish-container-image.yaml +++ b/.github/workflows/build-and-publish-container-image.yaml @@ -20,7 +20,6 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 with: - platforms: linux/amd64,linux/arm64 install: true - name: Checkout code @@ -39,6 +38,7 @@ jobs: - name: Build image run: | docker build --tag "$IMAGE:$IMAGE_VERSION" \ + --platform linux/amd64,linux/arm64 \ --build-arg IMAGE_VERSION="$IMAGE_VERSION" \ --build-arg IMAGE_CREATE_DATE="`date -u +"%Y-%m-%dT%H:%M:%SZ"`" \ --build-arg IMAGE_SOURCE_REVISION="`git rev-parse HEAD`" \ From f97595fe53ce4434c579ea46326f1d1db63fb1f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20M=C3=BCller?= Date: Tue, 31 Jan 2023 10:20:10 +0100 Subject: [PATCH 3/8] made footer os multi arch --- src/app/server.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/app/server.js b/src/app/server.js index 303358d8..46535230 100644 --- a/src/app/server.js +++ b/src/app/server.js @@ -33,8 +33,8 @@ var podName = process.env.KUBERNETES_POD_NAME || os.hostname(); var nodeName = process.env.KUBERNETES_NODE_NAME || '-'; var nodeOS = os.type() + ' ' + os.release(); var applicationVersion = JSON.parse(fs.readFileSync('package.json', 'utf8')).version; -var containerImage = process.env.CONTAINER_IMAGE || 'paulbouwer/hello-kubernetes:' + applicationVersion -var containerImageArch = JSON.parse(fs.readFileSync('info.json', 'utf8')).containerImageArch; +var containerImage = process.env.CONTAINER_IMAGE || 'paulbouwer/hello-kubernetes:' + applicationVersion; +var containerImageArch = os.platform() + '/' + os.arch(); logger.debug(); logger.debug('Configuration'); @@ -79,4 +79,4 @@ logger.debug('-----------------------------------------------------'); app.listen(port, function () { logger.info("Listening on: http://%s:%s", podName, port); -}); \ No newline at end of file +}); From 6eaa7e87b74da2c97330c7ebe8958b972a517cdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20M=C3=BCller?= Date: Tue, 31 Jan 2023 09:42:14 +0000 Subject: [PATCH 4/8] Make build target dynamic --- .github/workflows/build-and-publish-container-image.yaml | 2 +- src/app/README.md | 1 - src/app/info.json | 3 --- 3 files changed, 1 insertion(+), 5 deletions(-) delete mode 100644 src/app/info.json diff --git a/.github/workflows/build-and-publish-container-image.yaml b/.github/workflows/build-and-publish-container-image.yaml index 126c4c65..482da9e0 100644 --- a/.github/workflows/build-and-publish-container-image.yaml +++ b/.github/workflows/build-and-publish-container-image.yaml @@ -14,7 +14,7 @@ jobs: env: CONTAINER_REGISTRY: docker.io - CONTAINER_IMAGE: paulbouwer/hello-kubernetes + CONTAINER_IMAGE: ${{ github.repository }} steps: - name: Set up Docker Buildx diff --git a/src/app/README.md b/src/app/README.md index 6cf40c09..acde9451 100644 --- a/src/app/README.md +++ b/src/app/README.md @@ -28,4 +28,3 @@ The application relies on the following files for configuration and operational | File | Required | Information | Description | | ---- | -------- | ----------- | ----------- | | package.json | Yes | `.version` | The release version is used when the CONTAINER_IMAGE env is not provided. | -| info.json | Yes | `.containerImageArch` | The container image architecture is used for display. This file will be overwritten in future versions as part of the container image build process when multi-arch images are supported. | \ No newline at end of file diff --git a/src/app/info.json b/src/app/info.json deleted file mode 100644 index 911ef762..00000000 --- a/src/app/info.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "containerImageArch": "linux/amd64" -} \ No newline at end of file From f9b3f8d5eb9318872c48bdf56a894f9b4bc919dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20M=C3=BCller?= Date: Tue, 31 Jan 2023 09:54:03 +0000 Subject: [PATCH 5/8] lowercase repo --- .github/workflows/build-and-publish-container-image.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-and-publish-container-image.yaml b/.github/workflows/build-and-publish-container-image.yaml index 482da9e0..aa5f6de6 100644 --- a/.github/workflows/build-and-publish-container-image.yaml +++ b/.github/workflows/build-and-publish-container-image.yaml @@ -14,9 +14,12 @@ jobs: env: CONTAINER_REGISTRY: docker.io - CONTAINER_IMAGE: ${{ github.repository }} steps: + - name: Lowercase env + run: | + echo "CONTAINER_IMAGE=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV} + - name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 with: From 72a2b7e1d2e3b599ef93b4094ca3f3020baedd5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20M=C3=BCller?= Date: Tue, 31 Jan 2023 10:44:21 +0000 Subject: [PATCH 6/8] use docker build actions --- .../build-and-publish-container-image.yaml | 120 ++++++++++-------- 1 file changed, 67 insertions(+), 53 deletions(-) diff --git a/.github/workflows/build-and-publish-container-image.yaml b/.github/workflows/build-and-publish-container-image.yaml index aa5f6de6..e69c9ede 100644 --- a/.github/workflows/build-and-publish-container-image.yaml +++ b/.github/workflows/build-and-publish-container-image.yaml @@ -1,63 +1,77 @@ name: "When a release tag is created, build and publish a new version of the container image" on: - - create - + create: + push: + branches: + - "**" + tags: + - "v*.*.*" + pull_request: + branches: + - "main" jobs: - build-and-push-container-image: - runs-on: ubuntu-latest - - if: startsWith(github.ref, 'refs/tags/v') - - env: - CONTAINER_REGISTRY: docker.io - steps: - - name: Lowercase env + - + name: Checkout + uses: actions/checkout@v3 + - + name: Initialize Environment run: | - echo "CONTAINER_IMAGE=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV} - - - name: Set up Docker Buildx + echo "IMAGE_VERSION=$(cat src/app/package.json | jq -r .version)" >> $GITHUB_ENV + echo "IMAGE_CREATE_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> $GITHUB_ENV + echo "IMAGE_SOURCE_REVISION=$(git rev-parse HEAD)" >> $GITHUB_ENV + - + name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + # list of Docker images to use as base name for tags + images: | + ${{ github.repository }} + ghcr.io/${{ github.repository }} + # generate Docker tags based on the following events/attributes + tags: | + type=schedule + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=sha + - + name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - + name: Set up Docker Buildx uses: docker/setup-buildx-action@v2 + - + name: Login to Docker Hub + if: github.event_name != 'pull_request' + uses: docker/login-action@v2 with: - install: true - - - name: Checkout code - uses: actions/checkout@v2 - - - name: Build image and version variables - run: | - echo "IMAGE=$CONTAINER_REGISTRY/$CONTAINER_IMAGE" >> $GITHUB_ENV - echo "IMAGE_VERSION=$(cat src/app/package.json | jq -r .version)" >> $GITHUB_ENV - - - name: Build additional image tag variables - run: | - echo "IMAGE_MAJOR_VERSION=$(echo $IMAGE_VERSION | cut -d '.' -f1)" >> $GITHUB_ENV - echo "IMAGE_MINOR_VERSION=$(echo $IMAGE_VERSION | cut -d '.' -f2)" >> $GITHUB_ENV - - - name: Build image - run: | - docker build --tag "$IMAGE:$IMAGE_VERSION" \ - --platform linux/amd64,linux/arm64 \ - --build-arg IMAGE_VERSION="$IMAGE_VERSION" \ - --build-arg IMAGE_CREATE_DATE="`date -u +"%Y-%m-%dT%H:%M:%SZ"`" \ - --build-arg IMAGE_SOURCE_REVISION="`git rev-parse HEAD`" \ - --file src/app/Dockerfile src/app - - - name: Create additional image tags - run: | - docker tag $IMAGE:$IMAGE_VERSION $IMAGE:$IMAGE_MAJOR_VERSION - docker tag $IMAGE:$IMAGE_VERSION $IMAGE:$IMAGE_MAJOR_VERSION.$IMAGE_MINOR_VERSION - - - name: Log into registry - run: echo "${{ secrets.DOCKERHUB_PASSWORD }}" | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin - - - name: Push image and tags to registry - run: | - docker push $IMAGE:$IMAGE_VERSION - docker push $IMAGE:$IMAGE_MAJOR_VERSION - docker push $IMAGE:$IMAGE_MAJOR_VERSION.$IMAGE_MINOR_VERSION - + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - + name: Login to GHCR + if: github.event_name != 'pull_request' + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - + name: Build and push + uses: docker/build-push-action@v3 + with: + context: src/app + platforms: linux/amd64,linux/arm64 + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + build-args: | + "IMAGE_VERSION=${{ env.IMAGE_VERSION }}" + "IMAGE_CREATE_DATE=${{ env.IMAGE_CREATE_DATE }}" + "IMAGE_SOURCE_REVISION=${{ env.IMAGE_SOURCE_REVISION }}" From fc04d68323c78dce7efe7c7a884be3cded781586 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20M=C3=BCller?= Date: Tue, 31 Jan 2023 10:47:13 +0000 Subject: [PATCH 7/8] fix docker hub secret name --- .github/workflows/build-and-publish-container-image.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-publish-container-image.yaml b/.github/workflows/build-and-publish-container-image.yaml index e69c9ede..d84bb9cb 100644 --- a/.github/workflows/build-and-publish-container-image.yaml +++ b/.github/workflows/build-and-publish-container-image.yaml @@ -53,7 +53,7 @@ jobs: uses: docker/login-action@v2 with: username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} - name: Login to GHCR if: github.event_name != 'pull_request' From 58e7eb7e826f6f8f41153be49f456e0cfabc2f9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20M=C3=BCller?= Date: Tue, 31 Jan 2023 11:07:15 +0000 Subject: [PATCH 8/8] update node --- src/app/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/app/Dockerfile b/src/app/Dockerfile index a61d1b77..b07ec88f 100644 --- a/src/app/Dockerfile +++ b/src/app/Dockerfile @@ -1,4 +1,4 @@ -FROM node:16-alpine3.13 +FROM node:19-alpine ARG IMAGE_CREATE_DATE ARG IMAGE_VERSION