R
Railway8mo ago
rhh4x0R

ENV Vars Not Accessible On Deployment

Attempting to deploy Astro app via Railway and seems like no ENV vars are being exposed. Dockerfile as requested by @Brody
FROM node:18.16 AS base
WORKDIR /app

COPY package.json package-lock.json ./

FROM base AS build
RUN npm ci

COPY . .
RUN npm run build

FROM base AS runtime

COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/dist ./dist

# Move the drizzle directory to the runtime image
COPY --from=build /app/drizzle ./drizzle

# Create the data directory for the database
RUN mkdir -p /data

ENV HOST=0.0.0.0
ENV PORT=4321
ENV NODE_ENV=production
EXPOSE 4321

CMD node ./dist/server/entry.mjs
FROM node:18.16 AS base
WORKDIR /app

COPY package.json package-lock.json ./

FROM base AS build
RUN npm ci

COPY . .
RUN npm run build

FROM base AS runtime

COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/dist ./dist

# Move the drizzle directory to the runtime image
COPY --from=build /app/drizzle ./drizzle

# Create the data directory for the database
RUN mkdir -p /data

ENV HOST=0.0.0.0
ENV PORT=4321
ENV NODE_ENV=production
EXPOSE 4321

CMD node ./dist/server/entry.mjs
29 Replies
Percy
Percy8mo ago
Project ID: N/A
rhh4x0R
rhh4x0ROP8mo ago
N/A
Brody
Brody8mo ago
interesting dockerfile please read this docs page - https://docs.railway.app/guides/dockerfiles#using-variables-at-build-time
rhh4x0R
rhh4x0ROP8mo ago
Ah, gotcha! I'll try that.
Brody
Brody8mo ago
if that works, then we can move on to optimizing the dockerfile but show me what changes you make to the dockerfile before trying another deployment please
rhh4x0R
rhh4x0ROP8mo ago
Just adding ARG <name of variable I have set in the dashboard> x 15, lol.
Brody
Brody8mo ago
correct, but still send the dockerfile before deployment please
rhh4x0R
rhh4x0ROP8mo ago
FROM node:18.16 AS base
WORKDIR /app

ARG RAILWAY_ENVIRONMENT
ARG NODE_ENV
ARG GOOGLE_CLIENT_ID
ARG PUBLIC_GOOGLE_CLIENT_ID
ARG GOOGLE_CLIENT_SECRET
ARG AUTH_SECRET
ARG AUTH_TRUST_HOST
ARG TRIGGER_API_KEY
ARG TRIGGER_API_URL
ARG TRIGGER_PUBLIC_API_KEY
ARG URL
ARG TURSO_AUTH_TOKEN
ARG TURSO_CONNECTION_URL

COPY package.json package-lock.json ./

FROM base AS build
RUN npm ci

COPY . .
RUN npm run build

FROM base AS runtime

COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/dist ./dist

# Move the drizzle directory to the runtime image
COPY --from=build /app/drizzle ./drizzle

# Create the data directory for the database
RUN mkdir -p /data

ENV HOST=0.0.0.0
ENV PORT=4321
ENV NODE_ENV=production
EXPOSE 4321

CMD node ./dist/server/entry.mjs
FROM node:18.16 AS base
WORKDIR /app

ARG RAILWAY_ENVIRONMENT
ARG NODE_ENV
ARG GOOGLE_CLIENT_ID
ARG PUBLIC_GOOGLE_CLIENT_ID
ARG GOOGLE_CLIENT_SECRET
ARG AUTH_SECRET
ARG AUTH_TRUST_HOST
ARG TRIGGER_API_KEY
ARG TRIGGER_API_URL
ARG TRIGGER_PUBLIC_API_KEY
ARG URL
ARG TURSO_AUTH_TOKEN
ARG TURSO_CONNECTION_URL

COPY package.json package-lock.json ./

FROM base AS build
RUN npm ci

COPY . .
RUN npm run build

FROM base AS runtime

COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/dist ./dist

# Move the drizzle directory to the runtime image
COPY --from=build /app/drizzle ./drizzle

# Create the data directory for the database
RUN mkdir -p /data

ENV HOST=0.0.0.0
ENV PORT=4321
ENV NODE_ENV=production
EXPOSE 4321

CMD node ./dist/server/entry.mjs
docker @Brody
Brody
Brody8mo ago
nope haha exactly what I thought you'd do
rhh4x0R
rhh4x0ROP8mo ago
Rekt Guess I need to pass those ARGS somewhere ? I was looking at one of your other responses, don't see much of a difference. What are you seeing?
Brody
Brody8mo ago
FROM node:18.16 AS build

