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

Dockerfile (with some convenience Makerules) for development, testing and serving #461

Merged
merged 32 commits into from
Mar 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
21b1871
Create Dockerfile
johndmulhausen Mar 9, 2017
c192457
Merge branch 'master' into dockerize
vidbina Aug 5, 2017
4ac341c
update ruby in container
vidbina Aug 5, 2017
76e40e0
follow recommendations for apt usage in image
vidbina Aug 5, 2017
ab2a31f
use /src as workdir
vidbina Aug 5, 2017
4f97a96
mount gh-pages + setup local override
vidbina Aug 6, 2017
1ffa175
serve site by default
vidbina Aug 6, 2017
4735c43
Makefile to keep it simple
vidbina Aug 6, 2017
46e410d
Merge branch 'master' into dockerize
vidbina Aug 30, 2017
5733af2
default to /site as workdir after bundle install
vidbina Sep 2, 2017
2bb738f
sourceable func for bash and zsh
vidbina Sep 2, 2017
209aa53
1st attempt at documenting the docker approach
vidbina Sep 2, 2017
a7a7e73
Merge branch 'master' into dockerize
vidbina Sep 2, 2017
1381be0
Merge documentation and shell func
vidbina Sep 2, 2017
0a6fc82
tried to be clearer... hopefully it worked
vidbina Sep 2, 2017
6cfbab0
which function?!?
vidbina Sep 2, 2017
a31946e
how-to enable func.sh + moved some bits to asides
vidbina Sep 2, 2017
3b30541
forgot to close
vidbina Sep 2, 2017
21101e2
Merge remote-tracking branch 'upstream/master'
vidbina Nov 25, 2017
cbe4cdf
docker image: moved /gh-pages to /src/gh/pages-gem
vidbina Nov 26, 2017
03709aa
docker image: echo err on undef or invalid $SITE
vidbina Nov 26, 2017
9d8fe18
docker image: moved /site to /src/site
vidbina Nov 26, 2017
f4a8d87
docker image: moved func.sh to contrib/func.sh
vidbina Nov 26, 2017
bc487a3
Merge branch 'master' into dockerize
vidbina Nov 27, 2017
8b6a3d2
Merge branch 'upstream/master' into dockerize
vidbina Nov 27, 2017
9d3ffff
docker helper: better shebang
vidbina Nov 27, 2017
be1ac57
docker helper: set uid and gid
vidbina Nov 27, 2017
7753628
docker image: set locale
vidbina Nov 28, 2017
72f81a3
docker image: installed nodejs
vidbina Nov 28, 2017
c09e851
docker image: minimized locale ops to single RUN
vidbina Nov 28, 2017
b3b4b84
Merge branch 'master' into dockerize
vidbina Dec 11, 2017
e8eb664
Merge branch 'master' into dockerize
benbalter Mar 16, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM ruby:2.4

RUN apt-get update \
&& apt-get install -y \
git \
locales \
make \
nodejs

COPY . /src/gh/pages-gem

RUN \
bundle config local.github-pages /src/gh/pages-gem && \
bundle install --gemfile=/src/gh/pages-gem/Gemfile

RUN \
echo "en_US UTF-8" > /etc/locale.gen && \
locale-gen en-US.UTF-8

ENV LANG en_US.UTF-8
ENV LANGUAGE en_US.UTF-8
ENV LC_ALL en_US.UTF-8

WORKDIR /src/site

CMD ["jekyll", "serve", "-H", "0.0.0.0", "-P", "4000"]
33 changes: 33 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
DOCKER=docker

TAG=gh-pages

# Build the docker image
image:
${DOCKER} build -t ${TAG} .

# Produce a bash shell
shell:
${DOCKER} run --rm -it \
-p 4000:4000 \
-u `id -u`:`id -g` \
-v ${PWD}:/src/gh/pages-gem \
${TAG} \
/bin/bash

# Spawn a server. Specify the path to the SITE directory by
# exposing it using `expose SITE="../path-to-jekyll-site"` prior to calling or
# by prepending it to the make rule e.g.: `SITE=../path-to-site make server`
server:
test -d "${SITE}" || \
(echo -E "specify SITE e.g.: SITE=/path/to/site make server"; exit 1) && \
${DOCKER} run --rm -it \
-p 4000:4000 \
-u `id -u`:`id -g` \
-v ${PWD}:/src/gh/pages-gem \
-v `realpath ${SITE}`:/src/site \
-w /src/site \
${TAG}

.PHONY:
image server shell
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ A simple Ruby Gem to bootstrap dependencies for setting up and maintaining a loc

## Usage

One may opt for the conventional approach of using the pages-gem or the containerized approach in which a Docker container is used to provide an environment with most dependencies pre-installed.

### Conventional

**Important: Make sure you have Bundler > v1.14 by running `gem update bundler` in your terminal before following the next steps.**

1. Add the following to your project's Gemfile:  
Expand All @@ -19,6 +23,29 @@ A simple Ruby Gem to bootstrap dependencies for setting up and maintaining a loc

*Note: You are not required to install Jekyll separately. Once the `github-pages` gem is installed, you can build your site using `jekyll build`, or preview your site using `jekyll serve`.* For more information about installing Jekyll locally, please see [the GitHub Help docs on the matter](https://help.github.com/articles/using-jekyll-with-pages#installing-jekyll).

### Docker

Provided that Docker is installed, one may avoid the setup of additional tools within the environment by simply spawning a Docker container.

1. Run `make image` from the root of the pages-gem directory to build an image which will be tagged as `gh-pages`
2. Start an instance of the server by running either:
- `SITE=PATH_TO_YOUR_PROJECT make server` from the root of the `gh-pages` repository (where the Makefile resides) or
- ``SITE=PATH_TO_YOUR_PROJECT docker run --rm -p 4000:4000 -v `realpath ${SITE}`:/src/site gh-pages`` from any directory or
- `github-pages $PATH_TO_YOUR_PROJECT` from any directory when [func.sh](contrib/func.sh) has been sourced into your terminal session or
- `github-pages` from the directory of the Jekyll site to be previewed when [func.sh](contrib/func.sh) has been sourced into your terminal session.

**Note:** the `github-pages` function may be enabled by sourcing func.sh. This can be done by appending

```bash
source $PATH_TO_THIS_DIRECTORY/contrib/func.sh
```

to the scripts that load on initiation of a terminal session (usually `~/.bashrc` on bash or `~/.zshrc` on zsh).:

> Running of `github-pages` inside a directory of a Jekyll site spawns a [server on port 4000](http://localhost:4000). One may explicitly provide a path to a Jekyll site and a port by running `github-pages $PATH $PORT`. This approach is provided as a user-friendlier alternative to the `make server` or `docker run` invocations mentioned as the first options in step 2.

> The ordering of the arguments for the `github-pages` function is based on the assumption that it is more likely to need to specify a custom path rather than a custom port.

### Command line usage

The GitHub Pages gem also comes with several command-line tools, contained within the `github-pages` command.
Expand Down
13 changes: 13 additions & 0 deletions contrib/func.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env sh
# The github-pages function optionally takes two arguments
# - the first argument is the path to the Jekyll site
# - the second argument is the port number
function github-pages {
_path=${1:-.}
_port=${2:-4000}
docker run --rm \
-p $_port:4000 \
-u `id -u`:`id -g` \
-v `realpath $_path`:/src/site \
gh-pages
}