I built a Dockerfile designed to work specifically with the GitHub Pages variant of Jekyll. I am creating a video that shows how to use it. Before I go too far, I would like to know if you have any issues with this implementation?
@ashmaroli has seen a variant of this and suggested Bison likely is not needed, although I do not understand what it does, it was just recommended on several sites I visited, so I left it for no reason other than it seems to be working
Dockerfile
FROM ubuntu:22.04
RUN echo "#################################################"
RUN echo "Get the latest APT packages"
RUN echo "apt-get update"
RUN apt-get update
RUN echo "#################################################"
RUN echo "Install prerequisites"
RUN echo "Partially based on https://gist.github.com/jhonnymoreira/777555ea809fd2f7c2ddf71540090526"
RUN apt-get -y install \
git \
curl \
autoconf \
bison \
build-essential \
libssl-dev \
libyaml-dev \
libreadline6-dev \
zlib1g-dev \
libncurses5-dev \
libffi-dev \
libgdbm6 \
libgdbm-dev \
libdb-dev \
apt-utils
ENV RBENV_ROOT /usr/local/src/rbenv
ENV RUBY_VERSION 3.1.2
ENV PATH ${RBENV_ROOT}/bin:${RBENV_ROOT}/shims:$PATH
RUN echo "#################################################"
RUN echo "Install rbenv to manage Ruby versions"
RUN git clone https://github.com/rbenv/rbenv.git ${RBENV_ROOT} \
&& git clone https://github.com/rbenv/ruby-build.git \
${RBENV_ROOT}/plugins/ruby-build \
&& ${RBENV_ROOT}/plugins/ruby-build/install.sh \
&& echo 'eval "$(rbenv init -)"' >> /etc/profile.d/rbenv.sh
RUN echo "#################################################"
RUN echo "Install ruby and set the global version"
RUN rbenv install ${RUBY_VERSION} \
&& rbenv global ${RUBY_VERSION}
RUN echo "#################################################"
RUN echo "Install Jekyll 3.9.x and include GitHub Pages as a dependency"
RUN gem install jekyll -v '~>3.9.0'
RUN gem install bundler
RUN bundle init
RUN bundle add "github-pages" --version "228" --group "jekyll_plugins"
RUN bundle add webrick
Basically, I am performing the following steps:
Use Ubuntu 22.04 and install [what I assume to be the correct] dependencies for Ubuntu, Ruby, and Jekyll
Install Jekyll 3.9.x (the current version of Jekyll supported on GitHub Pages… as of this writing, it is 3.9.3)
Add webrick, as I believe this is an issue with 3.9.x.
After I build a Docker container using the Dockerfile, I would go into the folder where the Dockerfile already exists, and type the following in a terminal window:
bundle exec jekyll new . --force
RUN bundle install
RUN bundle update
If you have any thoughts, I would appreciate hearing them.
As a reminder, I have not encountered issues, so this is more of a verification question.
Maybe a typo: the RUN in RUN bundle install, etc. will produce an error in a terminal-window/shell. Maybe you meant those lines to be added to the Dockerfile? Or remove RUN?
Also, should those command be run in the Container’s shell? Or local shell (where the Dockerfile lives)?
About bundle install, my understanding is that Github-Pages ignores Gemfile. I.e. any Gemfile in a Github-Pages repo are purely for local development, and are ignore when Github-Pages builds the site. Whether this is an issue depends on what level of Github-Pages fidelity you’re aiming for. For example, if you want errors for unapproved plugins, then I think you’d need to ignore the user’s Gemfile. Ref: https://stackoverflow.com/questions/56261127/is-the-gemfile-lock-file-needed-in-a-jekyll-site-hosted-with-github-pages
@chuckhoupt Good catch re: the RUN commands. I was testing today and found the same issue. They should be a post-run command and not included in the Docker image.
Regarding the Gemfile and Gemfile.lock, I understand they are not required, but when developing locally they can help you avoid installing gems that GitHub Pages does not support (based on my lackluster memory since I mostly use Jekyll 4.x ). I think I will leave that in because this training aims to set up a local Docker dev environment compatible with GitHub Pages-flavored Jekyll.
Hello,
Not sure if I said this prior thread(s), but I see some scope for edits.
Towards the end after RUN gem install bundler, I don’t see the point of initializing a Gemfile and adding gems to it when you scaffold a Jekyll site in a subsequent step.
Running jekyll new <path> creates a new Gemfile and immediately runs bundle install using that Gemfile. You need to pass the flag --skip-bundle to avoid this. Once the scaffolding completes, you may add needed additional gems like github-pages and webrick. To my knowledge, bundle add <gem_name> includes bundle install. So there is no need for a subsequent explicit bundle install and bundle update incantations.
In summary, my set up process would be (example shell script):
Ah, I love a minimization challenge . I setup a simple Github-Pages test repo, and then tried to generate the same site with Docker. Here’s the shortest steps so far:
Run Ruby in Docker:
docker run -it --rm ruby bash
In the container shell, run the following commands:
# Setup basic one-page Markdown site in home dir
cd ~ ; echo hello > index.md
# Setup for Github-Pages
bundle init
bundle add "github-pages" --group "jekyll_plugins"
# Build it
PAGES_REPO_NWO=chuckhoupt/pagestest jekyll build