From e3a9b3fb4195f4bd0fa19ce3a797503d8de3c702 Mon Sep 17 00:00:00 2001 From: rzen Date: Sat, 5 Sep 2020 00:20:42 -0400 Subject: [PATCH] refactor docker image building --- Dockerfile | 2 -- build/Dockerfile | 17 +++++++++++++++ build/Dockerfile-serve | 8 +++++++ build/docker-entrypoint.sh | 19 +++++++++++++++++ docker-compose.yaml | 38 ++++++++++++++++----------------- jekyll-theme-isabelline.gemspec | 4 ++-- 6 files changed, 65 insertions(+), 23 deletions(-) delete mode 100644 Dockerfile create mode 100644 build/Dockerfile create mode 100644 build/Dockerfile-serve create mode 100755 build/docker-entrypoint.sh diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 094c705..0000000 --- a/Dockerfile +++ /dev/null @@ -1,2 +0,0 @@ -FROM nginx:alpine -COPY _site /usr/share/nginx/html \ No newline at end of file diff --git a/build/Dockerfile b/build/Dockerfile new file mode 100644 index 0000000..8d7e127 --- /dev/null +++ b/build/Dockerfile @@ -0,0 +1,17 @@ +# borrowed from https://github.com/BretFisher/jekyll-serve + +FROM ruby:2.7-alpine + +RUN apk add --no-cache build-base gcc bash cmake git +RUN apk add --no-cache imagemagick + +# install both bundler 1.x and 2.x +RUN gem install bundler -v "~>1.0" && gem install bundler jekyll + +EXPOSE 4000 + +WORKDIR /site + +ENTRYPOINT [ "jekyll" ] + +CMD [ "--help" ] \ No newline at end of file diff --git a/build/Dockerfile-serve b/build/Dockerfile-serve new file mode 100644 index 0000000..2e9163f --- /dev/null +++ b/build/Dockerfile-serve @@ -0,0 +1,8 @@ +FROM docker.rzen.dev/jekyll:latest + +COPY docker-entrypoint.sh /usr/local/bin/ + +# on every container start, check if Gemfile exists and warn if it's missing +ENTRYPOINT [ "docker-entrypoint.sh" ] + +CMD [ "bundle", "exec", "jekyll", "serve", "--force_polling", "-H", "0.0.0.0", "-P", "4000" ] \ No newline at end of file diff --git a/build/docker-entrypoint.sh b/build/docker-entrypoint.sh new file mode 100755 index 0000000..fa2c414 --- /dev/null +++ b/build/docker-entrypoint.sh @@ -0,0 +1,19 @@ +#!/bin/bash +set -e + +if [ ! -f Gemfile ]; then + echo "NOTE: hmm, I don't see a Gemfile so I don't think there's a jekyll site here" + echo "Either you didn't mount a volume, or you mounted it incorrectly." + echo "Be sure you're in your jekyll site root and use something like this to launch" + echo "" + echo "docker run -p 80:4000 -v \$(pwd):/site bretfisher/jekyll-serve" + echo "" + echo "NOTE: To create a new site, you can use the sister image bretfisher/jekyll like:" + echo "" + echo "docker run -v \$(pwd):/site bretfisher/jekyll new ." + exit 1 +fi + +bundle install --retry 5 --jobs 20 + +exec "$@" \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index 0564950..dffb2bd 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -5,32 +5,32 @@ services: serve: container_name: isabelline-serve - image: jekyll/jekyll:4 - command: jekyll serve --host 0.0.0.0 --future --draft --force_polling --livereload + image: docker.rzen.dev/jekyll-serve + # command: jekyll serve --host 0.0.0.0 --future --draft --force_polling --livereload environment: JEKYLL_ENV: local ports: - 4000:4000 - 35729:35729 volumes: - - .:/srv/jekyll + - .:/site - .bundle:/usr/local/bundle # build and push to rubygems.org gem-push: container_name: jekyll-gem-push - image: jekyll/jekyll:4.0 - command: > - bash -c "gem build -v jekyll-theme-isabelline.gemspec \ - && GEM_VER=`ruby -e '\ - require \"rubygems\"; \ - spec = Gem::Specification::load(\"jekyll-theme-isabelline.gemspec\"); \ - puts \"#{spec.version}\"'` \ + image: docker.rzen.dev/jekyll + command: | + bash -c "gem build -v jekyll-theme-isabelline.gemspec + && GEM_VER=`ruby -e ' + require \"rubygems\"; + spec = Gem::Specification::load(\"jekyll-theme-isabelline.gemspec\"); + puts \"#{spec.version}\"'` && gem push jekyll-theme-isabelline-$${GEM_VER}.gem " volumes: - - .:/srv/jekyll + - .:/site - .bundle:/usr/local/bundle - ./.gem:/root/.gem @@ -38,28 +38,28 @@ services: jekyll: container_name: jekyll - image: jekyll/jekyll:4.0 + image: docker.rzen.dev/jekyll entrypoint: jekyll environment: JEKYLL_ENV: local volumes: - .bundle:/usr/local/bundle - - .:/srv/jekyll + - .:/site gem: container_name: jekyll-gem - image: jekyll/jekyll:4.0 + image: docker.rzen.dev/jekyll entrypoint: gem volumes: - .bundle:/usr/local/bundle - - .:/srv/jekyll + - .:/site + - ./.gem:/root/.gem bundle: container_name: bundle - image: jekyll/jekyll:4.0 + image: jekyll/jekyll:4 entrypoint: bundle volumes: - # - ./.bundle:/home/jekyll/.bundle - - ./.bundle:/usr/local/bundle - - .:/srv/jekyll + - .bundle:/usr/local/bundle + - .:/site - ./.gem:/root/.gem diff --git a/jekyll-theme-isabelline.gemspec b/jekyll-theme-isabelline.gemspec index e022fa1..208f104 100644 --- a/jekyll-theme-isabelline.gemspec +++ b/jekyll-theme-isabelline.gemspec @@ -1,7 +1,7 @@ # frozen_string_literal: true Gem::Specification.new do |spec| - spec.version = "0.1.20" + spec.version = "0.1.21" spec.name = "jekyll-theme-isabelline" spec.authors = ["Rouslan Zenetl"] @@ -13,7 +13,7 @@ Gem::Specification.new do |spec| # work out which files to include with the theme spec.files = `git ls-files -z`.split("\x0").select do |f| - f.match(%r!^(assets|_(includes|layouts|sass)/|(LICENSE|README|CHANGELOG|index)((\.(txt|md|html)|$)))!i) + f.match(%r!^(assets|build|_(includes|layouts|sass)/|(LICENSE|README|CHANGELOG|index)((\.(txt|md|html)|$)))!i) end # TODO: jekyll ver should be same as image in docker-compose.yaml