Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docker support #4

Open
ghost opened this issue Dec 9, 2016 · 13 comments
Open

Add docker support #4

ghost opened this issue Dec 9, 2016 · 13 comments

Comments

@ghost
Copy link

ghost commented Dec 9, 2016

It could be nice to use it with Docker !

@ghost ghost changed the title Add Add docker support Dec 9, 2016
@jhuckaby
Copy link
Owner

jhuckaby commented Dec 9, 2016

How would I add Docker support? Can't you just install it in a Docker container?

@ghost
Copy link
Author

ghost commented Dec 10, 2016

Your app look's really cool ! (tried Chronos from Airbnb dev team but it doesn't fit my needs ).

I really want to try Cronicle, but for a test purpose (and even after for production purpose), installing it from scratch is a little annoying.

Add a dockerfile to your project allow potential users to have a working Cronicle instance ready in less than 5min, perfect for a test ! I can work on it and make a Pull Request if you want !

@jhuckaby
Copy link
Owner

Thank you for the compliment, however...

... installing it from scratch is a little annoying.

Really? It's quite literally one single shell command:

curl -s https://raw.githubusercontent.com/jhuckaby/Cronicle/master/bin/install.js | node

Unfortunately, I don't know anything about Docker files, so I wouldn't know how to maintain it. If I am going to officially support Docker, then I think I would need to learn all about it first. It's still a mystery to me.

Thank you for your interest in Cronicle tho! It's great to see that people are finding it.

@ghost
Copy link
Author

ghost commented Dec 19, 2016

Honestly I exaggerate a little bit 😅 You'r right, it's pretty easy to install. It's just that all my stack is made of docker, and I want to keep going.

I tried to create a container with Cronicle, but i had an issue (no master elected). Don't have time to push investigation further last week, but I'm on it 😃.

If you'r interested to try Docker, I recommend you Kitematic and this article from Digital Ocean.

Anyway, thanks for your work ! Cronicle is really really full of cool features ! (API to schedule a job and CPU usage saved my life !) 😄

@jhuckaby
Copy link
Owner

Thanks! Yeah, Docker seems to be taking over the world. It's only a matter of time before I have to dive in and actually learn it. 😉

I'll bet the "no master elected" issue has to do with the hostname and/or IP of your Docker instance. When Cronicle is first installed, it takes a snapshot of the current server hostname and IP, and saves them into the cluster file on disk. Then when the daemon starts up, it needs to be able to "find" itself in the list, in order to be eligible for master. If the server hostname no longer matches what it was when Cronicle was installed (which is what I suspect is happening with Docker), it can't find itself, and just becomes a slave and goes to sleep. You might be able to hack around this by forcing the server to become master on startup. This is a bit messy, but...

If you edit the /opt/cronicle/bin/control.sh file, and locate this line:

BINARY="node --expose_gc --always_compact $HOMEDIR/lib/main.js"

Add --master to the end:

BINARY="node --expose_gc --always_compact $HOMEDIR/lib/main.js --master"

That might get around your problem, but I have to advise caution -- it really isn't meant to run like this. Cronicle is 100% hostname based, so the hostname of the server means everything. You could never run this server in a cluster, for example, because the other servers would never agree on who is master. The --master flag is a secret debug flag, really only meant for local development.

I think this is one of many things that will prevent Cronicle from working in a Docker container, unless I make some core changes. Right now, the server that Cronicle is installed on needs to keep the same hostname (and IP address). I think Docker breaks this requirement.

One other thing you might be able to do is delay calling the initial setup script until your Docker container is actually live and running (and has the final hostname and IP that it will live with). The initial setup script is the thing that snapshots the hostname and IP and saves it to disk. So basically, wait until you have a running Docker container before doing this step:

/opt/cronicle/bin/control.sh setup

@kozmic
Copy link

kozmic commented Jun 23, 2017

I tried to get it working with excellent tips from @jhuckaby, but there is one hurdle left to fix. The Javascript tries to connect by websocket with the wrong IP. It uses the internal docker IP, and not the exposed IP (maybe it should use the hostname in the conf/config.js?). Cronicle is launched in debug mode to become master.

Setup:
Need a bash script since "control.sh setup" has to be run in the container together with debug.sh master.

