Skip to content

Commit aecad4c

Browse files
committed
Allow docker workflow
1 parent 801ab30 commit aecad4c

File tree

6 files changed

+47
-4
lines changed

6 files changed

+47
-4
lines changed

Dockerfile

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM ruby:2.5
2+
3+
RUN gem install jekyll -v 3.8
4+
RUN gem install jekyll-paginate -v 1.1
5+
RUN gem install jekyll-redirect-from -v 0.15
6+
7+
EXPOSE 4000
8+
9+
CMD ["/bin/sh"]
10+
11+
# This Docker container is intended to only provide the necessary environment to
12+
# build the blog. It does not know about the blog itself. One should provide a
13+
# blog as a mount point and use this soley as a safe-heaven jekyll environment.
14+
15+
# E.g. sudo docker run -it --mount src="$(pwd)",target=/blog,type=bind thoughtram/blog:latest cd /blog && jekyll build

README.md

+16
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,19 @@ sudo gem install jekyll-paginate
1111
1212
jekyll serve
1313
```
14+
15+
## Using docker
16+
17+
This blog requires `ruby`, `jekyll` and a bunch of other dependencies in specific versions. Managing these dependencies can become difficult over time and often the simplest solution is to use `docker`.
18+
19+
**NOTE: Depending on the `docker` installation, the following commands might need to be run using `sudo`.**
20+
21+
| Action | Local Jekyll | Using Docker |
22+
|-----------|---------------------|----------------------------------|
23+
| Building | `jekyll build` | `yarn docker-jekyll-build` |
24+
| Serving | `jekyll serve` | `yarn docker-jekyll-serve` |
25+
| Deplyoing | `yarn deploy [...]` | `yarn deploy --use-docker [...]` |
26+
27+
### Caveats
28+
29+
These commands are intended to be used as straight forward replacements. There's one caveat though: They don't let one use additional parameters. E.g. one can not change the default port for serving, it is hard-wired to serve the site on `http://localhost:4000`.

deploy.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ let execute = (cmd) => {
1111
return output;
1212
}
1313
catch (e) {
14-
//Doesn't feel write to swallow the exceptions but there doesn't seem
15-
//to be a built in way to supress exceptions if git add and git push fail
14+
console.error(chalk.red(e.toString()))
1615
}
1716
}
1817

1918
const metaOnly = process.argv.includes('--meta-only');
2019
const skipMeta = process.argv.includes('--skip-meta');
2120
const force = process.argv.includes('--force');
2221
const noPush = process.argv.includes('--no-push');
22+
const useDocker = process.argv.includes('--use-docker');
2323

2424
const defaultBranch = 'master';
2525
const deployBranch = 'gh-pages';
@@ -52,7 +52,13 @@ if (isBehindUpstream && !force) {
5252

5353
console.log(chalk.green('Performing jekyll build...'));
5454
// perform jekyll build
55-
execute(`jekyll build`);
55+
56+
if (useDocker) {
57+
execute(`./docker-jekyll-build`);
58+
} else {
59+
execute(`jekyll build`);
60+
}
61+
5662

5763
console.log(chalk.green('Generating deploy artifacts...'));
5864
// cleanup temp branches

docker-jekyll-build

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
docker run -it --init --mount src="$(pwd)",target=/blog,type=bind thoughtram/blog:latest /bin/sh -c "cd /blog && jekyll build"

docker-jekyll-serve

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/sh
2+
docker run -it --init -p 4000:4000 --mount src="$(pwd)",target=/blog,type=bind thoughtram/blog:latest /bin/sh -c "cd /blog && jekyll serve --host 0.0.0.0"

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
"main": "index.js",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1",
8-
"deploy": "node deploy.js"
8+
"deploy": "node deploy.js",
9+
"docker-jekyll-build": "./docker-jekyll-build",
10+
"docker-jekyll-serve": "./docker-jekyll-serve"
911
},
1012
"repository": {
1113
"type": "git",

0 commit comments

Comments
 (0)