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
2 years ago
how big the the image when its built?
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
2 years ago
how long is the build time?
2 years ago
what stage took the longest?
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
2 years ago
look at the logs
2 years ago
what build stage took the longest?
2 years ago
the build is made up of multiple stages, please look at the logs
#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! ===
#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
I mean is it possible to get like 10 second deploys or am I oversimplifying the problem?
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
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
2 years ago
no, you would still let railway build from the dockerfile
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
Does that mean I need to have docker on my computer (Mac) or just the dockerfile and that's it?
2 years ago
just the dockerfile, i dont have docker on my computer
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?
2 years ago
that needs cgo?
2 years ago
theres no pure go to webp encoder?
2 years ago
fair enough
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
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
I saved it here as a bookmark for myself https://gist.github.com/zaydek/b60c4e5ef498165c5c24d1bee80bea55
2 years ago
no problem!