a year ago
I have a nestjs app, im trying to deploy it with dockerfile, it works the build part, but when trying to deploy and get the env variables, they are not detected, did the part of ARG VARIBRE_NAME
so railway can detect it, but still not working:
here is the dockerfile:
FROM node:18-alpine3.16
# Create app directory
WORKDIR /app
# Install app dependencies
COPY package.json ./
COPY tsconfig.json ./
# Bundle app source
COPY . .
RUN npm install -g @nestjs/cli
RUN npm install --omit=dev
# railway env variables
ARG RAILWAY_PUBLIC_DOMAIN
ARG RAILWAY_PRIVATE_DOMAIN
ARG RAILWAY_PROJECT_NAME
ARG RAILWAY_ENVIRONMENT_NAME
ARG RAILWAY_SERVICE_NAME
ARG RAILWAY_PROJECT_ID
ARG RAILWAY_ENVIRONMENT_ID
ARG RAILWAY_SERVICE_ID
# app env variables
ARG DATABASE_URL
ARG JWT_SECRET
ARG JWT_EXPIRES_IN
ENV DATABASE_URL=$DATABASE_URL \
JWT_SECRET=$JWT_SECRET \
JWT_EXPIRES_IN=$JWT_EXPIRES_IN \
RAILWAY_PUBLIC_DOMAIN=$RAILWAY_PUBLIC_DOMAIN \
RAILWAY_PRIVATE_DOMAIN=$RAILWAY_PRIVATE_DOMAIN \
RAILWAY_PROJECT_NAME=$RAILWAY_PROJECT_NAME \
RAILWAY_ENVIRONMENT_NAME=$RAILWAY_ENVIRONMENT_NAME \
RAILWAY_SERVICE_NAME=$RAILWAY_SERVICE_NAME \
RAILWAY_PROJECT_ID=$RAILWAY_PROJECT_ID \
RAILWAY_ENVIRONMENT_ID=$RAILWAY_ENVIRONMENT_ID \
RAILWAY_SERVICE_ID=$RAILWAY_SERVICE_ID
RUN npm run build
ENV NODE_ENV=production
EXPOSE 3000
CMD ["npm", "run", "start:prod"]
17 Replies
a year ago
You only need to include the variables you need during the build, so please remove all the ENV lines.
a year ago
please could you modify this dockerfile to work, i have tried several ways, i did it like you suggested, did it without the env lines and still not working, and i did it before and after the npm build command, before and after the cmd, i dont understand why still not working
a year ago
it would be these ones:
ARG RAILWAY_PUBLIC_DOMAIN
ARG RAILWAY_PRIVATE_DOMAIN
ARG RAILWAY_PROJECT_NAME
ARG RAILWAY_ENVIRONMENT_NAME
ARG RAILWAY_SERVICE_NAME
ARG RAILWAY_PROJECT_ID
ARG RAILWAY_ENVIRONMENT_ID
ARG RAILWAY_SERVICE_ID
# app env variables
ARG DATABASE_URL
ARG JWT_SECRET
ARG JWT_EXPIRES_IN
these are the env variables defined in the settings of the project
a year ago
mmm, i thought i have to use all the variables that are in railway, i think railway is the best platform for deploy, i really wanto to use it, for now im using back4app, but i want to keep using railway but i cannot because of this problem
a year ago
Can you please provide a minimal reproducible example?
Have you saved the changes you have made in the service variables?
a year ago
the railway app is not working, but what i did is
i created the project for the nestjs app
i went to variables and the default railway env variables were there and i just added the ones from my env file i use locally
JWT_SECRET JWT_EXPIRES_IN DATABASE_URL
i modified the dockerfile to use
ARG
as is explained here: https://docs.railway.app/guides/dockerfiles#using-variables-at-build-timei saved the changes and let the automatic deploy
the app is build correctly, the nestjs app works, but when trying to get the env variables i receive the error regarding the jwt secret not defined, and invalid database url, that means the env variables are not being detected
a year ago
I am unable to reproduce, the variables are loaded into the environment just fine. Are you committing your .env file to GitHub?
a year ago
do i have to commit my env file? but they are supposed to be secret, and it should be replaced by railway
a year ago
if you can check it with this monorepo:
https://github.com/macluiggy/social-media
this is the one i cant deploy the backend
a year ago
i found the issue, it was because the env variables in railway would not be saved until i press the apply changes button
Attachments
a year ago
i wondered why the env variables were purple, i thought it was because there were not the default ones, but the purple color mean that those are changes not saved yet
Status changed to Solved railway[bot] • 12 months ago
a year ago
I'm also not sure why you have used shared variables? using those incorrect can also cause issues.
Do you think you can share some insights into how you overlooked the big Deploy button?
10 months ago
I'm also not sure why you have used shared variables? using those incorrect can also cause issues.
Do you think you can share some insights into how you overlooked the big Deploy button?
I had the exact same issue, the UX is really not clear, they change colour but the deploy button is on a completely different screen and it's not apparent that it's linked to the variables. When you save the variables you think it's saved so I think if the button was actually on the same page it'd be much more apparent.