How can I speed up my build time?

developerharris
HOBBY

a year ago

Each build takes roughly like 4 minutes. I'm testing on prod so it makes my iterations kinda slow.

0 Replies


developerharris
HOBBY

a year ago

```FROM oven/bun:1 as base
WORKDIR /usr/src/app

RUN apt update \
&& apt install -y curl

ARG NODEVERSION=18 RUN curl -L https://raw.githubusercontent.com/tj/n/master/bin/n -o n \ && bash n $NODEVERSION \
&& 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
```


a year ago

how big is the image?


a year ago

also why compile and minify your .ts file? bun has first class support for ts


developerharris
HOBBY

a year ago

because this is production and that's much more performant


a year ago

how long does that specific command take when building?


developerharris
HOBBY

a year ago

100ms


developerharris
HOBBY

a year ago

1232525195554848800


a year ago

how long does railway say it took


developerharris
HOBBY

a year ago

the docker file itself is finished in 12s

1232525278920704000


developerharris
HOBBY

a year ago

but the image is quite big


developerharris
HOBBY

a year ago

idk why


a year ago

yes, how big


a year ago

keep in mind i cant read your logs for you


developerharris
HOBBY

a year ago

1 layer = 99.96MB
another layer = 715.2MB


developerharris
HOBBY

a year ago

1232525488166273000


developerharris
HOBBY

a year ago

even then it says it only taks 124s tho


a year ago

thats big, do you need node during the runtime?


developerharris
HOBBY

a year ago

not after i've compiled the executable from bun, i don't think i need anything at that point


a year ago

big images take a seemingly exponentially longer time to deploy and there is some awsome fixes in the pipeline for that


a year ago

but until then, the only fix would be to write a better dockerfile


developerharris
HOBBY

a year ago

can I clear the entire image after i compile the executable?


developerharris
HOBBY

a year ago

```FROM oven/bun:1 as base
WORKDIR /usr/src/app

RUN apt update \
&& apt install -y curl

ARG NODEVERSION=18 RUN curl -L https://raw.githubusercontent.com/tj/n/master/bin/n -o n \ && bash n $NODEVERSION \
&& 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
```


a year ago

in more words, yes, you will want to look into multi layered images


developerharris
HOBBY

a year ago

oh wait, yeah, that makes sense


developerharris
HOBBY

a year ago

the executable is the 700mb


developerharris
HOBBY

a year ago

it's every package


a year ago

you are like 10% of the way there with -

FROM oven/bun:1 as base

developerharris
HOBBY

a year ago

yeah but if I'm making an executable each time it'll be different


developerharris
HOBBY

a year ago

so you can't save it as layers


developerharris
HOBBY

a year ago

so i just have to tank the performance hit i thikn


a year ago

nope, please look into multi layered dockerfiles


developerharris
HOBBY

a year ago

how do i do a multi-layered dockerfile with a binary executable?


developerharris
HOBBY

a year ago

since it itself will alwasy be ~700mb and changing


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

a year ago

get the idea?


developerharris
HOBBY

a year ago

while i agree that will help, I don't think that solves the core issue


developerharris
HOBBY

a year ago

i think the biggest time sink is that the 700mb executable is being uploaded every time


developerharris
HOBBY

a year ago

the build step itself doesn't take that long


a year ago

are we talking about the node executable?


developerharris
HOBBY

a year ago

no, the bun compiled executable of my server


a year ago

its actually 700mb?? where is this number coming from?


developerharris
HOBBY

a year ago

no the compiled executable is only 70mb, idk where the rest is coming from


developerharris
HOBBY

a year ago

hvaen't dug into it yet


a year ago

then it's coming from node and everything else in the image that isn't needed


a year ago

^


a year ago

^


developerharris
HOBBY

a year ago

will look into


developerharris
HOBBY

a year ago

ty


How can I speed up my build time? - Railway Help Station