From c5f599ee6cdcc142930e6fcd0fc51891657eef8a Mon Sep 17 00:00:00 2001 From: muriukialex Date: Sat, 24 Feb 2024 16:48:23 +0300 Subject: [PATCH] update Dockerfile, add docker-compose, add Makefile --- .dockerignore | 26 ++++++++++++++++++++++++++ Dockerfile | 43 ++++++++++++++++++++++++++++++++++--------- Makefile | 10 ++++++++++ docker-compose.yml | 6 ++++++ 4 files changed, 76 insertions(+), 9 deletions(-) create mode 100644 .dockerignore create mode 100644 Makefile create mode 100644 docker-compose.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..d4d8f0e --- /dev/null +++ b/.dockerignore @@ -0,0 +1,26 @@ +# Include files that you wouldn't want included in your container + +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.vs +**/.vscode +**/.next +**/.cache +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/charts +**/docker-compose* +**/compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/build +**/dist +LICENSE +README.md +**/public/__env.js \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 88fc387..8644b9a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,22 +1,47 @@ -# Choose the Image which has Node installed already -FROM node:18.17-alpine +FROM node:18-alpine as base + +RUN apk add --no-cache g++ make py3-pip libc6-compat -# make the 'app' folder the current working directory WORKDIR /app -# copy both 'package.json' and 'package-lock.json' (if available) COPY package*.json ./ -# install project dependencies +FROM base as builder + +WORKDIR /app + +COPY . . +# Install project dependencies RUN npm install +RUN npm run build + +FROM base as production + +WORKDIR /app + +ENV NODE_ENV=production +# Install only production dependencies +RUN npm ci --only=production + +# Install pm2 process manager RUN npm install pm2@latest -g -# copy project files and folders to the current working directory -COPY . . +RUN addgroup -g 1001 -S nodejs +RUN adduser -S nextjs -u 1001 + +USER nextjs + +# Copy necessary files from builder stage +COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next +COPY --from=builder --chown=nextjs:nodejs /app/next.config.mjs ./ +COPY --from=builder /app/node_modules ./node_modules +COPY --from=builder /app/package.json ./package.json +COPY --from=builder /app/public ./public +COPY --from=builder /app/.env.production ./.env -# specifies that the container will listen on port 3000 EXPOSE 3000 # specifies the command to run when the Docker image is started -ENTRYPOINT ["./entrypoint.sh"] \ No newline at end of file +ENTRYPOINT ["./entrypoint.sh"] + diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..669e4c0 --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +SERVICE_NAME = aws-rstart-labs + +start-app: + docker-compose up + +tear-app: + docker-compose down --rmi $(SERVICE_NAME) + +# Phony targets to avoid conflicts with file names +.PHONY: start-app tear-app \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..9c3e176 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,6 @@ +version: "3" +services: + aws-rstart-labs: + build: . + ports: + - "3000:3000"