From c1b2f7edb1b75a1325cebd39664af0b0fcaabe46 Mon Sep 17 00:00:00 2001 From: Veinar Date: Fri, 3 Nov 2023 01:48:13 +0100 Subject: [PATCH 1/3] Created Dockerfile and updated ReadMe Signed-off-by: Veinar --- Dockerfile | 22 ++++++++++++++++++++++ README.md | 9 +++++++++ package.json | 4 ++-- 3 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..dd5dc0f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +FROM alpine:3 + +# Setup env +ENV NODE_OPTIONS=--openssl-legacy-provider + +# Install Node and npm +RUN apk add --update autoconf automake build-base libtool nasm pkgconf nodejs npm git && rm -rf /var/cache/apk/* + +# Change workdir to have separate place for app +WORKDIR /gitops-website + +# Add required files +ADD . . + +# Install dependencies +RUN npm i + +# Expose port for server +EXPOSE 8000 + +# Create entrypoint +ENTRYPOINT ["npm", "start"] \ No newline at end of file diff --git a/README.md b/README.md index 81cab45..d4a8be5 100644 --- a/README.md +++ b/README.md @@ -16,3 +16,12 @@ npm start yarn install yarn start ``` + +**Docker setup** +```shell +# Build docker image from local filesystem +docker build . --no-cache -t website:latest + +# Run docker image with mapping port 80 on your computer +docker run -dit -p 0.0.0.0:80:8000 website:latest +``` diff --git a/package.json b/package.json index 78e247e..e16cf1f 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ ], "scripts": { "develop": "gatsby develop", - "start": "gatsby develop", + "start": "gatsby develop --host=0.0.0.0", "build": "gatsby build", "serve": "gatsby serve", "clean": "gatsby clean", @@ -58,4 +58,4 @@ "postcss": "^8.3.5", "tailwindcss": "^2.2.2" } -} +} \ No newline at end of file From dbf2bd68be701a0c70f6d49679899ffbce5c1587 Mon Sep 17 00:00:00 2001 From: Veinar Date: Sat, 4 Nov 2023 23:03:08 +0100 Subject: [PATCH 2/3] PR requested changes Signed-off-by: Veinar --- Containerfile | 32 ++++++++++++++++++++++++++++++++ Dockerfile | 22 ---------------------- README.md | 8 ++++---- 3 files changed, 36 insertions(+), 26 deletions(-) create mode 100644 Containerfile delete mode 100644 Dockerfile diff --git a/Containerfile b/Containerfile new file mode 100644 index 0000000..be683a1 --- /dev/null +++ b/Containerfile @@ -0,0 +1,32 @@ +# Use the NODE_VERSION argument to specify the Node.js version +ARG NODE_VERSION + +# Use the specified Node.js version as the base image +FROM node:${NODE_VERSION}-alpine + +# Set Node args +ENV NODE_OPTIONS=--openssl-legacy-provider + +RUN apk add --update autoconf automake build-base libtool nasm pkgconf && \ + rm -rf /var/cache/apk/* + +# Setup work directory +WORKDIR /gitops-website + +# Set permissions for non-root user +RUN chown -R node:node /gitops-website + +# Switch user to non-root +USER node + +# Add repo files with correct user:group ownership +ADD --chown=node:node . . + +# Install dependencies +RUN npm ci + +# Expose port for server +EXPOSE 8000 + +# Create entrypoint +ENTRYPOINT ["npm", "start"] \ No newline at end of file diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index dd5dc0f..0000000 --- a/Dockerfile +++ /dev/null @@ -1,22 +0,0 @@ -FROM alpine:3 - -# Setup env -ENV NODE_OPTIONS=--openssl-legacy-provider - -# Install Node and npm -RUN apk add --update autoconf automake build-base libtool nasm pkgconf nodejs npm git && rm -rf /var/cache/apk/* - -# Change workdir to have separate place for app -WORKDIR /gitops-website - -# Add required files -ADD . . - -# Install dependencies -RUN npm i - -# Expose port for server -EXPOSE 8000 - -# Create entrypoint -ENTRYPOINT ["npm", "start"] \ No newline at end of file diff --git a/README.md b/README.md index d4a8be5..5b88785 100644 --- a/README.md +++ b/README.md @@ -19,9 +19,9 @@ yarn start **Docker setup** ```shell -# Build docker image from local filesystem -docker build . --no-cache -t website:latest +# Build container image from local filesystem with Node version as build arg +docker build --build-arg NODE_VERSION=19 --no-cache -t website: -f Containerfile . -# Run docker image with mapping port 80 on your computer -docker run -dit -p 0.0.0.0:80:8000 website:latest +# Run container image with mapping port 80 on your computer +docker run -dit -p 80:8000 website: ``` From c8c28cc242460fcefcf104095f41bfb444ac0d4e Mon Sep 17 00:00:00 2001 From: Veinar Date: Wed, 8 Nov 2023 22:57:10 +0100 Subject: [PATCH 3/3] PR review changes Signed-off-by: Veinar --- .dockerignore | 1 + Containerfile | 4 ++-- README.md | 5 ++++- 3 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..40b878d --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +node_modules/ \ No newline at end of file diff --git a/Containerfile b/Containerfile index be683a1..c72d234 100644 --- a/Containerfile +++ b/Containerfile @@ -1,10 +1,10 @@ # Use the NODE_VERSION argument to specify the Node.js version -ARG NODE_VERSION +ARG NODE_VERSION=20 # Use the specified Node.js version as the base image FROM node:${NODE_VERSION}-alpine -# Set Node args +# Set Node args (do not set in node version 16 and below) ENV NODE_OPTIONS=--openssl-legacy-provider RUN apk add --update autoconf automake build-base libtool nasm pkgconf && \ diff --git a/README.md b/README.md index 5b88785..3812b2b 100644 --- a/README.md +++ b/README.md @@ -19,9 +19,12 @@ yarn start **Docker setup** ```shell +# Build container image from local filesystem with default Node version +docker build --no-cache -t website: -f Containerfile . + # Build container image from local filesystem with Node version as build arg docker build --build-arg NODE_VERSION=19 --no-cache -t website: -f Containerfile . # Run container image with mapping port 80 on your computer -docker run -dit -p 80:8000 website: +docker run -dit -p 8000:8000 website: ```