From 8a13ff2c6821643e8df08cc0d7731e4b938e9edb Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Tue, 5 May 2020 02:07:32 +0300 Subject: 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. --- .dockerignore | 3 +++ Dockerfile | 41 ----------------------------------------- Dockerfile.base | 34 ++++++++++++++++++++++++++++++++++ Dockerfile.project | 10 ++++++++++ Makefile | 20 ++++++++++++-------- docker-compose.yml | 20 +++++++++++++++----- 6 files changed, 74 insertions(+), 54 deletions(-) create mode 100644 .dockerignore delete mode 100644 Dockerfile create mode 100644 Dockerfile.base create mode 100644 Dockerfile.project 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 deleted file mode 100644 index 1f56c22..0000000 --- a/Dockerfile +++ /dev/null @@ -1,41 +0,0 @@ -FROM debian:buster-slim - -SHELL ["/bin/bash", "-c"] - -ENV DEBIAN_FRONTEND=noninteractive - -RUN apt update -yq && \ - apt install -yq --no-install-recommends \ - build-essential \ - ca-certificates wget \ - sudo - -# Creating regular user 'developer': -ARG USER=developer -RUN addgroup "$USER" && \ - adduser --disabled-password --gecos "" --ingroup "$USER" --home "/home/$USER" "$USER" && \ - addgroup "$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" - -ENV PATH="/home/$USER/.local/bin:$PATH" - -COPY ["docker/Makefile", "./"] -RUN sudo make ruby-install && \ - sudo make ruby-install/clean && \ - make ruby && \ - sudo make chruby && \ - 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.base b/Dockerfile.base new file mode 100644 index 0000000..2957289 --- /dev/null +++ b/Dockerfile.base @@ -0,0 +1,34 @@ +FROM debian:buster-slim + +SHELL ["/bin/bash", "-c"] + +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt update -yq && \ + apt install -yq --no-install-recommends \ + build-essential \ + ca-certificates wget \ + sudo + +# Creating regular user 'developer': +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 "$JEKYLL_USER" +ENV PATH="/home/$JEKYLL_USER/.local/bin:$PATH" + +ENV MAKEFILE_DIR="/utils" +COPY ["Makefile", "$MAKEFILE_DIR/"] +WORKDIR "$MAKEFILE_DIR" + +RUN sudo make ruby-install && \ + sudo make ruby-install/clean && \ + make ruby && \ + sudo make chruby && \ + sudo make chruby/profile.d && \ + sudo make chruby/clean && \ + make bundler 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' -- cgit v1.2.3