What I am doing is setting up sbcl and quicklisp in RUN commands in the Dockerfile and then using a CMD to load my custom code.
When I run it with Docker on my local machine all is well, but when I push it to "google run" the lisp code (loaded with CMD) crashes because it cant find quicklisp.
And as far as I can see that is because the HOME is different for RUN (/root) and CMD (/home).
It is the same user in RUN and CMD = uid=0(root) gid=0(root) groups=0(root)
I am assuming that they (google run) use some linux command to change the "user context" (dont know the correct word to use for linux) of the user, but dont know why or how they are doing it. And because I dont know what or why, they are doing it, it is difficult to google for a solution.
Any suggestions would be welcome.
To see the behaviour:
Dockerfile:
FROM phusion/baseimage
MAINTAINER Piet Pompies <[email protected]>
RUN echo $HOME
CMD echo $HOME
When you build $HOME will be /root and when you deploy and run it will be /home
EDIT: I found a work around (12 Jun 2020):
Not sure if I should put the workaround in the answer or just in a edit like I did here. Will leave it in the edit till advised otherwise.
WORK AROUND:
You can can dump a core in your RUN commands and use that in CMD or use buildapp to run lisp. buildapp is what you will be going for in a final release.
Full woo and buildapp example
woo.lisp
(defun main (&rest args)
(declare (ignore args))
(woo:run
(lambda (env)
(cond ((equalp (getf env :REQUEST-URI) "/test")
(list 200
(list :content-type "text/plain")
(list (format nil "Hello, World - ~A" (getf env :REQUEST-URI)))))
(t
(list 200
(list :content-type "text/plain")
(list (format nil "~S" env))))))
:address "0.0.0.0"
:port 5000))
Dockerfile:
FROM phusion/baseimage
MAINTAINER Piet Pompies <[email protected]>
RUN apt-get update &&\
apt-get install -y sbcl curl wget rlwrap build-essential time libev-dev screen && \
cd /tmp && \
curl -O https://ufpr.dl.sourceforge.net/project/sbcl/sbcl/2.0.5/sbcl-2.0.5-source.tar.bz2 && \
tar jxvf sbcl-2.0.5-source.tar.bz2 && \
cd /tmp/sbcl-2.0.5 && \
sh ./make.sh && \
sh ./install.sh && \
rm -rf /tmp/sbcl*
RUN cd /tmp && \
wget http://www.xach.com/lisp/buildapp.tgz && \
tar xvf buildapp.tgz && \
cd /tmp/buildapp-1.5.6 && \
make install && \
rm -rf /tmp/buildapp*
RUN mkdir /src/
# install quicklisp (requirements: curl, sbcl)
RUN curl -k -o /tmp/quicklisp.lisp 'https://beta.quicklisp.org/quicklisp.lisp' && \
sbcl --noinform --non-interactive --load /tmp/quicklisp.lisp --eval \
'(quicklisp-quickstart:install :path "~/quicklisp/")' && \
sbcl --noinform --non-interactive --load ~/quicklisp/setup.lisp --eval \
'(ql-util:without-prompting (ql:add-to-init-file))' && \
echo '#+quicklisp(push "/src" ql:*local-project-directories*)' >> ~/.sbclrc && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
COPY woo.lisp /src/woo.lisp
RUN sbcl --no-userinit \
--no-sysinit --non-interactive \
--load ~/quicklisp/setup.lisp \
--eval '(ql:quickload "woo")' \
--eval '(ql:write-asdf-manifest-file "quicklisp-manifest.txt")'
RUN buildapp \
--manifest-file quicklisp-manifest.txt \
--load-system woo \
--load /src/woo.lisp \
--entry main \
--output woo
EXPOSE 5000
CMD sleep 0.05; ./woo