WORKDIR /app

ARG RAILWAY_ENVIRONMENT
ARG NODE_ENV
ARG GOOGLE_CLIENT_ID
ARG PUBLIC_GOOGLE_CLIENT_ID
ARG GOOGLE_CLIENT_SECRET
ARG AUTH_SECRET
ARG AUTH_TRUST_HOST
ARG TRIGGER_API_KEY
ARG TRIGGER_API_URL
ARG TRIGGER_PUBLIC_API_KEY
ARG URL
ARG TURSO_AUTH_TOKEN
ARG TURSO_CONNECTION_URL

COPY package.json package-lock.json ./

RUN npm ci

COPY . .

RUN npm run build

FROM node:18.16

COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/dist ./dist

# Move the drizzle directory to the runtime image
COPY --from=build /app/drizzle ./drizzle

# Create the data directory for the database
RUN mkdir -p /data

ENV HOST=0.0.0.0
ENV NODE_ENV=production

CMD ["node", "./dist/server/entry.mjs"]
FROM node:18.16 AS build

WORKDIR /app

ARG RAILWAY_ENVIRONMENT
ARG NODE_ENV
ARG GOOGLE_CLIENT_ID
ARG PUBLIC_GOOGLE_CLIENT_ID
ARG GOOGLE_CLIENT_SECRET
ARG AUTH_SECRET
ARG AUTH_TRUST_HOST
ARG TRIGGER_API_KEY
ARG TRIGGER_API_URL
ARG TRIGGER_PUBLIC_API_KEY
ARG URL
ARG TURSO_AUTH_TOKEN
ARG TURSO_CONNECTION_URL

COPY package.json package-lock.json ./

RUN npm ci

COPY . .

RUN npm run build

FROM node:18.16

COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/dist ./dist

# Move the drizzle directory to the runtime image
COPY --from=build /app/drizzle ./drizzle

# Create the data directory for the database
RUN mkdir -p /data

ENV HOST=0.0.0.0
ENV NODE_ENV=production

CMD ["node", "./dist/server/entry.mjs"]
hopefully there's no typos, edited on mobile
rhh4x0R
rhh4x0ROP8mo ago
Hmm, ok so just cleaning it up a little? Seemed tow ork otherwise. Lemme try this though
Brody
Brody8mo ago
you had your layers in a weird order
rhh4x0R
rhh4x0ROP8mo ago
Gotcha. Interesting. It failed based on one of my env vars. Invalid define value (must be an entity name or valid JSON syntax): libsql://sderkaderka.turso.io Do I need to wrap that shit in quotes or something?
Brody
Brody8mo ago
how have you defined it in your railway service variables
rhh4x0R
rhh4x0ROP8mo ago
Without quotes TURSO_CONNECTION_URL=libsql://fesfesfsef.turso.io (Like how I do on .env)
Brody
Brody8mo ago
and what's the correct syntax?
rhh4x0R
rhh4x0ROP8mo ago
That's what I use on dev. And works fine. (localhost, rather) Hmm. Might be a VITE bundle thing, I'll try adding quotes I guess. EDIT: Probably what happens when you use ARG in Dockerfile Just tripped on the URL environment variables. adding quotes allowed it to build.
Brody
Brody8mo ago
railway strips quotes from environment variables fwiw
rhh4x0R
rhh4x0ROP8mo ago
Gotcha. @Brody Seems to be working now. Thank you. Adding ARGS in the Dockerfile + quotes around necessary ENV vars seemed to do it. For anyone looking for this in the future, still not sure if I needed to update my astro.config.mjs with vite define variables, but we'll see.
Brody
Brody8mo ago
lets see your final dockerfile?
rhh4x0R
rhh4x0ROP8mo ago
Same one you sent me. I just added quotes in the Railway var settings in the dashboard.
Brody
Brody8mo ago
interesting
rhh4x0R
rhh4x0ROP8mo ago
Why’s that?
Brody
Brody8mo ago
^
rhh4x0R
rhh4x0ROP8mo ago
Maybe because I’m injecting them from docker it’s pulling the value before it’s stripped.
Brody
Brody8mo ago
haha not how it works
rhh4x0R
rhh4x0ROP8mo ago
I also hook into vite to define the variables in my config file, referencing process.env so maybe that’s it too.
Brody
Brody8mo ago
we may never know
Want results from more Discord servers?
Add your server