R
Railway2mo ago
Harris

How can I speed up my build time?

Each build takes roughly like 4 minutes. I'm testing on prod so it makes my iterations kinda slow.
No description
Solution:
nope, please look into multi layered dockerfiles
Jump to solution
33 Replies
Percy
Percy2mo ago
Project ID: 893df018-6917-4ca3-b43d-6db80b4819ca
Harris
Harris2mo ago
Railway
404 - Page not found
Railway is an infrastructure platform where you can provision infrastructure, develop with that infrastructure locally, and then deploy to the cloud.
Harris
Harris2mo ago
FROM oven/bun:1 as base
WORKDIR /usr/src/app

RUN apt update \
&& apt install -y curl

ARG NODE_VERSION=18
RUN curl -L https://raw.githubusercontent.com/tj/n/master/bin/n -o n \
&& bash n $NODE_VERSION \
&& rm n \
&& npm install -g n

COPY . .
ARG DATABASE_URL
RUN bun install --frozen-lockfile
RUN bunx turbo run db:generate
RUN bun build --compile --minify ./apps/server/index.ts --outfile server

ENV NODE_ENV=production

CMD ./server
FROM oven/bun:1 as base
WORKDIR /usr/src/app

RUN apt update \
&& apt install -y curl

ARG NODE_VERSION=18
RUN curl -L https://raw.githubusercontent.com/tj/n/master/bin/n -o n \
&& bash n $NODE_VERSION \
&& rm n \
&& npm install -g n

COPY . .
ARG DATABASE_URL
RUN bun install --frozen-lockfile
RUN bunx turbo run db:generate
RUN bun build --compile --minify ./apps/server/index.ts --outfile server

ENV NODE_ENV=production

CMD ./server
Brody
Brody2mo ago
how big is the image? also why compile and minify your .ts file? bun has first class support for ts
Harris
Harris2mo ago
because this is production and that's much more performant
Brody
Brody2mo ago
how long does that specific command take when building?
Harris
Harris2mo ago
100ms
Harris
Harris2mo ago
No description
Brody
Brody2mo ago
how long does railway say it took
Harris
Harris2mo ago
the docker file itself is finished in 12s
No description
Harris
Harris2mo ago
but the image is quite big idk why
Brody
Brody2mo ago
yes, how big keep in mind i cant read your logs for you
Harris
Harris2mo ago
1 layer = 99.96MB another layer = 715.2MB
Harris
Harris2mo ago
No description
Harris
Harris2mo ago
even then it says it only taks 124s tho
Brody
Brody2mo ago
thats big, do you need node during the runtime?
Harris
Harris2mo ago
not after i've compiled the executable from bun, i don't think i need anything at that point
Brody
Brody2mo ago
big images take a seemingly exponentially longer time to deploy and there is some awsome fixes in the pipeline for that but until then, the only fix would be to write a better dockerfile
Harris
Harris2mo ago
can I clear the entire image after i compile the executable?
FROM oven/bun:1 as base
WORKDIR /usr/src/app

RUN apt update \
&& apt install -y curl

ARG NODE_VERSION=18
RUN curl -L https://raw.githubusercontent.com/tj/n/master/bin/n -o n \
&& bash n $NODE_VERSION \
&& rm n \
&& npm install -g n

COPY . .
ARG DATABASE_URL
RUN bun install --frozen-lockfile
RUN bunx turbo run db:generate
RUN bun build --compile --minify ./apps/server/index.ts --outfile server

// TODO erase everything else

ENV NODE_ENV=production

CMD ./server
FROM oven/bun:1 as base
WORKDIR /usr/src/app

RUN apt update \
&& apt install -y curl

ARG NODE_VERSION=18
RUN curl -L https://raw.githubusercontent.com/tj/n/master/bin/n -o n \
&& bash n $NODE_VERSION \
&& rm n \
&& npm install -g n

COPY . .
ARG DATABASE_URL
RUN bun install --frozen-lockfile
RUN bunx turbo run db:generate
RUN bun build --compile --minify ./apps/server/index.ts --outfile server

// TODO erase everything else

ENV NODE_ENV=production

CMD ./server
Brody
Brody2mo ago
in more words, yes, you will want to look into multi layered images
Harris
Harris2mo ago
oh wait, yeah, that makes sense the executable is the 700mb it's every package
Brody
Brody2mo ago
you are like 10% of the way there with -
FROM oven/bun:1 as base
FROM oven/bun:1 as base
Harris
Harris2mo ago
yeah but if I'm making an executable each time it'll be different so you can't save it as layers so i just have to tank the performance hit i thikn
Solution
Brody
Brody2mo ago
nope, please look into multi layered dockerfiles
Harris
Harris2mo ago
how do i do a multi-layered dockerfile with a binary executable? since it itself will alwasy be ~700mb and changing
Brody
Brody2mo ago
FROM oven/bun:1 AS builder

// install node and do build stuff

FROM oven/bun:1

// only copy the needed stuff down

// start the server
FROM oven/bun:1 AS builder

// install node and do build stuff

FROM oven/bun:1

// only copy the needed stuff down

// start the server
get the idea?
Harris
Harris2mo ago
while i agree that will help, I don't think that solves the core issue i think the biggest time sink is that the 700mb executable is being uploaded every time the build step itself doesn't take that long
Brody
Brody2mo ago
are we talking about the node executable?
Harris
Harris2mo ago
no, the bun compiled executable of my server
Brody
Brody2mo ago
its actually 700mb?? where is this number coming from?
Harris
Harris2mo ago
no the compiled executable is only 70mb, idk where the rest is coming from hvaen't dug into it yet
Brody
Brody2mo ago
then it's coming from node and everything else in the image that isn't needed ^ ^
Harris
Harris2mo ago
will look into ty