diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000000000..6b8710a711f3b --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +.git 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/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..210d03b85f572 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/ --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: + + sudo docker start -i jekyll + ## Testing locally See README.md as well, but here's the quick version: 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 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