I decided to experiment with Docker. I want to replicate the functionality of Github Pages. Essentially, that means pulling a git repository, running Jekyll, and hosting the pages output by Jekyll. Additionally, you would need some externally exposed method to allow a push hook in the repository to trigger a build.
Warning: This is all a bit new to me, so if you have any suggestions, please let me know. Be gentle.
Why recreate Github pages?
Good question. Github pages works well and is free. Why recreate it? Essentially, this is an exercise for me to learn more about Docker and in general Linux. Also, Github pages does have some limitations. You have to host the source on Github, of course, and the repository you are hosting has to be public. So, this little project could be useful for someone that wants to have the functionality of Github pages but wants to keep their repository elsewhere, and/or private. So, a company’s internal web site would be a good use case.
How many containers?
I had a decision to make. How many containers should I use to implement my solution? Functionally, it seems like it would make sense to have one container pull the changes and run Jekyll, with a second container dedicated to hosting the content. This seemed like too many moving parts for such a simple problem, so instead I put everything into one container. This simplifies the deployment, but it does have a slightly larger surface area. I could always split it into two images in the future.
It is done and working
This was remarkably easy to get done. The hardest part for me was figuring out how to handle exposing a way to have the Jekyll build pushed. I ended up writing a simple bash script, and using nginx with uwsgi to expose the bash script as a CGI interface. This part of the solution is a bit uncharted for me. Please let me know if you see any problems.
I used supervisor to start the various processes. There may be a more appropriate way to do that for Docker images.
Hosting your own site
You can easily set up your own site. For example, you can go to Digital Ocean and fire up a docker “droplet”, and then run my docker image against your repository. For example:
docker run -p :80:80 -e REPO=[YOUR REPO URL HERE] dmcnamara/dockerjekyllpages
That will run on port 80 on your droplet. When you get it working you should run it in detached mode (command line option ‘-d’).
You will need to set up the git service hook to initiate the Jekyll builds. Set up the service hook as a “push” hook.
Okay, that’s it. Docker was very easy to work with. I really like it.
Again, this is still pretty new to me, especially uswgi. Please let me know if you have any suggestions. You can leave a comment on the GitHub project.