How long are deploys supposed to take?

zaydek
PRO

2 years ago

I know it depends on a lot of factors but my code is taking 1-3 minutes which is really breaking my flow and productivity. I am already a Team user for Railway (didn't seem to help at all) and I use the railway up command from the CLI to deploy. The one nuance is this server needs CGO_ENABLED but besides that I'm not understanding why it takes so long in the first place?

0 Replies

zaydek
PRO

2 years ago

d60c6135-973c-4957-bf95-00eac2ed9e32


2 years ago

how big the the image when its built?


zaydek
PRO

2 years ago

I see

Pushing [==================================================>] 543.9MB 04c0d2b851c3

Pushed 04c0d2b851c3

121a47bf-47df-4e3a-a1b8-0c9888d3f770: digest: sha256:9d75f75d2f2b4621291cf91527fd96876d73a8b9a41f607ec45b19e3237ba475 size: 2633

Publish time: 38.38 seconds

====================

Starting Healthcheck

====================

Path: /healthz

Retry window: 5m0s


2 years ago

540mb, not bad


zaydek
PRO

2 years ago

Yeah it should be zippy


2 years ago

how long is the build time?


zaydek
PRO

2 years ago

This one was about 3 minutes even


2 years ago

what stage took the longest?


zaydek
PRO

2 years ago

I know the health check takes another few seconds and then it takes another 30 seconds for it to turn off the previous deploy but 3 minutes is from when I type railway up and then wait for the Starting healthcheck message


zaydek
PRO

2 years ago

How can I tell?


2 years ago

look at the logs


zaydek
PRO

2 years ago

It's virtualized so I can't copy paste the whole thing


zaydek
PRO

2 years ago

Sec


zaydek
PRO

2 years ago

Build time: 89.75 seconds
Publish time: 38.38 seconds


2 years ago

what build stage took the longest?


zaydek
PRO

2 years ago

Are there more stages than that?


2 years ago

the build is made up of multiple stages, please look at the logs


zaydek
PRO

2 years ago

#8 36.87 deleting '/nix/store/hnz8p5w9xc0ivsiyrgky6f6h7sjb28a5-file-5.45'

#8 36.88 deleting '/nix/store/7fqp73ncnbwr5bxxszqicf6r33d9yhkw-gnused-4.9'

#8 36.89 deleting unused links...

#8 36.89 note: currently hard linking saves -0.00 MiB

#8 36.95 27 store paths deleted, 250.35 MiB freed



#8 DONE 37.1s





#9 [stage-0 5/9] COPY . /app/.

#9 DONE 0.0s





#10 [stage-0 6/9] RUN --mount=type=cache,id=s/a354a09b-f734-4f06-85d6-61dd0c222868-/root/cache/go-build,target=/root/.cache/go-build go mod download



#10 DONE 2.2s





#11 [stage-0 7/9] COPY . /app/.



#11 DONE 0.0s



#12 [stage-0 8/9] RUN --mount=type=cache,id=s/a354a09b-f734-4f06-85d6-61dd0c222868-/root/cache/go-build,target=/root/.cache/go-build go build -o app cmd/iconflex/*.go



#12 DONE 44.0s





#13 [stage-0 9/9] COPY . /app

#13 DONE 0.0s



#14 exporting to image

#14 exporting layers



#14 exporting layers 4.8s done



#14 writing image sha256:e18f7387818d3d9ab5d9870fa8067192356cb7b74e059536e7a039632de18739 done

#14 naming to us-west1.registry.rlwy.net/a354a09b-f734-4f06-85d6-61dd0c222868:121a47bf-47df-4e3a-a1b8-0c9888d3f770 done

#14 DONE 4.8s



=== Successfully Built! ===

zaydek
PRO

2 years ago

I see there are 9 stages


zaydek
PRO

2 years ago

#1 transferring dockerfile: 2.28kB done

#1 DONE 0.0s

#2 DONE 0.2s

#3 DONE 0.0s

#5 transferring context: 2B done

#5 DONE 0.0s

#6 transferring context: 328.65kB 0.0s done

#6 DONE 0.1s

#7 DONE 0.1s

#8 DONE 37.1s

#9 DONE 0.0s

#10 DONE 2.2s

#11 DONE 0.0s

#12 DONE 44.0s

#13 DONE 0.0s

#14 exporting layers 4.8s done

#14 writing image sha256:e18f7387818d3d9ab5d9870fa8067192356cb7b74e059536e7a039632de18739 done

#14 naming to us-west1.registry.rlwy.net/a354a09b-f734-4f06-85d6-61dd0c222868:121a47bf-47df-4e3a-a1b8-0c9888d3f770 done

#14 DONE 4.8s

2 years ago

44 seconds to go build, theres not really too many ways around that since its already cached


zaydek
PRO

2 years ago

Based on this 8 and 12 take a ton of time


zaydek
PRO

2 years ago

I mean is it possible to get like 10 second deploys or am I oversimplifying the problem?


zaydek
PRO

2 years ago

Every time I deploy it just takes forever because I usually need multiple iterations and the feedback loop takes minutes each


2 years ago

the only thing i can see that you could improve would be the publish time


zaydek
PRO

2 years ago

How would I improve that?


zaydek
PRO

2 years ago

Can I just build it locally and send the executable or something?


2 years ago

you would want to create your own dockerfile that uses a final image so that the published image is as small as possible, i dont have any super big go apps running on railway but the publish time of my go apps is 4-5 seconds


zaydek
PRO

2 years ago

So I have my own docker file and I build locally?


zaydek
PRO

2 years ago

I'm open minded I just don't really know the steps


2 years ago

no, you would still let railway build from the dockerfile


zaydek
PRO

2 years ago

I see I guess I will have to try this approach


2 years ago

personally, i stay away far away from cgo, my go build times are 10s making my total build times sub 25 seconds


zaydek
PRO

2 years ago

Does that mean I need to have docker on my computer (Mac) or just the dockerfile and that's it?


zaydek
PRO

2 years ago

No I know it's a requirement for this one server because I needd webp I think


2 years ago

just the dockerfile, i dont have docker on my computer


zaydek
PRO

2 years ago

Do you have an example docker file you can share?


zaydek
PRO

2 years ago

I wouldn't really know where to start


zaydek
PRO

2 years ago

And you might be right that this server in particular doesn't need CGO but one of them definitely does


2 years ago

this would be a decent starting point but would be super unlikely to work out of the box for you

############# STAGE 1 #############

FROM golang:1.22.0-alpine AS builder

WORKDIR /app

COPY go.mod go.sum ./

RUN go mod download

COPY . ./

RUN go build -ldflags="-w -s" -o main

############# STAGE 2 #############

FROM gcr.io/distroless/static

WORKDIR /app

COPY --from=builder /app/main ./

ENTRYPOINT ["/app/main"]

2 years ago

what does your one server need cgo for?


zaydek
PRO

2 years ago

One of the thing this machine does is convert PNG to WebP


zaydek
PRO

2 years ago

But only one server needs that


2 years ago

that needs cgo?


zaydek
PRO

2 years ago

Yes because nobody writes WebP encoders


zaydek
PRO

2 years ago

They just talk to the C library because it's too complicated to rewrite the lib


2 years ago

theres no pure go to webp encoder?


zaydek
PRO

2 years ago

No so far that I can find


zaydek
PRO

2 years ago

Apparently it's wildly complicated


2 years ago

fair enough


zaydek
PRO

2 years ago

What is this bit about? FROM [gcr.io/distroless/static](gcr.io/distroless/static)


2 years ago

i copy the built binary into the distroless image so that the final image is nearly as small as the binary itself


zaydek
PRO

2 years ago

OK I see. I'll play with docker deploys later and see if I can remove CGO from one of my servers


2 years ago

resulting in sub 10mb images for me, and thats how i get my 4 second publish times


zaydek
PRO

2 years ago


zaydek
PRO

2 years ago

Great thanks, that helps for now. Have two things I can try


zaydek
PRO

2 years ago

Yeah 1-3 minutes is killing me


zaydek
PRO

2 years ago

I'll mark this as solved, thanks @Brody


zaydek
PRO

2 years ago

I don't know how to mark this as closed lol


2 years ago

no problem!


How long are deploys supposed to take? - Railway Help Station