From 311f9b6b08c682d22f8b92610ea48c41b689fadd Mon Sep 17 00:00:00 2001 From: breakid Date: Sun, 24 Sep 2023 18:48:24 -0400 Subject: [PATCH 1/2] Modified Dockerfile to build site; added Docker Compose config --- .dockerignore | 21 +++++++++++++-------- Dockerfile | 32 +++++++++++++++++++++++--------- compose.yaml | 10 ++++++++++ 3 files changed, 46 insertions(+), 17 deletions(-) create mode 100644 compose.yaml diff --git a/.dockerignore b/.dockerignore index f1ba3fde..02bbf616 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,12 +1,17 @@ +# Directories +.git/ +.github/ +.idea/ node_modules/ -test + +# Files +.editorconfig +.eslintignore +.gitignore +.travis.yml *.log +docker-compose* Dockerfile* -README.md LICENSE -style.tailwindcss - -.idea/ -.github/ -.travis.yml -.eslintignore +README.md +style.tailwindcss \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 24a2b673..09fd207d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,28 @@ -# Stage 1: build the application -FROM nginx:alpine AS build +# Stage 1: Build site +FROM node:alpine AS build + +WORKDIR /app + +COPY package.json . + +# Install dependencies +RUN npm install + +COPY . . + +# Build site +RUN npm run build + +# Stage 2: Create final image +FROM nginx:alpine + RUN rm -rf /etc/nginx/conf.d/* + COPY nginx.conf /etc/nginx/ -COPY public /usr/share/nginx/html/ -EXPOSE 80 -# Stage 2: final image -FROM alpine:latest -RUN apk add --no-cache nginx && mkdir -p /run/nginx -COPY --from=build /usr/share/nginx/html/ /usr/share/nginx/html/ -COPY --from=build /etc/nginx/nginx.conf /etc/nginx/nginx.conf +# Copy site data to nginx web root +COPY --from=build /app/public/ /usr/share/nginx/html/ + EXPOSE 80 + CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 00000000..fab5b722 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,10 @@ +--- +version: '3' + +services: + cheatsheets: + build: . + image: cheatsheets + restart: unless-stopped + ports: + - 8080:80 \ No newline at end of file From 78042a662b9f629ed5b68c0bbfb47b80b48e1924 Mon Sep 17 00:00:00 2001 From: breakid Date: Sun, 24 Sep 2023 23:35:28 -0400 Subject: [PATCH 2/2] Added a healthcheck to the Dockerfile --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index 09fd207d..96f1d006 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,4 +25,6 @@ COPY --from=build /app/public/ /usr/share/nginx/html/ EXPOSE 80 +HEALTHCHECK CMD curl --fail http://localhost || exit 1 + CMD ["nginx", "-g", "daemon off;"] \ No newline at end of file