Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use binary in slim docker image #13

Merged
merged 1 commit into from
Apr 19, 2024
Merged

feat: use binary in slim docker image #13

merged 1 commit into from
Apr 19, 2024

Conversation

webbertakken
Copy link
Member

@webbertakken webbertakken commented Apr 19, 2024

Changes

Research

Did a quick research to compare running the application using Bun, as a binary on Debian and as a binary on Alpine. Here are the results:

Option: run typescript files on the offical bun image, running bun server.js

Build command

bun build src/main.ts --target=bun --outfile=dist/server.js

Production image (simplified)

FROM oven/bun:${BUN_VERSION} as automation-prod
ENV NODE_ENV="production"
WORKDIR /app
COPY --from=builder /app/dist /app/package.json ./
COPY --from=builder /app/node_modules node_modules
USER bun
EXPOSE 3000
CMD [ "bun", "run", "server.js" ]

Size: 232MB (OS = 213MB, application = 3MB (of which source map 2MB), node modules 16MB
Coldstart bootstrap: 982ms


Option: binary on debian:buster-slim image

Build command

bun build src/main.ts --compile --minify --outfile dist/server

production image

FROM debian:buster-slim
WORKDIR /app
COPY --from=builder /app/dist /app/package.json ./
CMD ["./server"]

Size: 169MB
Coldstart bootstrap: 991ms


Option: binary on alpine

Executable didn't work because it's built on bitnami/node, which uses debian.

Size: 107MB (OS = 5MB, Binary = 102MB (of which Sourcemap is 2MB))

Tried fixes:

  • apk add gcompat different error: Error relocating /app/server: unsupported relocation type 37
  • apk add libc6-compat different error: Error relocating /app/server: unsupported relocation type 37

Both of those seem to cryptically indicate that you're missing shared libs or other files

If you want to use one or more files on Alpine Linux which were compiled on a glibc based operating system, then you are responsible for ensuring that all of the shared libraries they need are available at runtime. I am unable to help you with this process.

Sources used:

Conclusion:

  • Installing those linker deps and then also the missing libraries will most likely add about 30 megs, at which point we're half way up to the debian slim image again.
  • Since this is not a deployment intensive enterprise scale application I'm deeming it to probably not be worth the hassle - unless somebody has specific experience in this field

Checklist

  • Read the contribution guide and accept the
    code of conduct
  • Readme and docs (updated or not needed)
  • Tests (added, updated or not needed)

Copy link

codecov bot commented Apr 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 12.85%. Comparing base (95fd7a2) to head (a31eeb7).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main      #13   +/-   ##
=======================================
  Coverage   12.85%   12.85%           
=======================================
  Files           3        3           
  Lines         140      140           
  Branches        2        2           
=======================================
  Hits           18       18           
  Misses        120      120           
  Partials        2        2           

@webbertakken webbertakken merged commit 3fa2026 into main Apr 19, 2024
3 checks passed
@webbertakken webbertakken deleted the optimise-prod branch April 19, 2024 22:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Investigate optimised bun executable / minified builds
1 participant