deno_docker icon indicating copy to clipboard operation
deno_docker copied to clipboard

`deno compile` example?

Open AFCMS opened this issue 1 year ago • 5 comments

Currently the README explains how to use deno with the deno run command inside the Docker images.

But there are no examples for using deno compile

I have tried to do so, but I didn't succeed, getting an error like that:

 => ERROR [build 10/10] RUN deno compile --output /app/custom_binary --allow-read=".env,.env.defaults,.env.example" --allow-net main.ts                           2.5s 
------                                                                                                                                                                    
 > [build 10/10] RUN deno compile --output /app/custom_binary --allow-read=".env,.env.defaults,.env.example" --allow-net main.ts:                                      
0.268 Check file:///app/main.ts                                                                                                                                           
0.368 Compile file:///app/main.ts to /app/custom_binary                                                                                                                
0.368 Download https://dl.deno.land/release/v1.44.0/denort-x86_64-unknown-linux-gnu.zip                                                                                   
1.775 Archive:  /tmp/.tmpyRVvzh/denort.zip
1.775   inflating: denort                  
2.365 error: Writing /app/custom_binary
2.365 
2.365 Caused by:
2.365     No such file or directory (os error 2)
------
Dockerfile:16
--------------------
  14 |     RUN ls -la && exit 0
  15 |     
  16 | >>> RUN deno compile --output /app/custom_binary --allow-read=".env,.env.defaults,.env.example" --allow-net main.ts
  17 |     
  18 |     FROM alpine as runtime
--------------------
ERROR: failed to solve: process "/bin/sh -c deno compile --output /app/custom_binary --allow-read=\".env,.env.defaults,.env.example\" --allow-net main.ts" did not complete successfully: exit code: 1
FROM denoland/deno:alpine as build

RUN apk add --no-cache unzip

WORKDIR /app

COPY deno.json /app/
COPY deno.lock /app/
COPY main.ts /app/
COPY schema.gen.ts /app/

RUN deno cache main.ts

RUN deno compile --output /app/custom_binary --allow-read=".env,.env.defaults,.env.example" --allow-net main.ts

FROM alpine as runtime

COPY --from=build /app/custom_binary /app/

CMD [ "/app/custom_binary" ]

AFCMS avatar Jun 04 '24 12:06 AFCMS

I got the same issue it seems to happen only inside Docker containers, but the strange thing is that if I run it manually inside a devcontainer this error does not occur

duesabati avatar Nov 17 '24 21:11 duesabati

I get the same issue. It seems unhappy using alpine as the second stage (there seem to be a number of issues related to glibc requirements)

So if running a multi-stage build you still need to use denoland/deno:alpine in the runtime stage, which doesn't save anywhere near as much on image size.

Similar issue noted in #428, #373 and #350, there's also a lot of discussion on https://github.com/denoland/deno_docker/issues/373

If you really need to use the alpine image I think the workarounds included here should fix: https://github.com/dojyorin/deno_docker_image/blob/master/src/alpine.dockerfile

chrismclarke avatar Nov 19 '24 23:11 chrismclarke

It seemes like with version 2.1.1 on Debian it is solved at least for my case, give it a try

duesabati avatar Nov 22 '24 08:11 duesabati

@twosaturdayscode i still get errors - can you provide a short version of your Dockerfile to compare?

proof-llc avatar Nov 22 '24 22:11 proof-llc

@twosaturdayscode i still get errors - can you provide a short version of your Dockerfile to compare?

I think it would just confuse you, but let me give more details about my case, I'm using denoland/deno:debian-2.1.1 as base image for my devcontainer that will use the docker-in-docker feature, then I have a post-create hook that compiles a cli of mine, when I use the 2.0.6 it would always fail saying the same error of OP but since I've switched it doesn't occur anymore.

duesabati avatar Nov 22 '24 22:11 duesabati