GenieFramework / Genie.jl

🧞The highly productive Julia web framework
https://genieframework.com
MIT License
2.26k stars 190 forks source link

Docker integration: cross platform issues - end of line char and path to Julia #439

Open sjlynch opened 2 years ago

sjlynch commented 2 years ago

Describe the bug I get this error after building the image and doing Deploy.Docker.run() in the Julia REPL. The image does get built and if I run it in a container, I get this error inside the container "standard_init_linux.go:228: exec user process caused: no such file or directory"


Error stacktrace

julia> Deploy.Docker.run()
Starting docker container with `docker run -it --rm -p 80:8000 --name genieapp genie bin/server`
standard_init_linux.go:228: exec user process caused: no such file or directory
ERROR: UndefVarError: IOError not defined
Stacktrace:
 [1] run(command::Cmd)
   @ Genie.Deploy ~\.julia\packages\Genie\Uvtzb\src\Deploy.jl:8
 [2] |>
   @ .\operators.jl:858 [inlined]
 [3] run(; containername::String, hostport::Int64, containerport::Int64, appdir::String, mountapp::Bool, image::String, command::String, rm::Bool, it::Bool, websockets_hostport::Int64, websockets_containerport::Int64)
   @ Genie.Deploy.Docker ~\.julia\packages\Genie\Uvtzb\src\Deploy.jl:116
 [4] run()
   @ Genie.Deploy.Docker ~\.julia\packages\Genie\Uvtzb\src\Deploy.jl:88
 [5] top-level scope
   @ REPL[43]:1

caused by: failed process: Process(`docker run -it --rm -p 80:8000 --name genieapp genie bin/server`, ProcessExited(1)) [1]

Stacktrace:
 [1] pipeline_error
   @ .\process.jl:525 [inlined]
 [2] run(::Cmd; wait::Bool)
   @ Base .\process.jl:440
 [3] run
   @ .\process.jl:438 [inlined]
 [4] run(command::Cmd)
   @ Genie.Deploy ~\.julia\packages\Genie\Uvtzb\src\Deploy.jl:5
 [5] |>
   @ .\operators.jl:858 [inlined]
 [6] run(; containername::String, hostport::Int64, containerport::Int64, appdir::String, mountapp::Bool, image::String, command::String, rm::Bool, it::Bool, websockets_hostport::Int64, websockets_containerport::Int64)
   @ Genie.Deploy.Docker ~\.julia\packages\Genie\Uvtzb\src\Deploy.jl:116
 [7] run()
   @ Genie.Deploy.Docker ~\.julia\packages\Genie\Uvtzb\src\Deploy.jl:88
 [8] top-level scope
   @ REPL[43]:1

To reproduce Follow this guide on windows 10 with Julia v1.6.0 -- https://genieframework.github.io/Genie.jl/dev/tutorials/16--Using_Genie_With_Docker.html

Expected behavior I expected the server container to stand up after Deploy.Docker.run()

Additional context Please include the output of julia> versioninfo() Julia Version 1.6.0 Commit f9720dc2eb (2021-03-24 12:55 UTC) Platform Info: OS: Windows (x86_64-w64-mingw32) CPU: Intel(R) Core(TM) i7-7820HK CPU @ 2.90GHz WORD_SIZE: 64 LIBM: libopenlibm LLVM: libLLVM-11.0.1 (ORCJIT, skylake)

pkg> st Project WebService v0.1.0 Status C:\development\WebService\Project.toml [198e06fe] BangBang v0.3.32 [336ed68f] CSV v0.8.5 [324d7699] CategoricalArrays v0.10.2 [a93c6f00] DataFrames v1.2.2 [cc61a311] FLoops v0.1.11 [c43c736e] Genie v4.0.0 [cd3eb016] HTTP v0.9.16 [6deec6e2] IndexedTables v1.0.0 [6d011eab] Inflector v1.0.1 [682c06a0] JSON v0.21.2 [e6f89c97] LoggingExtras v0.4.7 [739be429] MbedTLS v1.0.3 [128add7d] MicroCollections v0.1.1 [69de0a69] Parsers v1.1.2 [a759f4b9] TimerOutputs v0.5.13 [ade2ca70] Dates [37e2e46d] LinearAlgebra [56ddb016] Logging [de0858da] Printf [6462fe0b] Sockets

Here is my dockerfile

pull latest julia image

FROM julia:latest

create dedicated user

RUN useradd --create-home --shell /bin/bash genie

set up the app

RUN mkdir /home/genie/app COPY . /home/genie/app WORKDIR /home/genie/app

configure permissions

RUN chown genie:genie -R *

RUN chmod +x bin/repl RUN chmod +x bin/server RUN chmod +x bin/runtask

switch user

USER genie

instantiate Julia packages

RUN julia -e "using Pkg; Pkg.activate(\".\"); Pkg.instantiate(); Pkg.precompile(); "

ports

EXPOSE 8000 EXPOSE 80

set up app environment

ENV JULIA_DEPOT_PATH "/home/genie/.julia" ENV GENIE_ENV "dev" ENV HOST "0.0.0.0" ENV PORT "8000" ENV WSPORT "8000" ENV EARLYBIND "true"

run app

CMD ["bin/server"]

AbhimanyuAryan commented 2 years ago

May I also know the OS? So I can test? @sjlynch

sjlynch commented 2 years ago

@AbhimanyuAryan It's Windows 10 Enterprise

AbhimanyuAryan commented 2 years ago

Can you CD into container and see if contains bin/server ??

sjlynch commented 2 years ago

it does contain bin/server. I tried running bash -c ./server.bat and got: ./server.bat: line 1: c:\Users\other-user\AppData\Local\Programs\Julia-1.6.0\bin\julia: command not found

here is server.bat:

!/bin/sh

julia --color=yes --depwarn=no --project=@. -q -L $(dirname $0)/../bootstrap.jl -- "$@"

Also additional context: this dockerfile was generated by someone else and I noticed that the error contained that user's name (I edited it to "other-user" above). So maybe that's the issue?

sjlynch commented 2 years ago

I think this might be resolved. We had to run

dos2unix bin/server

Before building the image. Not sure if this can be done in the Julia repl, but now the container is running and listening for requests! Might be a good idea to mention this in the genie docs?

essenciary commented 2 years ago

Yes... it's because the files were generated on Windows (where the Genie app was created) but then run on Linux in the container. I think we can change the line endings for the *nix file on Windows as well?

essenciary commented 2 years ago

Re the user, good point - when generating the file we're picking the current Julia path - which is a windows one and that's wrong. I guess for *nix we can put julia.

Please leave the issue open so we can fix these problems. Thanks