aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2020-05-05 02:07:32 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2020-05-05 02:07:32 +0300
commit8a13ff2c6821643e8df08cc0d7731e4b938e9edb (patch)
treea685a5ea1443acdf0847ca5ff57159b472382b69
parentUPPERCASE user-facing parameters (diff)
downloadjekyll-docker-8a13ff2c6821643e8df08cc0d7731e4b938e9edb.tar.gz
jekyll-docker-8a13ff2c6821643e8df08cc0d7731e4b938e9edb.zip
enable out-of-tree builds
This directory must not be a subdirectory of the Jekyll project anymore. The hacks I had to put in place for this will be documented in the next commit.
-rw-r--r--.dockerignore3
-rw-r--r--Dockerfile.base (renamed from Dockerfile)27
-rw-r--r--Dockerfile.project10
-rw-r--r--Makefile20
-rw-r--r--docker-compose.yml20
5 files changed, 50 insertions, 30 deletions
diff --git a/.dockerignore b/.dockerignore
new file mode 100644
index 0000000..5aded0c
--- /dev/null
+++ b/.dockerignore
@@ -0,0 +1,3 @@
+*
+
+!/Makefile
diff --git a/Dockerfile b/Dockerfile.base
index 1f56c22..2957289 100644
--- a/Dockerfile
+++ b/Dockerfile.base
@@ -11,20 +11,20 @@ RUN apt update -yq && \
sudo
# Creating regular user 'developer':
-ARG USER=developer
-RUN addgroup "$USER" && \
- adduser --disabled-password --gecos "" --ingroup "$USER" --home "/home/$USER" "$USER" && \
- addgroup "$USER" sudo && \
+ARG JEKYLL_USER=developer
+ENV JEKYLL_USER="$JEKYLL_USER"
+RUN addgroup "$JEKYLL_USER" && \
+ adduser --disabled-password --gecos "" --ingroup "$JEKYLL_USER" --home "/home/$JEKYLL_USER" "$JEKYLL_USER" && \
+ addgroup "$JEKYLL_USER" sudo && \
echo -e '%sudo ALL=(ALL) NOPASSWD:ALL\nDefaults env_keep += "HOME"' >> /etc/sudoers
-USER "$USER"
-ENV src_dir="/home/$USER/src"
-RUN mkdir -p -- "$src_dir/docker"
-WORKDIR "$src_dir/docker"
+USER "$JEKYLL_USER"
+ENV PATH="/home/$JEKYLL_USER/.local/bin:$PATH"
-ENV PATH="/home/$USER/.local/bin:$PATH"
+ENV MAKEFILE_DIR="/utils"
+COPY ["Makefile", "$MAKEFILE_DIR/"]
+WORKDIR "$MAKEFILE_DIR"
-COPY ["docker/Makefile", "./"]
RUN sudo make ruby-install && \
sudo make ruby-install/clean && \
make ruby && \
@@ -32,10 +32,3 @@ RUN sudo make ruby-install && \
sudo make chruby/profile.d && \
sudo make chruby/clean && \
make bundler
-
-COPY ["Gemfile", "Gemfile.lock", "../"]
-RUN make dependencies
-
-COPY [".", "../"]
-RUN sudo chown -R "$USER:$USER" ../
-CMD make jekyll/serve
diff --git a/Dockerfile.project b/Dockerfile.project
new file mode 100644
index 0000000..fd74035
--- /dev/null
+++ b/Dockerfile.project
@@ -0,0 +1,10 @@
+FROM jekyll_base
+
+ENV PROJECT_DIR="/project"
+RUN sudo mkdir -p -- "$PROJECT_DIR" && \
+ sudo chown -- "$JEKYLL_USER:$JEKYLL_USER" "$PROJECT_DIR"
+COPY --chown="$JEKYLL_USER:$JEKYLL_USER" ["Gemfile", "Gemfile.lock", "$PROJECT_DIR/"]
+RUN make dependencies
+
+COPY --chown="$JEKYLL_USER:$JEKYLL_USER" [".", "$PROJECT_DIR/"]
+CMD make jekyll/serve
diff --git a/Makefile b/Makefile
index 81fda6c..6b9dee4 100644
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,7 @@ SHELL := bash
makefile_dir := $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
-PROJECT_DIR := $(abspath $(dir $(makefile_dir))/..)
+PROJECT_DIR ?= $(abspath $(dir $(makefile_dir))/..)
RUBY_INSTALL_VERSION ?= 0.7.0
RUBY_VERSION ?= 2.6.5
CHRUBY_VERSION ?= 0.3.9
@@ -22,6 +22,7 @@ auto_sh := $(PREFIX)/share/chruby/auto.sh
ruby_install_url := https://github.com/postmodern/ruby-install/archive/v$(RUBY_INSTALL_VERSION).tar.gz
ruby_install_archive := $(makefile_dir)/ruby-install-$(RUBY_INSTALL_VERSION).tar.gz
ruby_install_dir := $(makefile_dir)/ruby-install-$(RUBY_INSTALL_VERSION)
+
.PHONY: chruby
chruby:
wget -O '$(chruby_archive)' '$(chruby_url)'
@@ -70,7 +71,10 @@ ruby-install/clean:
ruby:
ruby-install -j2 --cleanup ruby '$(RUBY_VERSION)'
-chruby := cd -- '$(PROJECT_DIR)' && . '$(chruby_sh)' && chruby 'ruby-$(RUBY_VERSION)'
+chruby := . '$(chruby_sh)' && chruby 'ruby-$(RUBY_VERSION)'
+project_chruby := cd -- '$(PROJECT_DIR)' && $(chruby)
+bundle := $(project_chruby) && bundle
+jekyll := $(bundle) exec jekyll
.PHONY: bundler
bundler:
@@ -78,13 +82,11 @@ bundler:
.PHONY: dependencies
dependencies:
- $(chruby) && bundle install --jobs=2 --retry=3
+ $(bundle) install --jobs=2 --retry=3
.PHONY: deps
deps: dependencies
-jekyll := $(chruby) && bundle exec jekyll
-
.PHONY: jekyll/build
jekyll/build:
$(jekyll) build --config _config.yml,_config_dev.yml
@@ -93,7 +95,9 @@ jekyll/build:
jekyll/serve:
$(jekyll) serve --host 0.0.0.0 --config _config.yml,_config_dev.yml
-docker_compose := cd -- '$(makefile_dir)' && docker-compose
+# Not an absolute path, cause you know, Windows (more specifically, Cygwin +
+# native Windows docker-compose).
+docker_compose := cd -- '$(makefile_dir)' && docker-compose --env-file ./.env
.PHONY: docker/build
docker/build:
@@ -101,7 +105,7 @@ docker/build:
.PHONY: docker/up
docker/up:
- $(docker_compose) up -d
+ $(docker_compose) up -d project
.PHONY: docker/down
docker/down:
@@ -109,7 +113,7 @@ docker/down:
.PHONY: docker/shell
docker/shell:
- $(docker_compose) exec serve bash --login
+ $(docker_compose) exec project bash --login
.PHONY: docker/clean
docker/clean:
diff --git a/docker-compose.yml b/docker-compose.yml
index 1600e0d..18ec75e 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -1,10 +1,20 @@
-version: '3'
+version: '3.2'
services:
- serve:
+ base:
build:
- context: ..
- dockerfile: docker/Dockerfile
+ context: .
+ dockerfile: "$PWD/Dockerfile.base"
+ args:
+ JEKYLL_USER: developer
+ project:
+ build:
+ context: "${PROJECT_DIR:-..}"
+ dockerfile: "$PWD/Dockerfile.project"
+ depends_on:
+ - base
ports:
- 4000:4000
volumes:
- - ../:/home/developer/src
+ - type: bind
+ source: "${PROJECT_DIR:-..}"
+ target: '/project'