From ee4685b968b8d90b027c5589e42133e9900ebf27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Fri, 1 Jul 2022 14:48:31 +0200 Subject: [PATCH 1/7] Adding multiplatform build arm64 in addition to amd64 --- build-and-test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build-and-test.sh b/build-and-test.sh index 83c26eb..32241a0 100755 --- a/build-and-test.sh +++ b/build-and-test.sh @@ -3,7 +3,7 @@ set -xe # Let's replace the "." by a "-" with some bash magic -docker build -t thecodingmachine/nodejs:${BRANCH}-${VARIANT} -f Dockerfile.${VARIANT} . +docker buildx build --platform=linux/amd64,linux/arm64 -t thecodingmachine/nodejs:${BRANCH}-${VARIANT} -f Dockerfile.${VARIANT} . # Post build unit tests if [[ $VARIANT == *apache ]]; then CONTAINER_CWD=/var/www/html; else CONTAINER_CWD=/usr/src/app; fi @@ -31,4 +31,4 @@ RESULT=`docker run --rm -e CRON_SCHEDULE_1="* * * * * * *" -e CRON_COMMAND_1="wh echo "Tests passed with success" -docker build -t thecodingmachine/nodejs:${VARIANT} -f Dockerfile.${VARIANT} . +docker buildx build --platform=linux/amd64,linux/arm64 -t thecodingmachine/nodejs:${VARIANT} -f Dockerfile.${VARIANT} . From e6e0531d45c2736f497fe6717e1ffd210d3acddf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Fri, 1 Jul 2022 14:49:25 +0200 Subject: [PATCH 2/7] Adding build for NodeJS 18 --- .github/workflows/workflow.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 177c6db..f1f5f17 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -21,12 +21,14 @@ jobs: - variant: '12' - variant: '14' - variant: '16' + - variant: '18' - variant: '6-apache' - variant: '8-apache' - variant: '10-apache' - variant: '12-apache' - variant: '14-apache' - variant: '16-apache' + - variant: '18-apache' runs-on: ubuntu-latest steps: - name: Set up QEMU From 743f233dff0be16deac7e1fe413622734766bbdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Fri, 1 Jul 2022 15:01:37 +0200 Subject: [PATCH 3/7] Fixing build --- build-and-test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build-and-test.sh b/build-and-test.sh index 32241a0..7e2ea6c 100755 --- a/build-and-test.sh +++ b/build-and-test.sh @@ -3,7 +3,7 @@ set -xe # Let's replace the "." by a "-" with some bash magic -docker buildx build --platform=linux/amd64,linux/arm64 -t thecodingmachine/nodejs:${BRANCH}-${VARIANT} -f Dockerfile.${VARIANT} . +docker buildx build --platform=linux/amd64,linux/arm64 --load -t thecodingmachine/nodejs:${BRANCH}-${VARIANT} -f Dockerfile.${VARIANT} . # Post build unit tests if [[ $VARIANT == *apache ]]; then CONTAINER_CWD=/var/www/html; else CONTAINER_CWD=/usr/src/app; fi @@ -31,4 +31,4 @@ RESULT=`docker run --rm -e CRON_SCHEDULE_1="* * * * * * *" -e CRON_COMMAND_1="wh echo "Tests passed with success" -docker buildx build --platform=linux/amd64,linux/arm64 -t thecodingmachine/nodejs:${VARIANT} -f Dockerfile.${VARIANT} . +docker buildx build --platform=linux/amd64,linux/arm64 --load -t thecodingmachine/nodejs:${VARIANT} -f Dockerfile.${VARIANT} . From 170ca4b39265273a3c26bb7881395c1c63e2a1e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Fri, 1 Jul 2022 15:10:55 +0200 Subject: [PATCH 4/7] Fixing build --- .github/workflows/workflow.yml | 11 +++-------- build-and-test.sh | 15 +++++++-------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index f1f5f17..f580a24 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -36,10 +36,6 @@ jobs: - name: Set up Docker Buildx uses: docker/setup-buildx-action@v1 - uses: actions/checkout@v1 - - name: Build and test - run: | - BRANCH="master" VARIANT="${{ matrix.variant }}" ./build-and-test.sh - docker images | grep thecodingmachine/nodejs - name: Login to DockerHub # Merge ~ push. if: ${{ github.event_name == 'push' || github.event_name == 'schedule' }} @@ -47,8 +43,7 @@ jobs: with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - - name: Release - # Merge ~ push. - if: ${{ github.event_name == 'push' || github.event_name == 'schedule' }} + - name: Build, test and push run: | - docker push thecodingmachine/nodejs:${{ matrix.variant}} + BRANCH="master" VARIANT="${{ matrix.variant }}" ./build-and-test.sh + docker images | grep thecodingmachine/nodejs diff --git a/build-and-test.sh b/build-and-test.sh index 7e2ea6c..d342210 100755 --- a/build-and-test.sh +++ b/build-and-test.sh @@ -2,33 +2,32 @@ set -xe -# Let's replace the "." by a "-" with some bash magic -docker buildx build --platform=linux/amd64,linux/arm64 --load -t thecodingmachine/nodejs:${BRANCH}-${VARIANT} -f Dockerfile.${VARIANT} . +docker buildx build --load -t thecodingmachine/nodejs:${VARIANT} -f Dockerfile.${VARIANT} . # Post build unit tests if [[ $VARIANT == *apache ]]; then CONTAINER_CWD=/var/www/html; else CONTAINER_CWD=/usr/src/app; fi # Default user is 1000 -RESULT=`docker run --rm thecodingmachine/nodejs:${BRANCH}-${VARIANT} id -ur` +RESULT=`docker run --rm thecodingmachine/nodejs:${VARIANT} id -ur` [[ "$RESULT" = "1000" ]] # If mounted, default user has the id of the mount directory mkdir user1999 && sudo chown 1999:1999 user1999 ls -al user1999 -RESULT=`docker run --rm -v $(pwd)/user1999:$CONTAINER_CWD thecodingmachine/nodejs:${BRANCH}-${VARIANT} id -ur` +RESULT=`docker run --rm -v $(pwd)/user1999:$CONTAINER_CWD thecodingmachine/nodejs:${VARIANT} id -ur` [[ "$RESULT" = "1999" ]] sudo rm -rf user1999 # Let's check that the crons are actually sending logs in the right place -RESULT=`docker run --rm -e CRON_SCHEDULE_1="* * * * * * *" -e CRON_COMMAND_1="(>&1 echo "foobar")" thecodingmachine/nodejs:${BRANCH}-${VARIANT} sleep 1 2>&1 | grep -oP 'msg=foobar' | head -n1` +RESULT=`docker run --rm -e CRON_SCHEDULE_1="* * * * * * *" -e CRON_COMMAND_1="(>&1 echo "foobar")" thecodingmachine/nodejs:${VARIANT} sleep 1 2>&1 | grep -oP 'msg=foobar' | head -n1` [[ "$RESULT" = "msg=foobar" ]] -RESULT=`docker run --rm -e CRON_SCHEDULE_1="* * * * * * *" -e CRON_COMMAND_1="(>&2 echo "error")" thecodingmachine/nodejs:${BRANCH}-${VARIANT} sleep 1 2>&1 | grep -oP 'msg=error' | head -n1` +RESULT=`docker run --rm -e CRON_SCHEDULE_1="* * * * * * *" -e CRON_COMMAND_1="(>&2 echo "error")" thecodingmachine/nodejs:${VARIANT} sleep 1 2>&1 | grep -oP 'msg=error' | head -n1` [[ "$RESULT" = "msg=error" ]] # Let's check that the cron with a user different from root is actually run. -RESULT=`docker run --rm -e CRON_SCHEDULE_1="* * * * * * *" -e CRON_COMMAND_1="whoami" -e CRON_USER_1="docker" thecodingmachine/nodejs:${BRANCH}-${VARIANT} sleep 1 2>&1 | grep -oP 'msg=docker' | head -n1` +RESULT=`docker run --rm -e CRON_SCHEDULE_1="* * * * * * *" -e CRON_COMMAND_1="whoami" -e CRON_USER_1="docker" thecodingmachine/nodejs:${VARIANT} sleep 1 2>&1 | grep -oP 'msg=docker' | head -n1` [[ "$RESULT" = "msg=docker" ]] echo "Tests passed with success" -docker buildx build --platform=linux/amd64,linux/arm64 --load -t thecodingmachine/nodejs:${VARIANT} -f Dockerfile.${VARIANT} . +docker buildx build --platform=linux/amd64,linux/arm64 --push -t thecodingmachine/nodejs:${VARIANT} -f Dockerfile.${VARIANT} . From b4588695de38c9aedf4dc7f0a637a1dd0a755f5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Fri, 1 Jul 2022 15:20:29 +0200 Subject: [PATCH 5/7] Using latest debian for Node18 --- Dockerfile.10 | 2 +- Dockerfile.10-apache | 2 +- Dockerfile.12 | 2 +- Dockerfile.12-apache | 2 +- Dockerfile.14 | 2 +- Dockerfile.14-apache | 2 +- Dockerfile.16 | 2 +- Dockerfile.16-apache | 2 +- Dockerfile.18 | 4 ++-- Dockerfile.18-apache | 4 ++-- Dockerfile.6 | 2 +- Dockerfile.6-apache | 2 +- Dockerfile.8 | 2 +- Dockerfile.8-apache | 2 +- orbit.yml | 28 ++++++++++++++-------------- utils/Dockerfile.blueprint | 5 +++-- 16 files changed, 33 insertions(+), 32 deletions(-) diff --git a/Dockerfile.10 b/Dockerfile.10 index 233e2eb..6840d25 100644 --- a/Dockerfile.10 +++ b/Dockerfile.10 @@ -137,4 +137,4 @@ CMD [ "node" ] ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] -USER docker \ No newline at end of file +USER docker diff --git a/Dockerfile.10-apache b/Dockerfile.10-apache index ce0788f..2a5dbed 100644 --- a/Dockerfile.10-apache +++ b/Dockerfile.10-apache @@ -229,4 +229,4 @@ CMD ["apache2-foreground"] ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] -USER docker \ No newline at end of file +USER docker diff --git a/Dockerfile.12 b/Dockerfile.12 index 19e9578..188fafc 100644 --- a/Dockerfile.12 +++ b/Dockerfile.12 @@ -137,4 +137,4 @@ CMD [ "node" ] ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] -USER docker \ No newline at end of file +USER docker diff --git a/Dockerfile.12-apache b/Dockerfile.12-apache index b098eff..d9a7d3f 100644 --- a/Dockerfile.12-apache +++ b/Dockerfile.12-apache @@ -229,4 +229,4 @@ CMD ["apache2-foreground"] ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] -USER docker \ No newline at end of file +USER docker diff --git a/Dockerfile.14 b/Dockerfile.14 index dbfad9f..7216c73 100644 --- a/Dockerfile.14 +++ b/Dockerfile.14 @@ -137,4 +137,4 @@ CMD [ "node" ] ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] -USER docker \ No newline at end of file +USER docker diff --git a/Dockerfile.14-apache b/Dockerfile.14-apache index 29fb9f8..88757f9 100644 --- a/Dockerfile.14-apache +++ b/Dockerfile.14-apache @@ -229,4 +229,4 @@ CMD ["apache2-foreground"] ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] -USER docker \ No newline at end of file +USER docker diff --git a/Dockerfile.16 b/Dockerfile.16 index f8396cf..8f8f6b2 100644 --- a/Dockerfile.16 +++ b/Dockerfile.16 @@ -137,4 +137,4 @@ CMD [ "node" ] ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] -USER docker \ No newline at end of file +USER docker diff --git a/Dockerfile.16-apache b/Dockerfile.16-apache index 2fddddf..7248071 100644 --- a/Dockerfile.16-apache +++ b/Dockerfile.16-apache @@ -229,4 +229,4 @@ CMD ["apache2-foreground"] ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] -USER docker \ No newline at end of file +USER docker diff --git a/Dockerfile.18 b/Dockerfile.18 index 9a58c9d..8d7490c 100644 --- a/Dockerfile.18 +++ b/Dockerfile.18 @@ -1,4 +1,4 @@ -FROM debian:stretch-slim +FROM debian:bullseye-slim LABEL authors="Julien Neuhart , David Négrier " @@ -137,4 +137,4 @@ CMD [ "node" ] ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] -USER docker \ No newline at end of file +USER docker diff --git a/Dockerfile.18-apache b/Dockerfile.18-apache index 78fb4e9..8d079ac 100644 --- a/Dockerfile.18-apache +++ b/Dockerfile.18-apache @@ -1,4 +1,4 @@ -FROM debian:stretch-slim +FROM debian:bullseye-slim LABEL authors="Julien Neuhart , David Négrier " @@ -229,4 +229,4 @@ CMD ["apache2-foreground"] ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] -USER docker \ No newline at end of file +USER docker diff --git a/Dockerfile.6 b/Dockerfile.6 index 2df6798..bf9d03f 100644 --- a/Dockerfile.6 +++ b/Dockerfile.6 @@ -137,4 +137,4 @@ CMD [ "node" ] ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] -USER docker \ No newline at end of file +USER docker diff --git a/Dockerfile.6-apache b/Dockerfile.6-apache index 08107c8..700f1a7 100644 --- a/Dockerfile.6-apache +++ b/Dockerfile.6-apache @@ -229,4 +229,4 @@ CMD ["apache2-foreground"] ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] -USER docker \ No newline at end of file +USER docker diff --git a/Dockerfile.8 b/Dockerfile.8 index 55037d1..051024d 100644 --- a/Dockerfile.8 +++ b/Dockerfile.8 @@ -137,4 +137,4 @@ CMD [ "node" ] ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] -USER docker \ No newline at end of file +USER docker diff --git a/Dockerfile.8-apache b/Dockerfile.8-apache index f828455..085a43e 100644 --- a/Dockerfile.8-apache +++ b/Dockerfile.8-apache @@ -229,4 +229,4 @@ CMD ["apache2-foreground"] ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] -USER docker \ No newline at end of file +USER docker diff --git a/orbit.yml b/orbit.yml index fc8bdd4..439c9dc 100644 --- a/orbit.yml +++ b/orbit.yml @@ -19,17 +19,17 @@ tasks: - use: generate short: Generates all Dockerfiles run: - - orbit generate -f utils/Dockerfile.blueprint -o Dockerfile.6 -p "NodeVersion,6.x;Variant,standalone" - - orbit generate -f utils/Dockerfile.blueprint -o Dockerfile.8 -p "NodeVersion,8.x;Variant,standalone" - - orbit generate -f utils/Dockerfile.blueprint -o Dockerfile.10 -p "NodeVersion,10.x;Variant,standalone" - - orbit generate -f utils/Dockerfile.blueprint -o Dockerfile.12 -p "NodeVersion,12.x;Variant,standalone" - - orbit generate -f utils/Dockerfile.blueprint -o Dockerfile.14 -p "NodeVersion,14.x;Variant,standalone" - - orbit generate -f utils/Dockerfile.blueprint -o Dockerfile.16 -p "NodeVersion,16.x;Variant,standalone" - - orbit generate -f utils/Dockerfile.blueprint -o Dockerfile.18 -p "NodeVersion,18.x;Variant,standalone" - - orbit generate -f utils/Dockerfile.blueprint -o Dockerfile.6-apache -p "NodeVersion,6.x;Variant,apache" - - orbit generate -f utils/Dockerfile.blueprint -o Dockerfile.8-apache -p "NodeVersion,8.x;Variant,apache" - - orbit generate -f utils/Dockerfile.blueprint -o Dockerfile.10-apache -p "NodeVersion,10.x;Variant,apache" - - orbit generate -f utils/Dockerfile.blueprint -o Dockerfile.12-apache -p "NodeVersion,12.x;Variant,apache" - - orbit generate -f utils/Dockerfile.blueprint -o Dockerfile.14-apache -p "NodeVersion,14.x;Variant,apache" - - orbit generate -f utils/Dockerfile.blueprint -o Dockerfile.16-apache -p "NodeVersion,16.x;Variant,apache" - - orbit generate -f utils/Dockerfile.blueprint -o Dockerfile.18-apache -p "NodeVersion,18.x;Variant,apache" + - orbit generate -f utils/Dockerfile.blueprint -o Dockerfile.6 -p "NodeVersion,6.x;Variant,standalone;DebianVariant,stretch-slim" + - orbit generate -f utils/Dockerfile.blueprint -o Dockerfile.8 -p "NodeVersion,8.x;Variant,standalone;DebianVariant,stretch-slim" + - orbit generate -f utils/Dockerfile.blueprint -o Dockerfile.10 -p "NodeVersion,10.x;Variant,standalone;DebianVariant,stretch-slim" + - orbit generate -f utils/Dockerfile.blueprint -o Dockerfile.12 -p "NodeVersion,12.x;Variant,standalone;DebianVariant,stretch-slim" + - orbit generate -f utils/Dockerfile.blueprint -o Dockerfile.14 -p "NodeVersion,14.x;Variant,standalone;DebianVariant,stretch-slim" + - orbit generate -f utils/Dockerfile.blueprint -o Dockerfile.16 -p "NodeVersion,16.x;Variant,standalone;DebianVariant,stretch-slim" + - orbit generate -f utils/Dockerfile.blueprint -o Dockerfile.18 -p "NodeVersion,18.x;Variant,standalone;DebianVariant,bullseye-slim" + - orbit generate -f utils/Dockerfile.blueprint -o Dockerfile.6-apache -p "NodeVersion,6.x;Variant,apache;DebianVariant,stretch-slim" + - orbit generate -f utils/Dockerfile.blueprint -o Dockerfile.8-apache -p "NodeVersion,8.x;Variant,apache;DebianVariant,stretch-slim" + - orbit generate -f utils/Dockerfile.blueprint -o Dockerfile.10-apache -p "NodeVersion,10.x;Variant,apache;DebianVariant,stretch-slim" + - orbit generate -f utils/Dockerfile.blueprint -o Dockerfile.12-apache -p "NodeVersion,12.x;Variant,apache;DebianVariant,stretch-slim" + - orbit generate -f utils/Dockerfile.blueprint -o Dockerfile.14-apache -p "NodeVersion,14.x;Variant,apache;DebianVariant,stretch-slim" + - orbit generate -f utils/Dockerfile.blueprint -o Dockerfile.16-apache -p "NodeVersion,16.x;Variant,apache;DebianVariant,stretch-slim" + - orbit generate -f utils/Dockerfile.blueprint -o Dockerfile.18-apache -p "NodeVersion,18.x;Variant,apache;DebianVariant,bullseye-slim" diff --git a/utils/Dockerfile.blueprint b/utils/Dockerfile.blueprint index b5c01f6..06eb15a 100644 --- a/utils/Dockerfile.blueprint +++ b/utils/Dockerfile.blueprint @@ -1,7 +1,8 @@ {{- $node_version := .Orbit.NodeVersion -}} {{- $variant := .Orbit.Variant -}} +{{- $debian_variant := .Orbit.DebianVariant -}} -FROM debian:stretch-slim +FROM debian:{{ $debian_variant }} LABEL authors="Julien Neuhart , David Négrier " @@ -237,4 +238,4 @@ CMD [ "node" ] ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"] -USER docker \ No newline at end of file +USER docker From 99e0c258cfccfa01631414735773c778af482940 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Fri, 1 Jul 2022 15:34:38 +0200 Subject: [PATCH 6/7] Trying to build first on only one target --- build-and-test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-and-test.sh b/build-and-test.sh index d342210..21278df 100755 --- a/build-and-test.sh +++ b/build-and-test.sh @@ -2,7 +2,7 @@ set -xe -docker buildx build --load -t thecodingmachine/nodejs:${VARIANT} -f Dockerfile.${VARIANT} . +docker buildx build --platform=linux/amd64 --load -t thecodingmachine/nodejs:${VARIANT} -f Dockerfile.${VARIANT} . # Post build unit tests if [[ $VARIANT == *apache ]]; then CONTAINER_CWD=/var/www/html; else CONTAINER_CWD=/usr/src/app; fi From 39e9d20c207ab4ccf3174970ac9bdb44439f0bac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20N=C3=A9grier?= Date: Fri, 1 Jul 2022 15:52:33 +0200 Subject: [PATCH 7/7] Fixing build --- .github/workflows/workflow.yml | 2 ++ build-and-test.sh | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index f580a24..903a894 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -44,6 +44,8 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Build, test and push + env: + EVENT_NAME: ${{ github.event_name }} run: | BRANCH="master" VARIANT="${{ matrix.variant }}" ./build-and-test.sh docker images | grep thecodingmachine/nodejs diff --git a/build-and-test.sh b/build-and-test.sh index 21278df..8ad7660 100755 --- a/build-and-test.sh +++ b/build-and-test.sh @@ -30,4 +30,6 @@ RESULT=`docker run --rm -e CRON_SCHEDULE_1="* * * * * * *" -e CRON_COMMAND_1="wh echo "Tests passed with success" -docker buildx build --platform=linux/amd64,linux/arm64 --push -t thecodingmachine/nodejs:${VARIANT} -f Dockerfile.${VARIANT} . +if [[ "$EVENT_NAME" == "push" || "$EVENT_NAME" == "schedule" ]]; then + docker buildx build --platform=linux/amd64,linux/arm64 --push -t thecodingmachine/nodejs:${VARIANT} -f Dockerfile.${VARIANT} . +fi