Define environment variables in CodePipeline for Nx project

currently we have a .env file with the following definitions in the backend of a Nx project

HOST=$HOST
USER_DB=$USER_DB 
PASS_DB=$PASS_DB

We are using this approach for not hardcoding anything, so we can have that .env file in our repo without any problem.

The workflow of the CodePipeline is:

  • Testing/Linting
  • Build image and put it into a Docker container
  • Once the image is pushed into the ECR it will be automatically deployed by EKS.

Dockerfile:

FROM node:lts-alpine
WORKDIR /app
COPY ./dist/apps/backend .
EXPOSE 3333
RUN yarn add pg
RUN yarn install --production
CMD node ./main.js

The CodeBuild has the values of the previous variables define as environment variables but it seems that the container is not picking them up because when the EKS deploy the new image built it can´t connect to the Postgres database (The security groups and connections are checked). What I´m thinking is that the variables should be set after the container is built, I mean, at the time the container is run, but my experience is very low on this subject.

Source: Angular Questions

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.