diff --git a/backend/.dockerignore b/backend/.dockerignore new file mode 100644 index 00000000..e3fbd983 --- /dev/null +++ b/backend/.dockerignore @@ -0,0 +1,2 @@ +build +node_modules diff --git a/backend/Dockerfile b/backend/Dockerfile index 36c80f90..4334a3bb 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -1,12 +1,15 @@ -FROM node:20-alpine3.19 AS build +FROM node:20-alpine3.19 AS backend-build ENV TZ="Europe/Helsinki" WORKDIR /usr/src/app -COPY package*.json ./ +COPY package.json ./ +COPY package-lock.json ./ -RUN npm install +ENV NODE_ENV=production + +RUN npm ci COPY . . @@ -16,8 +19,10 @@ FROM node:20-alpine3.19 AS node-run WORKDIR /usr/src/app -COPY --from=build /usr/src/app/build /usr/src/app +COPY --from=backend-build /usr/src/app/build /usr/src/app/build +COPY --from=backend-build /usr/src/app/node_modules /usr/src/app/node_modules EXPOSE 4000 +ENV NODE_ENV=production CMD ["node", "build/index.js"] diff --git a/backend/src/utils/config.ts b/backend/src/utils/config.ts index b4a0d4f7..466a94dd 100644 --- a/backend/src/utils/config.ts +++ b/backend/src/utils/config.ts @@ -6,4 +6,6 @@ export const MARIADB_PASSWORD = process.env.MARIADB_PASSWORD as string export const SECRET = process.env.SECRET as string export const PORT = process.env.NOWDB_BACKEND_PORT as unknown as number export const LOGIN_VALID_MS = parseInt(process.env.LOGIN_VALID_MINUTES as string) * 60 * 1000 -export const MARIADB_PORT = parseInt(process.env.MARIADB_PORT as string) \ No newline at end of file +export const MARIADB_PORT = parseInt(process.env.MARIADB_PORT as string) +export const USER_CREATION_SECRET = process.env.USER_CREATION_SECRET as string +export const BACKEND_MODE = (process.env.BACKEND_MODE as 'dev' | 'prod' | 'test') \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 5bfc3ab8..872c8e1d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,9 +14,7 @@ services: container_name: nowdb-backend build: context: backend/ - env_file: .db.dev.env - volumes: - - ./backend/:/usr/src/app + env_file: .db.env ports: - 4000:4000 db: diff --git a/frontend/.dockerignore b/frontend/.dockerignore new file mode 100644 index 00000000..1521c8b7 --- /dev/null +++ b/frontend/.dockerignore @@ -0,0 +1 @@ +dist diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 9096199b..4d88eb07 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -7,7 +7,7 @@ WORKDIR /app COPY package.json ./ COPY package-lock.json ./ -RUN npm install +RUN npm ci COPY . .