R
Railway4mo 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
Percy4mo ago
Project ID: N/A
Joshie
Joshie4mo 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
Brody4mo ago
yes they are exposed as build args
Joshie
Joshie4mo ago
hmmmmmmmmm idk. My vite builds don't seem to have the variable in them.
Brody
Brody4mo ago
dockerfile or nixpacks?
Joshie
Joshie4mo ago
dockerfile
Brody
Brody4mo ago
send it?
Joshie
Joshie4mo 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
Brody4mo ago
theres no build args there
Joshie
Joshie4mo 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
Brody4mo 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
Brody4mo ago
you absolutely do need them haha, if you want to use variables during build
Joshie
Joshie4mo 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
Brody4mo ago
lmao
Joshie
Joshie4mo 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
Brody4mo 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