diff --git a/dockerjekyllpages/Dockerfile b/Dockerfile similarity index 57% rename from dockerjekyllpages/Dockerfile rename to Dockerfile index 69d4e7a..d1971a4 100644 --- a/dockerjekyllpages/Dockerfile +++ b/Dockerfile @@ -1,18 +1,24 @@ -FROM ubuntu:trusty -MAINTAINER dmcnamara +FROM ubuntu:cosmic +MAINTAINER Natanael Arndt + +ENV LANG C.UTF-8 +ENV SSH_AUTH_SOCK /var/run/ssh-agent.sock # Install +## zlib1g-dev is needed for nokogiri dependency of jekyll-rdf +## ruby-dev and build-essential are needed to build jekyll RUN apt-get update && apt-get install -y \ git \ - ruby1.9.1-full \ + ruby \ + ruby-dev \ build-essential \ nginx \ uwsgi \ - uwsgi-core \ supervisor \ - nodejs + zlib1g-dev \ + && rm -rf /var/lib/apt/lists/* -RUN gem install --no-rdoc --no-ri jekyll +RUN gem install --no-rdoc --no-ri jekyll bundler # Configure nginx. RUN echo "\ndaemon off;" >> /etc/nginx/nginx.conf @@ -26,5 +32,7 @@ ADD ./supervisor-app.conf /etc/supervisor/conf.d/ ADD ./buildsite.sh /data/cgi/buildsite.sh RUN chmod +x /data/cgi/buildsite.sh +VOLUME /data/jekyll/source + EXPOSE 80 CMD ["supervisord", "-n"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..6e33810 --- /dev/null +++ b/README.md @@ -0,0 +1,85 @@ +Maybe this is not state of the art anymore. +Better build your page with some CI/CD system and then serve it as static site with: https://github.com/white-gecko/mini-server.compose + + +This is a fork from https://github.com/DonMcNamara/dockerfiles/tree/master/dockerjekyllpages which is built at https://hub.docker.com/r/dmcnamara/dockerjekyllpages/ + +This repo is built at https://hub.docker.com/r/whitegecko/dockerjekyllpages/ + +### Description +This is a docker image to build a Jekyll page from a Git repository. +This is essentially githubpages in a docker image. +This docker image uses nginx, Jekyll, uwsgi and supervisor. + +### Configuration of docker image +The git repository URL is passed as an environment variable to the docker image. +The environment variable is named `REPO`, also a branch to build can be specified using the variable `BRANCH`. +Alternatively the container can be linked to a volume at `/data/jekyll/source` which contains the Jekyll page to build. + +#### Use SSH Authentication +If you want to clone private git repositories your might want to forward your private SSH key resp. the *SSH Authentication Socket*. +Per default the `SSH_AUTH_SOCK` environment variable is set to `/var/run/ssh-agent.sock` in this image thus you only have to mount the hosts `SSH_AUTH_SOCK` to the container by adding the argument `-v "$SSH_AUTH_SOCK:/var/run/ssh-agent.sock"`. +If you don't have an `SSH_AUTH_SOCK` running on the docker host you can also mount the `id_rsa`-file e.g. with `-v $HOME/.ssh/id_rsa:/root/.ssh/id_rsa:ro`. +In the case that you are mounting a private key rather then using the hosts SSH agent it is a good idea to generate a key without password. + +Usually you also want to tell the known hosts to the container so it doesn't prompt for the decision. +You can do this by mounting the hosts `known_hosts`-file with `-v $HOME/.ssh/known_hosts:/root/.ssh/known_hosts:ro`. + +### Triggering builds +To initiate a rebuild, you can use your browser to load http://yourserver/cgi/buildsite.sh + +For an automatic build, you can set up a git service hook that posts to that URL on a git push. +Your site will rebuild when you push changes to your repository. + +### Execution +Per default the site will be hosted on port 80. +This is especially useful in combination with a proxy container e.g. the one from [jwilder](https://hub.docker.com/r/jwilder/nginx-proxy/). + +If you want to serve you site locally you can map it e.g. to port 8080: +``` +sudo docker run -p 8080:80 -e REPO=[YOUR REPO URL HERE] -e BRANCH=[YOUR BRANCH] whitegecko/dockerjekyllpages +``` + +### Troubleshooting + +#### Authenticity can't be established + +If you experience that `./buildsite.sh` never ends and if you run it manually you get the following output: + + The authenticity of host 'github.com (192.30.253.113)' can't be established. + RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8. + Are you sure you want to continue connecting (yes/no)? + +You are using a ssh remote URL. + +There are two solutions: + +1. Use a HTTPS URL for the remote instead +2. Include a `known_hosts`-file as explained above in the "Use SSH Authentication"-section + +### Changelog + +#### 0.3.2 +* Remove debian packages which are not used +* Update base image to ubuntu:zesty, latest and saves space + +#### 0.3.1 +* Remove apt list cache after installation with apt-get (should save some space) + +#### 0.3.0 Add Support for private SSH repositories +* Set SSH_AUTH_SOCK environment variable per default +* README: Explain how to forward the respective SSH resources to the container + +#### 0.2.0 Some Improvements +* Update base image, ruby and thus jekyll +* Reorganize file structure +* NGINX: also serve pages without .html +* NGINX: deliver 404 status codes +* NGINX: serve custom 404 pages +* Build process: install dependencies from Gemfile +* Build process: specify branch to checkout +* Build process: build from volume +* Update README + +#### 0.1.0 Initial release. +* It seems to work. diff --git a/buildsite.sh b/buildsite.sh new file mode 100644 index 0000000..a661944 --- /dev/null +++ b/buildsite.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +SOURCE="/data/jekyll/source" +TARGET="/data/jekyll/_site" + +# Output an HTML header so this works as a CGI script. +echo "Content-type: text/html" +echo "" + +echo "
"
+
+if [ -z "$(ls -A $SOURCE)" ]
+then
+    # $SOURCE is empty
+    if [ -z "$REPO" ]
+    then
+        echo "The source directory is empty and no repository is specified. I don't know what to build. :-("
+        exit 1
+    else
+        # pull down the repo
+        if [ -z "$BRANCH" ]
+        then
+            git clone $REPO $SOURCE
+        else
+            git clone --branch "$BRANCH" $REPO $SOURCE
+        fi
+    fi
+else
+    cd $SOURCE
+    git pull || true
+fi
+
+if [ -s $SOURCE/Gemfile ]
+then
+    cd $SOURCE
+
+    echo "Install dependencies from Gemfile"
+    # update gems
+    bundle install
+
+    # generate the site with jekyll
+    bundle exec jekyll build -s $SOURCE -d $TARGET
+else
+    echo "No Gemfile found use standard jekyll installation"
+    # generate the site with jekyll
+    jekyll build -s $SOURCE -d $TARGET
+fi
+
+echo
+date
+
+echo "
" diff --git a/dockerjekyllpages/README.md b/dockerjekyllpages/README.md deleted file mode 100644 index 33558b4..0000000 --- a/dockerjekyllpages/README.md +++ /dev/null @@ -1,24 +0,0 @@ -### Description -This is a docker image to run Jekyll against a git repository. This is essentially githubpages in a docker image. This docker image uses nginx, Jekyll, uwsgi and supervisor. - -### Configuration of docker image -The git repository URL is passed as an environment variable to the docker image. The environment variable is named REPO. - -### Triggering builds -To initiate a rebuild, you can use your browser to load http://yourserver/cgi/buildsite.sh - -For an automatic build, you can set up a git service hook that posts to that URL on a git push. Your site will rebuild when you push changes to your repository. - - -### Execution -This will host your Jekyll built site on local port 8080. -``` -sudo docker run -p :8080:80 -e REPO=[YOUR REPO URL HERE] dmcnamara/dockerjekyllpages -``` - -The repository URL is the URL to the .git file. For example, on github, it would be something like https://github.com/username/myrepo.git - -### Release Notes - -#### 0.1 Initial release. -* It seems to work. diff --git a/dockerjekyllpages/buildsite.sh b/dockerjekyllpages/buildsite.sh deleted file mode 100644 index e34b48e..0000000 --- a/dockerjekyllpages/buildsite.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash - -# Output an HTML header so this works as a CGI script. -echo "Content-type: text/html" -echo "" - -echo "
"
-
-# delete the old directory. (This is a bit heavy handed.)
-rm --recursive /data/jekyll/source
-
-# pull down the repo
-git clone $REPO /data/jekyll/source
-
-# generate the site with jekyll
-jekyll build -s /data/jekyll/source -d /data/jekyll/_site
-
-echo
-date
-
-echo "
" diff --git a/dockerjekyllpages/nginx.conf b/dockerjekyllpages/nginx.conf deleted file mode 100644 index 02fb64a..0000000 --- a/dockerjekyllpages/nginx.conf +++ /dev/null @@ -1,11 +0,0 @@ -server { - location / { - root /data/jekyll/_site; - } - - location /cgi { - include uwsgi_params; - uwsgi_modifier1 9; - uwsgi_pass 127.0.0.1:3031; - } -} diff --git a/nginx.conf b/nginx.conf new file mode 100644 index 0000000..59f877d --- /dev/null +++ b/nginx.conf @@ -0,0 +1,33 @@ +server { + + root /data/jekyll/_site; + index index.html; + + location / { + if ($http_accept ~ "text\/turtle") { + rewrite ^(.*)$ /ttl$1 last; + } + if ($http_accept ~ "application\/x-turtle") { + rewrite ^(.*)$ /ttl$1 last; + } + if ($http_accept ~ "text\/n3") { + rewrite ^(.*)$ /ttl$1 last; + } + try_files $uri $uri.html $uri/ =404; + error_page 404 /404.html; + } + + location /ttl { + default_type text/turtle; + add_header Access-Control-Allow-Origin $http_origin; + add_header Access-Control-Allow-Credentials true; + index index.ttl; + try_files $uri $uri.ttl $uri/ =404; + } + + location /cgi { + include uwsgi_params; + uwsgi_modifier1 9; + uwsgi_pass 127.0.0.1:3031; + } +} diff --git a/dockerjekyllpages/supervisor-app.conf b/supervisor-app.conf similarity index 100% rename from dockerjekyllpages/supervisor-app.conf rename to supervisor-app.conf diff --git a/dockerjekyllpages/uwsgi.ini b/uwsgi.ini similarity index 100% rename from dockerjekyllpages/uwsgi.ini rename to uwsgi.ini