ENV Vars Not Accessible On Deployment

rhh4x0r
PRO

a year ago

Attempting to deploy Astro app via Railway and seems like no ENV vars are being exposed.

Dockerfile as requested by <@539512869780455445>

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
Solved

0 Replies

rhh4x0r
PRO

a year ago

N/A


a year ago

interesting dockerfile


a year ago

please read this docs page -


rhh4x0r
PRO

a year ago

Ah, gotcha!


rhh4x0r
PRO

a year ago

I'll try that.


a year ago

if that works, then we can move on to optimizing the dockerfile


a year ago

but show me what changes you make to the dockerfile before trying another deployment please


rhh4x0r
PRO

a year ago

Just adding ARG


rhh4x0r
PRO

a year ago

x 15, lol.


a year ago

correct, but still send the dockerfile before deployment please


rhh4x0r
PRO

a year 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

docker


rhh4x0r
PRO

a year ago

@Brody


a year ago

nope


a year ago

haha exactly what I thought you'd do


rhh4x0r
PRO

a year ago

Rekt


rhh4x0r
PRO

a year ago

Guess I need to pass those ARGS somewhere


rhh4x0r
PRO

a year ago

?


rhh4x0r
PRO

a year ago

I was looking at one of your other responses, don't see much of a difference. What are you seeing?


a year 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"]

Status changed to Solved railway[bot] about 1 year ago


a year ago

hopefully there's no typos, edited on mobile


rhh4x0r
PRO

a year ago

Hmm, ok so just cleaning it up a little? Seemed tow ork otherwise. Lemme try this though


a year ago

you had your layers in a weird order


rhh4x0r
PRO

a year ago

Gotcha.


rhh4x0r
PRO

a year ago

Interesting. It failed based on one of my env vars.


rhh4x0r
PRO

a year ago

Invalid define value (must be an entity name or valid JSON syntax): libsql://sderkaderka.turso.io


rhh4x0r
PRO

a year ago

Do I need to wrap that shit in quotes or something?


a year ago

how have you defined it in your railway service variables


rhh4x0r
PRO

a year ago

Without quotes


rhh4x0r
PRO

a year ago

TURSOCONNECTIONURL=libsql://fesfesfsef.turso.io


rhh4x0r
PRO

a year ago

(Like how I do on .env)


a year ago

and what's the correct syntax?


rhh4x0r
PRO

a year ago

That's what I use on dev.


rhh4x0r
PRO

a year ago

And works fine.


rhh4x0r
PRO

a year ago

(localhost, rather)


rhh4x0r
PRO

a year ago

Hmm. Might be a VITE bundle thing, I'll try adding quotes I guess. EDIT: Probably what happens when you use ARG in Dockerfile


rhh4x0r
PRO

a year ago

Just tripped on the URL environment variables. adding quotes allowed it to build.


a year ago

railway strips quotes from environment variables fwiw


rhh4x0r
PRO

a year ago

Gotcha.


rhh4x0r
PRO

a year ago

@Brody Seems to be working now. Thank you.


rhh4x0r
PRO

a year ago

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.


a year ago

lets see your final dockerfile?


rhh4x0r
PRO

a year ago

Same one you sent me.


rhh4x0r
PRO

a year ago

I just added quotes in the Railway var settings in the dashboard.


a year ago

interesting


rhh4x0r
PRO

a year ago

Why’s that?


a year ago

^


rhh4x0r
PRO

a year ago

Maybe because I’m injecting them from docker it’s pulling the value before it’s stripped.


a year ago

haha not how it works


rhh4x0r
PRO

a year ago

I also hook into vite to define the variables in my config file, referencing process.env so maybe that’s it too.


a year ago

we may never know