R
Railway7mo 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
Percy7mo ago
Project ID: 893df018-6917-4ca3-b43d-6db80b4819ca
Harris
HarrisOP7mo 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
HarrisOP7mo 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
Brody7mo ago
how big is the image? also why compile and minify your .ts file? bun has first class support for ts
Harris
HarrisOP7mo ago
because this is production and that's much more performant
Brody
Brody7mo ago
how long does that specific command take when building?
Harris
HarrisOP7mo ago
100ms
Harris
HarrisOP7mo ago
No description
Brody
Brody7mo ago
how long does railway say it took
Harris
HarrisOP7mo ago
the docker file itself is finished in 12s
No description
Harris
HarrisOP7mo ago
but the image is quite big idk why
Brody
Brody7mo ago
yes, how big keep in mind i cant read your logs for you
Harris
HarrisOP7mo ago
1 layer = 99.96MB another layer = 715.2MB
Harris
HarrisOP7mo ago
No description
Harris
HarrisOP7mo ago
even then it says it only taks 124s tho
Brody
Brody7mo ago
thats big, do you need node during the runtime?
Harris
HarrisOP7mo ago
not after i've compiled the executable from bun, i don't think i need anything at that point
Brody
Brody7mo 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
HarrisOP7mo 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
Brody7mo ago
in more words, yes, you will want to look into multi layered images
Harris
HarrisOP7mo ago
oh wait, yeah, that makes sense the executable is the 700mb it's every package
Brody
Brody7mo ago
you are like 10% of the way there with -
FROM oven/bun:1 as base
FROM oven/bun:1 as base
Harris
HarrisOP7mo 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
Brody7mo ago
nope, please look into multi layered dockerfiles
Harris
HarrisOP7mo ago
how do i do a multi-layered dockerfile with a binary executable? since it itself will alwasy be ~700mb and changing
Brody
Brody7mo 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
HarrisOP7mo 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
Brody7mo ago
are we talking about the node executable?
Harris
HarrisOP7mo ago
no, the bun compiled executable of my server
Brody
Brody7mo ago
its actually 700mb?? where is this number coming from?
Harris
HarrisOP7mo ago
no the compiled executable is only 70mb, idk where the rest is coming from hvaen't dug into it yet
Brody
Brody7mo ago
then it's coming from node and everything else in the image that isn't needed ^ ^
Harris
HarrisOP7mo ago
will look into ty
Want results from more Discord servers?
Add your server