github / pages-gem

A simple Ruby Gem to bootstrap dependencies for setting up and maintaining a local Jekyll environment in sync with GitHub Pages
http://pages.github.com
MIT License
1.82k stars 349 forks source link

Running with docker image does not work out-of-the-box #891

Closed pmarinova closed 1 month ago

pmarinova commented 10 months ago

Before submitting an issue, please be sure to

This issue affects

What did you do (e.g., steps to reproduce)

Attempting to use the github-pages gem using the docker image with the instructions from the README does not work out-of-the-box, for example:

git clone https://github.com/github/pages-gem
cd pages-gem
git checkout v228
docker build -t gh-pages .
cd ..
git clone https://github.com/github/personal-website
cd personal-website
docker run --rm -it -p 4000:4000 -v ${PWD}:/src/site gh-pages

What did you expect to happen?

To be able to run the site locally at localhost:4000

What happened instead?

I got the following error:

Traceback (most recent call last):
        17: from /usr/local/bundle/bin/jekyll:25:in `<main>'
        16: from /usr/local/bundle/bin/jekyll:25:in `load'
        15: from /usr/local/bundle/gems/jekyll-3.9.3/exe/jekyll:11:in `<top (required)>'
        14: from /usr/local/bundle/gems/jekyll-3.9.3/lib/jekyll/plugin_manager.rb:50:in `require_from_bundler'
        13: from /usr/local/lib/ruby/site_ruby/2.7.0/bundler.rb:162:in `setup'
        12: from /usr/local/lib/ruby/site_ruby/2.7.0/bundler/runtime.rb:18:in `setup'
        11: from /usr/local/lib/ruby/site_ruby/2.7.0/bundler/definition.rb:266:in `specs_for'
        10: from /usr/local/lib/ruby/site_ruby/2.7.0/bundler/definition.rb:200:in `specs'
         9: from /usr/local/lib/ruby/site_ruby/2.7.0/bundler/definition.rb:523:in `materialize'
         8: from /usr/local/lib/ruby/site_ruby/2.7.0/bundler/definition.rb:301:in `resolve'
         7: from /usr/local/lib/ruby/site_ruby/2.7.0/bundler/definition.rb:570:in `start_resolution'
         6: from /usr/local/lib/ruby/site_ruby/2.7.0/bundler/resolver.rb:28:in `start'
         5: from /usr/local/lib/ruby/site_ruby/2.7.0/bundler/resolver.rb:61:in `setup_solver'
         4: from /usr/local/lib/ruby/site_ruby/2.7.0/bundler/resolver.rb:357:in `prepare_dependencies'
         3: from /usr/local/lib/ruby/site_ruby/2.7.0/bundler/resolver.rb:357:in `map'
         2: from /usr/local/lib/ruby/site_ruby/2.7.0/bundler/resolver.rb:357:in `each'
         1: from /usr/local/lib/ruby/site_ruby/2.7.0/bundler/resolver.rb:372:in `block in prepare_dependencies'
/usr/local/lib/ruby/site_ruby/2.7.0/bundler/resolver.rb:312:in `raise_not_found!': Could not find gem 'github-pages' in locally installed gems. (Bundler::GemNotFound)

Additional information

The only way I could get it working was by running bundle install before jekyll serve:

docker run --rm -it \
    -p 4000:4000 \
    -v ${PWD}:/src/site \
    gh-pages \
    sh -c "bundle install && jekyll serve -H 0.0.0.0 -P 4000"

Shouldn't the github-pages gem be already preinstalled in the docker image?

pmarinova commented 6 months ago

After updating to the latest version of the pages-gem (v229), the Docker image was updated to Ruby 3 and fails because of issue #752. To work around this you now also need to run bundle add webrick before jekyll serve:

docker run --rm -it \
    -p 4000:4000 \
    -v ${PWD}:/src/site \
    gh-pages \
    sh -c "bundle add webrick && bundle install && jekyll serve -H 0.0.0.0 -P 4000"
pmarinova commented 1 month ago

I tested the fix and the 'github-pages' gem not found error disappears, but the site is not generated properly. Everything is just plain text. It's the same behavior as when there is no Gemfile at the site root.

Anyway, this is not an issue for me anymore as I realized this docker image is intended for development of the github-pages gem whereas my case is to simply run a github-pages site locally. I am now using the latest version of the github-pages gem from rubygems like this: https://gist.github.com/pmarinova/0b345a2656abe079c322ad0a90a32c61