Closed arxenix closed 8 years ago
Seems like the API_HTTP_LISTEN_PORT
variable is not set correctly.
Yeah, I just realized that. I'm not sure how to set it correctly though. I know its not an issue with your project but could you help me out?
You can pass the environment variables to docker run
.
Here is a slightliy modified bash script i have used in the past to start the container:
docker run \
-p 8090:8090 \
--detach \
--restart always \
--env API_ENVIRONMENT="production" \
--env API_HTTP_LISTEN_IP="0.0.0.0" \
--env API_HTTP_LISTEN_PORT="8090" \
--env DATA_PATH="/home/app/data/" \
--env LOG_PATH="/home/app/log/" \
--env BASE_URL="https://run.glot.io" \
--env ADMIN_TOKEN="secret" \
--env DOCKER_API_URL="http://10.0.0.127" \
--env DOCKER_RUN_TIMEOUT="15" \
--env MAX_OUTPUT_SIZE="100000" \
--volume /containers/glot-run/data:/home/app/data \
--volume /containers/glot-run/log:/home/app/log \
glotrun
Thank you so much for the help! It seems to be working now. Thanks for open sourcing this great project
@prasmussen sorry, 1 last question! I tried sending a curl POST request to it, but I get an invalid token error even though I have the header Authorization: Token secret
, and I set the env variable ADMIN_TOKEN to secret. Do I need to hash it or something?
Note the admin token only works for the the /admin endpoints, to create a normal user you can use the following query:
curl -sv -H "Authorization: Token secret" -H 'Content-type: application/json' -X POST -d '{"token": "af4c0a23-7b42-4207-b61c-1430c9637056"}' http://localhost:8090/admin/users
@prasmussen Thanks, but I'm still not able to get it working. When I make a POST to /languages/python/latest
with data {"files": [{"name": "main.py", "content": "print(42)"}]}
, and the Authorization: Token usertoken. I no longer get the auth failed error, but I get a HTTP 500 error after aboutt 8 seconds.
This is the stack trace in the docker logs.
19:00:57.952 [error] Ranch listener http had connection process started with cowboy_protocol:start_link/4 at <0.663.0> exit with reason: {[{reason,{badmatch,{error,connect_timeout}}},{mfa,{language_run_resource,accept_post,2}},{stacktrace,[{docker,container_create,1,[{file,"/glot-run/_build/default/lib/glot/src/docker/docker.erl"},{line,13}]},{language_run,run,3,[{file,"/glot-run/_build/default/lib/glot/src/models/language_run.erl"},{line,11}]},{language_run_resource,run_code,3,[{file,"/glot-run/_build/default/lib/glot/src/resources/language_run_resource.erl"},{line,97}]},{cowboy_rest,call,3,[{file,"/glot-run/_build/default/lib/cowboy/src/cowboy_rest.erl"},{line,976}]},{cowboy_rest,process_content_type,3,[{file,"/glot-run/_build/default/lib/cowboy/src/cowboy_rest.erl"},{line,777}]},{cowboy_protocol,execute,4,[{file,"/glot-run/_build/default/lib/cowboy/src/cowboy_protocol.erl"},{line,442}]}]},{req,[{socket,#Port<0.997>},{transport,ranch_tcp},{connection,keepalive},{pid,<0.663.0>},{method,<<"POST">>},{version,'HTTP/1.1'},{peer,{{172,17,42,1},56216}},{host,<<"localhost">>},{host_info,undefined},{port,80},{path,<<"/languages/python/latest">>},{path_info,undefined},{qs,<<>>},{qs_vals,undefined},{bindings,[{version,<<"latest">>},{name,<<"python">>}]},{headers,[{<<"user-agent">>,<<"curl/7.35.0">>},{<<"host">>,<<"localhost">>},{<<"accept">>,<<"*/*">>},{<<"authorization">>,<<"Token usertoken">>},{<<"content-type">>,<<"application/json">>},{<<"content-length">>,<<"56">>}]},{p_headers,[{<<"content-type">>,{<<"application">>,<<"json">>,[]}},{<<"if-modified-since">>,undefined},{<<"if-none-match">>,undefined},{<<"if-unmodified-since">>,undefined},{<<"if-match">>,undefined},{<<"accept">>,[{{<<"*">>,<<"*">>,[]},1000,[]}]}]},{cookies,undefined},{meta,[{media_type,{<<"application">>,<<"json">>,[]}},{charset,undefined}]},{body_state,waiting},{buffer,<<"{\"files\": [{\"name\": \"main.py\", \"content\": \"print(42)\"}]}">>},{multipart,undefined},{resp_compress,false},{resp_state,waiting},{resp_headers,[{<<"content-type">>,[<<"application">>,<<"/">>,<<"json">>,<<>>]}]},{resp_body,<<>>},{onresponse,#Fun<http_util.log_response.4>}]},{state,{state,<<"python">>,<<"latest">>}}],[{cowboy_rest,process_content_type,3,[{file,"/glot-run/_build/default/lib/cowboy/src/cowboy_rest.erl"},{line,777}]},{cowboy_protocol,execute,4,[{file,"/glot-run/_build/default/lib/cowboy/src/cowboy_protocol.erl"},{line,442}]}]}
it seems to be some sort of problem in spawning the docker container to run the program?
Yes, it seems like container_create process times out. Make sure that that the glotrun container is able to access the docker api. Try doing curl $DOCKER_API_URL/version
from inside the container. This should return the docker version. (Probably need to install curl first)
@bobacadodl did you register the language in glot-run? Did you download the python container in your docker daemon?
Check #9 for some scripts to download and register all languages 😉
I got it working. I did have the languages registered. The problem was that I was using the incorrect docker API URL (I just copied the example one)
Hi, the issue is probably on my part, but I'd really like to use this project and I can't seem to get it working. (I am new to both docker and erlang)
I've pulled the glot-code-runner images for python and java, and they seem to be working. If I run the container with
docker run -it glot/python
and paste{"language": "python", "files": [{"name": "main.py", "content": "print(42)"}]}
into stdin, I get the correct JSON response.However, I can't get the glot-run project working. I tried editing the Dockerfile, to add those environment variables in it by adding lines
ENV [variable name]=[value]
, for each of the environment variables. For exampleENV API_ENVIRONMENT=production
.I then tried to build it, with the command
docker build --tag=glotrun .
And also added the line
DOCKER_OPTS="-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock"
to/etc/default/docker
However, when I tried running it with the command
docker run -it -p 8090:8090 glotrun
, it fails with the following stack trace:I don't really know what this means and would greatly appreciate the help. Please let me know if there's any other info I should provide
EDIT: Looking through the code, it seems to be because my container's environment variables aren't properly set, so its failing on the line
list_to_integer(os:getenv("API_HTTP_LISTEN_PORT")).
. but I added them to the Dockerfile.. so I'm not sure what's wrong