From ea46a56650104dcd41433bd8ee690ee4a9bfb162 Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Tue, 5 Jun 2018 13:37:28 -0700 Subject: [PATCH 1/2] Make running jekyll less irritating Every time I need to edit the blog and view it locally something in the ruby/jekyll stack has changed enough that it doesn't work. So make a Dockerfile and some instructions to make setting up the environment more reliable. And separate from the host. --- .dockerignore | 1 + Dockerfile | 9 +++++++++ StyleGuide.md | 14 ++++++++++++++ entrypoint.sh | 18 ++++++++++++++++++ 4 files changed, 42 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100755 entrypoint.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000000..6b8710a711f3b --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +.git diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000000..1225885a41dad --- /dev/null +++ b/Dockerfile @@ -0,0 +1,9 @@ +FROM fedora:latest +RUN dnf --setopt=deltarpm=0 --verbose install -y passwd sudo vim-enhanced less redhat-rpm-config \ +@development-tools gcc-c++ autoconf automake libtool zlib-devel \ +rubygem-bundler ruby-devel kernel-headers +WORKDIR /weldr.io/ + +# Run as user passed in with --env LOCAL_UID=`id -u` +COPY entrypoint.sh /usr/local/bin/entrypoint.sh +ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] diff --git a/StyleGuide.md b/StyleGuide.md index 70d5b698c4d99..101b25459cb79 100644 --- a/StyleGuide.md +++ b/StyleGuide.md @@ -2,6 +2,20 @@ Notes for weldrists writing for weldr.io. +## Testing locally using containers + +This will build a container, install the needed fedora packages and mount the current directory as +your user id (so that you can edit from within the container without making everything owned by root). + + sudo docker build -t weldr/jekyll . + sudo docker run -it --name=jekyll --security-opt="label=disable" -v "$PWD:/weldr.io/" --env LOCAL_UID=`id -u` -p 4000:4000 weldr/jekyll /usr/bin/bash + bundle install --binstubs=/tmp/bin/ + bundle exec /tmp/bin/jekyll serve --host=0.0.0.0 --incremental + +...then just open http://localhost:4000/ and you're off. On subsequent runs you can reuse the container with: + + sudo docker start -i jekyll + ## Testing locally See README.md as well, but here's the quick version: diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000000000..d5f9e161098fc --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,18 @@ +#!/bin/bash + +# Setup a user account from environment: +# LOCAL_USERNAME +# LOCAL_UID +USERNAME=${LOCAL_USERNAME:-user} +USER_ID=${LOCAL_UID:-1000} + +if [ "$USERNAME" == "root" ]; then + echo "Running as root" + exec "$@" +else + echo "Running with $USERNAME:$USER_ID" + useradd -u "$USER_ID" -G wheel -m "$USERNAME" + # Remove user password, allows sudo use + passwd -d "$USERNAME" + exec sudo -u "$USERNAME" "$@" +fi From 549341801b2f21fed6f4ea032ef984ebf165d4dc Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Tue, 5 Jun 2018 16:36:59 -0700 Subject: [PATCH 2/2] Make the container build instructions more reproducible Add --distribution so that it will use the .lock file contents, otherwise with the latest fedora:latest container it fails with a bunch of complaints. Add vendor to the _config.yml so that jekyll doesn't think it's part of your site and try to parse things it shouldn't. --- .gitignore | 1 + StyleGuide.md | 2 +- _config.yml | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 62bf7251e6d5b..ea7210ca84dff 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ Gemfile Gemfile.lock node_modules package.json +vendor diff --git a/StyleGuide.md b/StyleGuide.md index 101b25459cb79..210d03b85f572 100644 --- a/StyleGuide.md +++ b/StyleGuide.md @@ -9,7 +9,7 @@ your user id (so that you can edit from within the container without making ever sudo docker build -t weldr/jekyll . sudo docker run -it --name=jekyll --security-opt="label=disable" -v "$PWD:/weldr.io/" --env LOCAL_UID=`id -u` -p 4000:4000 weldr/jekyll /usr/bin/bash - bundle install --binstubs=/tmp/bin/ + bundle install --binstubs=/tmp/bin/ --deployment bundle exec /tmp/bin/jekyll serve --host=0.0.0.0 --incremental ...then just open http://localhost:4000/ and you're off. On subsequent runs you can reuse the container with: diff --git a/_config.yml b/_config.yml index a7309f99b1c8d..b4dcf0ffcf2b1 100644 --- a/_config.yml +++ b/_config.yml @@ -89,5 +89,6 @@ exclude: - README.md - CNAME - StyleGuide.md + - vendor theme: jekyll-theme-hacker