refactor: use .env to configure the server in Dockerfile, it uses the .env.production

This commit is contained in:
Nemo D'ACREMONT 2024-10-25 18:54:01 +02:00
parent b42d403031
commit d95109a86e
No known key found for this signature in database
GPG Key ID: 6E5BCE8022FA8276
2 changed files with 7 additions and 19 deletions

5
back-end/.dockerignore Normal file
View File

@ -0,0 +1,5 @@
node_modules
dist
.env
.env.example
nodemon.json

View File

@ -4,30 +4,14 @@ FROM node:22-alpine
# Workdir definition
WORKDIR /usr/src/back
# Environment declaration variables
ENV NODE_ENV="dev"
ENV DB_HOST="briques_postgres"
ENV DB_NAME="briques_db"
ENV DB_USER="briques_llm"
ENV DB_PASSWORD="briques_password_2025"
ENV DB_PORT=5432
COPY package.json ./
RUN npm install
RUN npm install -g pm2
# Copy sources
COPY . .
# Setting up environment
RUN echo "NODE_ENV=${NODE_ENV}" > .env \
&& echo "DB_HOST=${DB_HOST}" >> .env \
&& echo "DB_NAME=${DB_NAME}" >> .env \
&& echo "DB_USER=${DB_USER}" >> .env \
&& echo "DB_PORT=${DB_PORT}" >> .env \
&& echo "DB_PASSWORD=${DB_PASSWORD}" >> .env
COPY .env.production .env
# Compilation des fichiers TypeScript
RUN npm run build
@ -40,5 +24,4 @@ RUN chmod -R u=rwx,g=,o= ./
EXPOSE 3000
# Start app
CMD ["npm", "run", "startonly"]
#CMD ["pm2", "start", "dist/app.js", "--no-daemon"]
CMD ["pm2", "start", "dist/app.js", "--no-daemon"]