deno_docker icon indicating copy to clipboard operation
deno_docker copied to clipboard

Add multi-stage docker image for alpine without glibc

Open hayd opened this issue 4 years ago • 6 comments

You have to first build gn using ubuntu then build deno with gn in alpine. This should be possible, and I have some progress towards it... (failing) attempt: Dockerfile. failure output

~This may also be useful for automating creating of binaries suitable for AWS Lambda (or similar). The tricky part is to not rely on glibc...~ This is complete.

Note/Aside: Current size is 62Mb (18.1Mb compressed).

See also https://github.com/denoland/deno/issues/1456 ~and https://dev.to/kt3k/write-aws-lambda-function-in-deno-4b20~.

xpost: https://github.com/denoland/deno/issues/3243

hayd avatar Oct 27 '19 06:10 hayd

Not exactly sure how this is related, but I am running a multi-stage build by running deno bundle app.ts app.bundle.js in the first stage and then copying the produced file into the final image. Works nice! This is a just a simple events handler and the size of the app.bundle.js is about 450kb.

webdeb avatar Nov 10 '20 00:11 webdeb

@webdeb An example like that would be really nice for the README, I think that's a better option that running bundle locally (on potentially another deno version) then using that file :+1:

hayd avatar Nov 11 '20 22:11 hayd

@hayd sure!

Please feel free to include it, I just copied what I have locally in my project (just updated it according to the new release):

FROM hayd/alpine-deno:1.5.2 as build
ADD . .
RUN deno bundle --importmap=./import_map.json --unstable ./app.ts /tmp/app.bundle.js

# --- build the final image, include only the app.bundle.js
FROM hayd/alpine-deno:1.5.2
WORKDIR /app
USER deno
ENV MODE=production

COPY --from=build /tmp/app.bundle.js /app/app.bundle.js
CMD ["deno", "run", "--allow-net", "--allow-env", "--allow-read", "/app/app.bundle.js"]

webdeb avatar Nov 11 '20 23:11 webdeb

@webdeb Why use bundle and not compile?

Trying to "improve" my Dockerfile though both of those produce the same error, which I not get running the server using deno run

The bundle'd at least show a more insightful error & lets me inspect

error: Uncaught ReferenceError: Cannot access 'Error' before initialization
class DenoStdInternalError extends Error {

Thoug I've no idea what to do, probably opening a new issue @ denoland/deno right?

CanRau avatar Oct 21 '21 19:10 CanRau

@CanRau Oh your are right. I guess by that time the compile command wasn't available. Your error seems weird and reporting it is a good idea, however to fix workaround your problem maybe you could try to define a Variable like const ExtendableError = Error and then use it like MyError extend ExtendableError {} Don't know if this will work, but it could ;)

webdeb avatar Oct 21 '21 19:10 webdeb

Huh, just found https://github.com/denoland/deno/issues/12086 and it's "duplicate" https://github.com/denoland/deno/issues/12477

@webdeb I'm not directly using Error in my code, at least as far as I recall

CanRau avatar Oct 21 '21 23:10 CanRau