Skip to content

Instantly share code, notes, and snippets.

@MarceloPrado
Created August 1, 2023 10:12
Show Gist options
  • Save MarceloPrado/5977288d08ed91ddf18aeaaf20f2aa53 to your computer and use it in GitHub Desktop.
Save MarceloPrado/5977288d08ed91ddf18aeaaf20f2aa53 to your computer and use it in GitHub Desktop.
Railway dockerfile
# ------------------------------
# First stage: build the app
# ------------------------------
FROM node:16.19-alpine as builder
ARG DATABASE_URL
ARG DATADOG_API_KEY
ARG PORT
ARG SENTRY_DSN
# Export the env variables that should be available to the Prisma CLI during build time.
ENV DATABASE_URL=$DATABASE_URL
ENV DATADOG_API_KEY=$DATADOG_API_KEY
ENV SENTRY_DSN=$SENTRY_DSN
WORKDIR /app
# Install dependencies
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile
COPY . .
# Prisma related commands
RUN npx prisma generate
RUN npx prisma migrate deploy
RUN npx prisma db seed
RUN yarn run build
# ------------------------------
# Second stage: the actual production image
# ------------------------------
FROM node:16.19-alpine
WORKDIR /app
# Install app dependencies
COPY --from=builder /app/package.json /app/yarn.lock ./
COPY --from=builder /app/dist ./dist
COPY --from=builder /app/prisma ./prisma
RUN yarn install --production --frozen-lockfile
# Re-generate Prisma client
RUN npx prisma generate
# Railway requires host to be this - https://docs.railway.app/deploy/exposing-your-app
ENV HOST="0.0.0.0"
EXPOSE $PORT
CMD [ "yarn", "run", "start" ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment