From 05950c2670011e1e0b0e5b5b70179eeced75d673 Mon Sep 17 00:00:00 2001 From: aleks Date: Sat, 8 Jun 2024 16:45:47 +0500 Subject: [PATCH 1/3] feat: add Dockerfile & update compose.yaml --- compose.yaml | 44 +++++------------- frontend/.dockerignore | 34 ++++++++++++++ frontend/Dockerfile | 76 +++++++++++++++++++++++++++++++ frontend/src/app/welcome/page.tsx | 2 +- 4 files changed, 122 insertions(+), 34 deletions(-) create mode 100644 frontend/.dockerignore create mode 100644 frontend/Dockerfile diff --git a/compose.yaml b/compose.yaml index 2435f5d..ba3c70f 100644 --- a/compose.yaml +++ b/compose.yaml @@ -1,39 +1,17 @@ - +name: study-platform services: - server: + backend: + container_name: backend-api build: context: ./backend ports: - 3000:3000 -# volumes: -# - ./backend/:/usr/src/app -# - /usr/src/app/node_modules - - -# depends_on: -# db: -# condition: service_healthy -# db: -# image: postgres -# restart: always -# user: postgres -# secrets: -# - db-password -# volumes: -# - db-data:/var/lib/postgresql/data -# environment: -# - POSTGRES_DB=example -# - POSTGRES_PASSWORD_FILE=/run/secrets/db-password -# expose: -# - 5432 -# healthcheck: -# test: [ "CMD", "pg_isready" ] -# interval: 10s -# timeout: 5s -# retries: 5 -# volumes: -# db-data: -# secrets: -# db-password: -# file: db/password.txt + frontend: + container_name: frontend-ui + build: + context: ./frontend + environment: + NODE_ENV: production + ports: + - 3001:3001 diff --git a/frontend/.dockerignore b/frontend/.dockerignore new file mode 100644 index 0000000..dc157ff --- /dev/null +++ b/frontend/.dockerignore @@ -0,0 +1,34 @@ +# Include any files or directories that you don't want to be copied to your +# container here (e.g., local build artifacts, temporary files, etc.). +# +# For more help, visit the .dockerignore file reference guide at +# https://docs.docker.com/go/build-context-dockerignore/ + +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/.next +**/.cache +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/charts +**/docker-compose* +**/compose.y*ml +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +**/build +**/dist +LICENSE +README.md diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 0000000..c7f12ce --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,76 @@ +# syntax=docker/dockerfile:1 + +# Comments are provided throughout this file to help you get started. +# If you need more help, visit the Dockerfile reference guide at +# https://docs.docker.com/go/dockerfile-reference/ + +# Want to help us make this template better? Share your feedback here: https://forms.gle/ybq9Krt8jtBL3iCk7 + +ARG NODE_VERSION=20.12.1 +ARG PNPM_VERSION=9.0.5 + +################################################################################ +# Use node image for base image for all stages. +FROM node:${NODE_VERSION}-alpine as base + +# Set working directory for all build stages. +WORKDIR /usr/src/app + +# Install pnpm. +RUN --mount=type=cache,target=/root/.npm \ + npm install -g pnpm@${PNPM_VERSION} + +################################################################################ +# Create a stage for installing production dependecies. +FROM base as deps + +# Download dependencies as a separate step to take advantage of Docker's caching. +# Leverage a cache mount to /root/.local/share/pnpm/store to speed up subsequent builds. +# Leverage bind mounts to package.json and pnpm-lock.yaml to avoid having to copy them +# into this layer. +RUN --mount=type=bind,source=package.json,target=package.json \ + --mount=type=bind,source=pnpm-lock.yaml,target=pnpm-lock.yaml \ + --mount=type=cache,target=/root/.local/share/pnpm/store \ + pnpm install --prod --frozen-lockfile + +################################################################################ +# Create a stage for building the application. +FROM deps as build + +# Download additional development dependencies before building, as some projects require +# "devDependencies" to be installed to build. If you don't need this, remove this step. +RUN --mount=type=bind,source=package.json,target=package.json \ + --mount=type=bind,source=pnpm-lock.yaml,target=pnpm-lock.yaml \ + --mount=type=cache,target=/root/.local/share/pnpm/store \ + pnpm install --frozen-lockfile + +# Copy the rest of the source files into the image. +COPY . . +# Run the build script. +RUN pnpm run build + +################################################################################ +# Create a new stage to run the application with minimal runtime dependencies +# where the necessary files are copied from the build stage. +FROM base as final + +# Use production node environment by default. +ENV NODE_ENV production + +# Run the application as a non-root user. +USER node + +# Copy package.json so that package manager commands can be used. +COPY package.json . + +# Copy the production dependencies from the deps stage and also +# the built application from the build stage into the image. +COPY --from=deps /usr/src/app/node_modules ./node_modules +COPY --from=build /usr/src/app/.next ./.next + + +# Expose the port that the application listens on. +EXPOSE 3001 + +# Run the application. +CMD pnpm start diff --git a/frontend/src/app/welcome/page.tsx b/frontend/src/app/welcome/page.tsx index 795fdd5..9b09adc 100644 --- a/frontend/src/app/welcome/page.tsx +++ b/frontend/src/app/welcome/page.tsx @@ -1,7 +1,7 @@ export default function Home() { return (
- + TEST
); } From 15a632ac4ee2b2fdad541a5e705d044d523d06d9 Mon Sep 17 00:00:00 2001 From: aleks Date: Sat, 8 Jun 2024 21:56:52 +0500 Subject: [PATCH 2/3] docs: update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 195b97c..a3df651 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,9 @@ # Quick start -запуск проекта: +Запуск проекта: - backend: [http://localhost:3000](http://localhost:3000) -- frontend: +- frontend: [http://localhost:3001](http://localhost:3001) ``` From 2ae966d015425848476fe5cd1adfa8f0a4c5d1ba Mon Sep 17 00:00:00 2001 From: aleks Date: Mon, 10 Jun 2024 09:55:37 +0500 Subject: [PATCH 3/3] refactor: remove unnecessary welcome comment in Dockerfile --- frontend/Dockerfile | 6 ------ 1 file changed, 6 deletions(-) diff --git a/frontend/Dockerfile b/frontend/Dockerfile index c7f12ce..9e46f62 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -1,11 +1,5 @@ # syntax=docker/dockerfile:1 -# Comments are provided throughout this file to help you get started. -# If you need more help, visit the Dockerfile reference guide at -# https://docs.docker.com/go/dockerfile-reference/ - -# Want to help us make this template better? Share your feedback here: https://forms.gle/ybq9Krt8jtBL3iCk7 - ARG NODE_VERSION=20.12.1 ARG PNPM_VERSION=9.0.5