Skip to content

Commit dd12556

Browse files
author
Bryce Anderson
authored
Add a docker workflow to the site publishing (#128)
Problem It's a huge pain to try and maintain a consistent ruby environment on ones development machine. There is a nonstop struggle to get the right version of ruby, the gems installed, and everything coherent. Solution Use docker to build consistent environments. We add a Dockerfile which bootstraps a Ubuntu 18.04 image with all the fixins and our entry point becomes ``` $ bundle install $ preview_the_site $ publish_the_site ```
1 parent ffc56f1 commit dd12556

File tree

6 files changed

+68
-11
lines changed

6 files changed

+68
-11
lines changed

Dockerfile

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM ubuntu:18.04 as base-image
2+
3+
RUN apt-get update -qqy \
4+
&& apt-get install -qqy --no-install-recommends \
5+
ssh \
6+
build-essential \
7+
libxml2-dev \
8+
libxslt1-dev \
9+
nodejs \
10+
gpg \
11+
curl \
12+
git \
13+
ruby-full \
14+
&& apt-get clean \
15+
&& rm -rf /var/lib/apt/lists/* \
16+
&& gem update --system \
17+
&& gem install bundler:1.16.6
18+
19+

Gemfile

+2
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ gem 'rake', '12.3.3'
1212
gem "rdiscount", '2.2.0.1'
1313
gem "redcarpet", '3.5.1'
1414

15+
gem "tzinfo-data"
16+

Gemfile.lock

+3
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ GEM
139139
hitimes
140140
tzinfo (1.2.5)
141141
thread_safe (~> 0.1)
142+
tzinfo-data (1.2021.3)
143+
tzinfo (>= 1.0.0)
142144
uber (0.0.15)
143145
uglifier (2.7.2)
144146
execjs (>= 0.3.0)
@@ -158,6 +160,7 @@ DEPENDENCIES
158160
rake (= 12.3.3)
159161
rdiscount (= 2.2.0.1)
160162
redcarpet (= 3.5.1)
163+
tzinfo-data
161164

162165
BUNDLED WITH
163166
1.16.6

README.md

+36-11
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,40 @@ repository and submit a pull request for us to review.
99

1010
## Setup
1111

12-
Once you've forked the repository, run the following command to grab the
13-
project's dependencies:
12+
The first thing you need is a recent version of Docker. See the
13+
[Docker Desktop](https://www.docker.com/products/docker-desktop) page for installation
14+
instructions.
15+
16+
The second thing we need to do is get the docker image built. We have a simple helper
17+
command to do that for you:
1418

1519
``` bash
16-
gem install bundler
17-
bundle install
20+
$ build_docker_image.sh
1821
```
1922

20-
Note that you'll need to have [Ruby](https://www.ruby-lang.org/)
21-
and [RubyGems](https://rubygems.org/) installed first.
23+
This will build a new docker image on your local machine and tag it `ghpublish`.
24+
Once that completes successfully we can boot into our docker image and start our work.
25+
26+
``` bash
27+
$ docker_start.sh
28+
# ... Container starts ...
29+
docker $ cd finagle.github.io
30+
docker $ bundle install # installs all the dependencies from the gemfile
31+
```
32+
33+
Now you're ready to start working on the site.
2234

2335
## Generating the site
2436

25-
Now you can run `bundle exec rake dev` and open a browser window to `http://localhost:4567/`
26-
to see your local build of the site. Any changes you make to the `sources`
27-
directory will be reflected more or less immediately, and errors will be shown
28-
in the console you launched `rake dev` in.
37+
Once inside the container with the bundle installed we can generate and preview the site:
38+
39+
``` bash
40+
docker $ bundle exec middleman server # preview the site locally before publishing
41+
```
42+
43+
You can open the site preview from the host OS and preview the files by going to
44+
`http://localhost:4567/` in your host OS's browser. Updates to the underlying source files
45+
will be detected and automatically rebuilt for the previewing server.
2946

3047
## Writing a post
3148

@@ -57,9 +74,17 @@ have changes to suggest, etc. Please let us know if you have any questions!
5774

5875
## Deploying the site
5976

77+
---
78+
**NOTE**
79+
80+
You must have the appropriate Github access to perform the deployment step.
81+
82+
---
83+
6084
Once you merged you new blog post into the `source` branch, it's time to get that deployed
6185
on [Github Pages](https://pages.github.com/) by running `bundle exec middleman deploy`
62-
against the `source` branch.
86+
against the `source` branch from inside the docker container (if you exited you'll need to
87+
`bundle install` again).
6388

6489
## Licensing
6590

build_docker_image.sh

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
# This is pretty basic... It just builds the image and tags it as ghpublish
4+
docker build -t ghpublish .

docker_start.sh

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
# This script will boot you into the image ready to start at the `bundle install` command.
4+
docker run -p 4567:4567 -v "$HOME/.gitconfig:/root/.gitconfig" -v "$HOME/.ssh:/root/.ssh" -v "$PWD:/finagle.github.io" -it ghpublish bash

0 commit comments

Comments
 (0)