$ cat setup_and_start_in_debug.sh
#!/bin/bash
/opt/cronicle/bin/control.sh setup
mv /opt/cronicle/conf/config.json /opt/cronicle/conf/config.json.bak
jq '.web_socket_use_hostnames = 1' /opt/cronicle/conf/config.json.bak > /opt/cronicle/conf/config.json
/opt/cronicle/bin/debug.sh --master
$ cat Dockerfile
FROM node:6.11-alpine

WORKDIR /opt/cronicle/
ADD setup_and_start_in_debug.sh /opt/cronicle/setup_and_start_in_debug.sh
RUN apk update && apk add git curl wget perl bash perl-pathtools
# Update tar in Alpine to fix "tar: unrecognized option: strip-components" issue:
RUN apk --update add tar procps
RUN curl -s https://raw.githubusercontent.com/jhuckaby/Cronicle/master/bin/install.js | node

EXPOSE 3012

CMD ["sh", "setup_and_start_in_debug.sh"]

In the same directory as these files run:
docker build -t kozmic/cronicle .
docker run -it -p 3012:3012 kozmic/cronicle

Cronicle should now be available on localhost:3012 from your host comuputer. BUT with WebSocket error messages in console like this:

image

@jhuckaby
Copy link
Owner

The Javascript tries to connect by websocket with the wrong IP. It uses the internal docker IP, and not the exposed it (maybe it should use the hostname in the conf/config.js?).

Have you tried this configuration option:

https://github.com/jhuckaby/Cronicle#web_socket_use_hostnames

web_socket_use_hostnames

Setting this parameter to 1 will force Cronicle's Web UI to connect to the back-end servers using their hostnames rather than IP addresses. This includes both AJAX API calls and Websocket streams. You should only need to enable this in special situations where your users cannot access your servers via their LAN IPs, and you need to proxy them through a hostname (DNS) instead. The default is 0 (disabled), meaning connect using IP addresses.

That may do the trick, but please note that whatever hostname your Docker container has assigned itself, this needs to be resolvable in DNS, and routable from your client machine. Good luck!

@kozmic
Copy link

kozmic commented Jun 26, 2017

@jhuckaby Thanks for the tips, it worked :) Updated my previous comment with this change, so my previous comment should be a fully working Docker setup.

@imran-baig-se
Copy link

imran-baig-se commented Jan 4, 2018

@jhuckaby how to start running Cronicle in normal mode instead of Deamon mode as it is exiting in my container.
Screen Shot 2018-01-04 at 8.31.08 PM
image

If i run in Debug mode it will work fine and it wont exit.
image

This is just a slave server I dont want to run setup or anyting just start.
@kozmic @pierreprevoteau @jhuckaby @barryw please suggest. am running through docker-compose.yml

@jhuckaby
Copy link
Owner

jhuckaby commented Jan 6, 2018

I don't understand the question. If running it in debug mode solves the issue, then can you just run it in debug mode? Sorry, I don't know anything about Docker, so I don't understand the exact issue here.

The debug.sh script simply runs the Node.js main script with two command-line arguments:

node --expose_gc --always_compact $HOMEDIR/lib/main.js --debug --echo "$@"

The --debug flag prevents the background daemon fork, and the --echo flag causes the debug log to be echoed to the console. If you don't want the log echo, just remove that argument from the script, or better, just copy debug.sh to your own script, and remove the echo flag.

@imran-baig-se
Copy link

imran-baig-se commented Jan 10, 2018

@jhuckaby am passing the debug level by this command node --expose_gc --always_compact /opt/cronicle/lib/main.js --debug --echo --debug_level 4 "$@"

instead of changing in config.json

@jhuckaby please confirm

@belsander
Copy link

@kozmic Thanks for working out the docker details! the only thing was missing for me was setting the hostname of the container:
docker run --hostname my-machine -it -p 3012:3012 kozmic/cronicle
so now http://my-machine:3012 works!

@ckt114
Copy link

ckt114 commented Feb 25, 2019

Hi everyone,

I'm able to run this in docker/kubernetes by setting the hostname to a static value. The master works fine, however, none of clients joined the cluster. I have two clients running on same network and they all can talk to the server on both 3012 and 3014, I'm assuming 3014 is used for discovery. I used the same secret_key for all and below two environment variables as well.

CRONICLE_web_socket_use_hostnames	true
CRONICLE_server_comm_use_hostnames	true

How does the client communicate with the server?

Thanks,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants