R
Railway5mo ago
Joshie

Are variables exposed during build?

Are environment variables exposed during the build step? Or only the deployment?
Solution:
```dockerfile FROM oven/bun:latest AS build WORKDIR /app ...
Jump to solution
16 Replies
Percy
Percy5mo ago
Project ID: N/A
Joshie
JoshieOP5mo ago
N/A I suspect that some variables are not being exposed during a build step in my docker image. I don't have a great way of tracking this down. "works on my machine" but not on railway
Brody
Brody5mo ago
yes they are exposed as build args
Joshie
JoshieOP5mo ago
hmmmmmmmmm idk. My vite builds don't seem to have the variable in them.
Brody
Brody5mo ago
dockerfile or nixpacks?
Joshie
JoshieOP5mo ago
dockerfile
Brody
Brody5mo ago
send it?
Joshie
JoshieOP5mo ago
FROM oven/bun:latest as build
WORKDIR /app

COPY package.json bun.lockb .
RUN bun install --frozen-lockfile
COPY . .

RUN bun run build

FROM caddy:latest

copy --from=build /app/dist /dist/

COPY Caddyfile /etc/caddy/Caddyfile

RUN caddy fmt --overwrite /etc/caddy/Caddyfile

CMD exec caddy run --config /etc/caddy/Caddyfile --adapter caddyfile 2>&1
FROM oven/bun:latest as build
WORKDIR /app

COPY package.json bun.lockb .
RUN bun install --frozen-lockfile
COPY . .

RUN bun run build

FROM caddy:latest

copy --from=build /app/dist /dist/

COPY Caddyfile /etc/caddy/Caddyfile

RUN caddy fmt --overwrite /etc/caddy/Caddyfile

CMD exec caddy run --config /etc/caddy/Caddyfile --adapter caddyfile 2>&1
Brody
Brody5mo ago
theres no build args there
Joshie
JoshieOP5mo ago
Yea. I wouldn't normally need it. Just not used to the way Vite handles environement variables. But I guess just some ARG VITE_NAME_OF_THING should be good
Solution
Brody
Brody5mo ago
FROM oven/bun:latest AS build

WORKDIR /app

COPY package.json bun.lockb .

RUN bun install --frozen-lockfile

COPY . ./

ARG VITE_BACKEND_URL

RUN bun run build

FROM caddy:latest

WORKDIR /app

copy --from=build /app/dist ./dist/

COPY Caddyfile /etc/caddy/Caddyfile

RUN caddy fmt --overwrite /etc/caddy/Caddyfile

CMD exec caddy run --config /etc/caddy/Caddyfile --adapter caddyfile 2>&1
FROM oven/bun:latest AS build

WORKDIR /app

COPY package.json bun.lockb .

RUN bun install --frozen-lockfile

COPY . ./

ARG VITE_BACKEND_URL

RUN bun run build

FROM caddy:latest

WORKDIR /app

copy --from=build /app/dist ./dist/

COPY Caddyfile /etc/caddy/Caddyfile

RUN caddy fmt --overwrite /etc/caddy/Caddyfile

CMD exec caddy run --config /etc/caddy/Caddyfile --adapter caddyfile 2>&1
Brody
Brody5mo ago
you absolutely do need them haha, if you want to use variables during build
Joshie
JoshieOP5mo ago
Yea, let me go try that. I hope it fixes my issue. Finally getting around to fixing it from all that time ago Yay!!! It actually works now!! Now when a user reports a bug I can spy on them to find out if it was human error or a me error. Thanks posthog
Brody
Brody5mo ago
lmao
Joshie
JoshieOP5mo ago
jk about the spying. Well ... kinda. It is sessions. I can see what they did. Great feature That is what made me prioritize coming back to this. A user complained about a bug that in my mind is actually impossible. But I can't tell them that. So now we wait for them to report it again ... and I see if it really is a bug ....
Brody
Brody5mo ago
A user complained about a bug that in my mind is actually impossible. But I can't tell them that
story of my life
Want results from more Discord servers?
Add your server