From 9ff168317e4fe8614ca0e0cf73fb079cec4fa78e Mon Sep 17 00:00:00 2001 From: Ruakij Date: Mon, 14 Nov 2022 18:59:06 +0100 Subject: [PATCH 1/5] Add build-scripts for own- and multi-arch --- build/docker-multiarch.sh | 9 +++++++++ build/docker-ownarch.sh | 7 +++++++ 2 files changed, 16 insertions(+) create mode 100755 build/docker-multiarch.sh create mode 100644 build/docker-ownarch.sh diff --git a/build/docker-multiarch.sh b/build/docker-multiarch.sh new file mode 100755 index 0000000..825ad80 --- /dev/null +++ b/build/docker-multiarch.sh @@ -0,0 +1,9 @@ +TAG="ruakij/rfmon-to-influx" +PLATFORM="linux/amd64,linux/arm64/v8,linux/arm/v7" +EXTRA_ARGS="" + +docker buildx build \ +--platform $PLATFORM \ +--tag $TAG \ +$EXTRA_ARGS \ +. diff --git a/build/docker-ownarch.sh b/build/docker-ownarch.sh new file mode 100644 index 0000000..f6016ac --- /dev/null +++ b/build/docker-ownarch.sh @@ -0,0 +1,7 @@ +TAG="ruakij/rfmon-to-influx" +EXTRA_ARGS="" + +docker build \ +--tag $TAG \ +$EXTRA_ARGS \ +. From d5c7f0a580e1069db98e20c727647cd720cf8d89 Mon Sep 17 00:00:00 2001 From: Ruakij Date: Mon, 14 Nov 2022 19:13:32 +0100 Subject: [PATCH 2/5] Make apk package install more elegant --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index c1cf0d0..ecda5d2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,9 +11,9 @@ RUN npm install RUN npm prune --production # Install required apk-packages & delete cache -RUN apk update && apk add tcpdump && rm -rf /var/cache/apk/* +RUN apk add --no-cache tcpdump # Bundle app source COPY ./src/ . -CMD ["npm", "run", "start"] \ No newline at end of file +CMD ["npm", "run", "start"] From d5a727c3df54c1389f9cd52e7995d9f4a3d1484b Mon Sep 17 00:00:00 2001 From: Ruakij Date: Mon, 14 Nov 2022 21:19:37 +0100 Subject: [PATCH 3/5] Make executeable --- build/docker-ownarch.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 build/docker-ownarch.sh diff --git a/build/docker-ownarch.sh b/build/docker-ownarch.sh old mode 100644 new mode 100755 From ad8d546b78ae8b5e12d5b3190dc64f4ea5e7b2ee Mon Sep 17 00:00:00 2001 From: Ruakij Date: Mon, 14 Nov 2022 22:39:57 +0100 Subject: [PATCH 4/5] Utilize Multi-stage building to reduce Image-size --- Dockerfile | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index ecda5d2..cf9ab67 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,18 +1,28 @@ -FROM node:16-alpine +# ---- Base ---- +FROM alpine:3 AS base # Create app directory WORKDIR /usr/src/app +# Copy project file +COPY package.json . + +# Install required apk-packages +RUN apk add --no-cache nodejs npm tcpdump + + +# ---- Dependencies ---- +FROM base AS dependencies + # Install app dependencies -COPY package*.json ./ -RUN npm install +RUN npm install --only=production -# remove development dependencies -RUN npm prune --production -# Install required apk-packages & delete cache -RUN apk add --no-cache tcpdump +# ---- Release ---- +FROM base AS release +# copy from build image +COPY --from=dependencies /usr/src/app/ ./ # Bundle app source COPY ./src/ . From 41302b9f9fd95a396e5ff7d428c398198644d0d4 Mon Sep 17 00:00:00 2001 From: Ruakij Date: Mon, 14 Nov 2022 23:02:47 +0100 Subject: [PATCH 5/5] Set bash args as extra-args --- build/docker-multiarch.sh | 2 +- build/docker-ownarch.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build/docker-multiarch.sh b/build/docker-multiarch.sh index 825ad80..2bbc1be 100755 --- a/build/docker-multiarch.sh +++ b/build/docker-multiarch.sh @@ -1,6 +1,6 @@ TAG="ruakij/rfmon-to-influx" PLATFORM="linux/amd64,linux/arm64/v8,linux/arm/v7" -EXTRA_ARGS="" +EXTRA_ARGS="$@" docker buildx build \ --platform $PLATFORM \ diff --git a/build/docker-ownarch.sh b/build/docker-ownarch.sh index f6016ac..c0807a8 100755 --- a/build/docker-ownarch.sh +++ b/build/docker-ownarch.sh @@ -1,5 +1,5 @@ TAG="ruakij/rfmon-to-influx" -EXTRA_ARGS="" +EXTRA_ARGS="$@" docker build \ --tag $TAG \