Skip to content
This repository has been archived by the owner on Mar 20, 2021. It is now read-only.

Development environment setup with docker #91

Open
3 of 4 tasks
dellagustin opened this issue Feb 17, 2020 · 28 comments
Open
3 of 4 tasks

Development environment setup with docker #91

dellagustin opened this issue Feb 17, 2020 · 28 comments
Labels
website Things revolving around our website

Comments

@dellagustin
Copy link
Contributor

dellagustin commented Feb 17, 2020

I have recently forked and cloned the repository.
As I like keeping a clean host, I will try to create a Dockerfile for easily setting up the environment without needing to install all the dependencies on the host.

My initial goal is to have a docker build followed by a docker run that will build the page, as described on https://github.com/InnerSourceCommons/innersourcecommons.org/blob/3f99fb032d47c93513c08c629a9a5e23e6da3632/CONTRIBUTING.md,

Stretch goals:

  • file system watcher that rebuilds automatically on change
  • live reload of the webpage being served

I am still investigating, so I will not set a definition of done yet, but eventually the stretch goals will be documented on separate tasks.

Acceptance Criteria

  • Provide a way to serve the website using docker
    • With the solution, a user should be able to host the website locally without having to install Jekyll in his/her host machine
  • Create a follow up issue for Docker Toolbox hosts, see Text Edit innersourcecommons.org#91 (comment)
  • Document how to setup the development environment with docker, or create a follow up issue for writing the documentation
  • While serving the website, the solution should be able to rebuild it when the source is changed, without restarting the container OR a follow up issue should be created to track this individual goal
@dellagustin
Copy link
Contributor Author

dellagustin commented Feb 17, 2020

Error during tests with

FROM ruby:2.7.0-alpine3.11

WORKDIR /InnerSource
ADD Gemfile .
ADD Gemfile.lock .

RUN bundle install
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /usr/local/bundle/gems/eventmachine-1.2.7/ext
/usr/local/bin/ruby -I /usr/local/lib/ruby/2.7.0 -r
./siteconf20200217-1-9pc7kt.rb extconf.rb
checking for -lcrypto... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/usr/local/bin/$(RUBY_BASE_NAME)
        --with-ssl-dir
        --without-ssl-dir
        --with-ssl-include
        --without-ssl-include=${ssl-dir}/include
        --with-ssl-lib
        --without-ssl-lib=${ssl-dir}/lib
        --with-openssl-config
        --without-openssl-config
        --with-pkg-config
        --without-pkg-config
        --with-crypto-dir
        --without-crypto-dir
        --with-crypto-include
        --without-crypto-include=${crypto-dir}/include
        --with-crypto-lib
        --without-crypto-lib=${crypto-dir}/lib
        --with-cryptolib
        --without-cryptolib
/usr/local/lib/ruby/2.7.0/mkmf.rb:471:in `try_do': The compiler failed to
generate an executable file. (RuntimeError)
You have to install development tools first.
        from /usr/local/lib/ruby/2.7.0/mkmf.rb:564:in `try_link0'
        from /usr/local/lib/ruby/2.7.0/mkmf.rb:582:in `try_link'
        from /usr/local/lib/ruby/2.7.0/mkmf.rb:801:in `try_func'
        from /usr/local/lib/ruby/2.7.0/mkmf.rb:1029:in `block in have_library'
        from /usr/local/lib/ruby/2.7.0/mkmf.rb:971:in `block in checking_for'
        from /usr/local/lib/ruby/2.7.0/mkmf.rb:361:in `block (2 levels) in postpone'     
        from /usr/local/lib/ruby/2.7.0/mkmf.rb:331:in `open'
        from /usr/local/lib/ruby/2.7.0/mkmf.rb:361:in `block in postpone'
        from /usr/local/lib/ruby/2.7.0/mkmf.rb:331:in `open'
        from /usr/local/lib/ruby/2.7.0/mkmf.rb:357:in `postpone'
        from /usr/local/lib/ruby/2.7.0/mkmf.rb:970:in `checking_for'
        from /usr/local/lib/ruby/2.7.0/mkmf.rb:1024:in `have_library'
        from extconf.rb:8:in `block in check_libs'
        from extconf.rb:8:in `all?'
        from extconf.rb:8:in `check_libs'
        from extconf.rb:95:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can
be found here:

/usr/local/bundle/extensions/x86_64-linux-musl/2.7.0/eventmachine-1.2.7/mkmf.log

extconf failed, exit code 1
Gem files will remain installed in /usr/local/bundle/gems/eventmachine-1.2.7 for
inspection.
Results logged to
/usr/local/bundle/extensions/x86_64-linux-musl/2.7.0/eventmachine-1.2.7/gem_make.out     

An error occurred while installing eventmachine (1.2.7), and Bundler cannot
continue.
Make sure that `gem install eventmachine -v '1.2.7' --source
'https://rubygems.org/'` succeeds before bundling.

In Gemfile:
  jekyll-redirect-from was resolved to 0.16.0, which depends on
    jekyll was resolved to 4.0.0, which depends on
      em-websocket was resolved to 0.5.1, which depends on
        eventmachine

Solved based on docker-library/ruby#163 (comment)

@rrrutledge
Copy link
Collaborator

This is fantastic stuff, @dellagustin. We were having need to uplevel some of our tech game! Looking forward to seeing it develop!

@dellagustin
Copy link
Contributor Author

When trying to serve the page from the docker container with command docker run --rm -it -v <host path of the page>:/source <image>, and the dockerfile having the command CMD jekyll serve --config /source/_config.yml,/source/_config_dev.yml -s /source -d /dist, I get the error below:

  Conversion error: Jekyll::Converters::Scss encountered an error while converting 'assets/css/atom.scss':
                    undefined method `to_sym' for true:TrueClass Did you mean? to_s
                    ------------------------------------------------
      Jekyll 4.0.0   Please append `--trace` to the `serve` command 
                     for any additional information or backtrace. 
                    ------------------------------------------------
Traceback (most recent call last):
        30: from /usr/local/bundle/bin/jekyll:23:in `<main>'
        29: from /usr/local/bundle/bin/jekyll:23:in `load'
        28: from /usr/local/bundle/gems/jekyll-4.0.0/exe/jekyll:15:in `<top (required)>'
        27: from /usr/local/bundle/gems/mercenary-0.3.6/lib/mercenary.rb:19:in `program'
        26: from /usr/local/bundle/gems/mercenary-0.3.6/lib/mercenary/program.rb:42:in `go'
        25: from /usr/local/bundle/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `execute'
        24: from /usr/local/bundle/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `each'
        23: from /usr/local/bundle/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `block in execute'
        22: from /usr/local/bundle/gems/jekyll-4.0.0/lib/jekyll/commands/serve.rb:86:in `block (2 levels) in init_with_program'
        21: from /usr/local/bundle/gems/jekyll-4.0.0/lib/jekyll/command.rb:89:in `process_with_graceful_fail'
        20: from /usr/local/bundle/gems/jekyll-4.0.0/lib/jekyll/command.rb:89:in `each'
        19: from /usr/local/bundle/gems/jekyll-4.0.0/lib/jekyll/command.rb:89:in `block in process_with_graceful_fail'
        18: from /usr/local/bundle/gems/jekyll-4.0.0/lib/jekyll/commands/build.rb:36:in `process'
        17: from /usr/local/bundle/gems/jekyll-4.0.0/lib/jekyll/commands/build.rb:65:in `build'
        16: from /usr/local/bundle/gems/jekyll-4.0.0/lib/jekyll/command.rb:28:in `process_site'
        15: from /usr/local/bundle/gems/jekyll-4.0.0/lib/jekyll/site.rb:76:in `process'
        14: from /usr/local/bundle/gems/jekyll-4.0.0/lib/jekyll/site.rb:202:in `render'
        13: from /usr/local/bundle/gems/jekyll-4.0.0/lib/jekyll/site.rb:515:in `render_pages'
        12: from /usr/local/bundle/gems/jekyll-4.0.0/lib/jekyll/site.rb:515:in `each'
        11: from /usr/local/bundle/gems/jekyll-4.0.0/lib/jekyll/site.rb:516:in `block in render_pages'
        10: from /usr/local/bundle/gems/jekyll-4.0.0/lib/jekyll/site.rb:523:in `render_regenerated'
         9: from /usr/local/bundle/gems/jekyll-4.0.0/lib/jekyll/renderer.rb:63:in `run'
         8: from /usr/local/bundle/gems/jekyll-4.0.0/lib/jekyll/renderer.rb:84:in `render_document'
         7: from /usr/local/bundle/gems/jekyll-4.0.0/lib/jekyll/renderer.rb:100:in `convert'
         6: from /usr/local/bundle/gems/jekyll-4.0.0/lib/jekyll/renderer.rb:100:in `reduce'
         5: from /usr/local/bundle/gems/jekyll-4.0.0/lib/jekyll/renderer.rb:100:in `each'
         4: from /usr/local/bundle/gems/jekyll-4.0.0/lib/jekyll/renderer.rb:102:in `block in convert'
         3: from /usr/local/bundle/gems/jekyll-sass-converter-2.0.1/lib/jekyll/converters/scss.rb:180:in `convert'
         2: from /usr/local/bundle/gems/jekyll-sass-converter-2.0.1/lib/jekyll/converters/scss.rb:173:in `sass_configs'
         1: from /usr/local/bundle/gems/jekyll-sass-converter-2.0.1/lib/jekyll/converters/scss.rb:231:in `sourcemap_required?'
/usr/local/bundle/gems/jekyll-sass-converter-2.0.1/lib/jekyll/converters/scss.rb:224:in `sourcemap_option': undefined method `to_sym' for true:TrueClass (NoMethodError)
Did you mean?  to_s

I already found some references when googling, but I need some more investigation.

@rrrutledge
Copy link
Collaborator

Thanks for this update @dellagustin.

@dellagustin
Copy link
Contributor Author

I reported an issue on https://github.com/jekyll/jekyll-sass-converter:
jekyll/jekyll-sass-converter#102

I already found some references when googling, but I need some more investigation.
The results I have seen before did not lead anywhere.

@dellagustin
Copy link
Contributor Author

Ok, the issue with jekyll-sass-converter as actually on our side.
I am surprised no one had this before, but if one includes the config file _config_dev.yml, then the error should occur.

The problem is the the property sass.sourcemap is currently set to true, and it should either be never, always or development: https://github.com/jekyll/jekyll-sass-converter/blob/b044e9e3ad9ed9ce647fab76c621aeaa89775999/README.md#configuration-options.

This is actually a bug in the existing development setup, I will create separate issue for this one.

@dellagustin
Copy link
Contributor Author

Now, I got past most issues and it should be working, but I think I am facing some networking issues as I am currently using docker toolbox (poor man's version for windows 10 home ...).

I am almost installing a full fledged virtual machine.
I'll troubleshoot that, and soon we should have a docker based development environment version 1.

@maxcapraro
Copy link
Member

Thank you for working on this, @dellagustin. I always had my shenanigans with local builds and your work will make it significantly easier for everyone to contribute to the ISC website!

@maxcapraro
Copy link
Member

One note: If you like, consider creating a "WIP" pull request. Then others can jump in with their docker expertise and maybe help making sense of the error messages :)

@maxcapraro maxcapraro added the website Things revolving around our website label Feb 19, 2020
@dellagustin-sap
Copy link
Contributor

@maxcapraro

One note: If you like, consider creating a "WIP" pull request. Then others can jump in with their docker expertise and maybe help making sense of the error messages :)

That would be my normal working way 😉 , but this time it was very experimental to me, so I decided to keep the WIP transparency through comments on the issue.
I will test it today in a Docker for Mac installation, I am expecting it to work. If that happens, I will send a PR with the current status.

@dellagustin-sap
Copy link
Contributor

And here is why you should take the build once, run anywhere moto of docker has to be taken with a grain of salt.
I use this branch to test it here in macOS: https://github.com/dellagustin/innersourcecommons.org/tree/bug-report__converters-scss-undefined-method-to_sym
I am quite sure that at least the build worked for this branch (it failed when trying to run the container, because of the issue I describe in InnerSourceCommons/innersourcecommons.org#91 (comment) )

Now try to build the image in, what looks to me, the same way, I get the following error:

Step 6/7 : RUN bundle install
 ---> Running in b45682a1cbf1
/usr/local/lib/ruby/2.7.0/rubygems.rb:275:in `find_spec_for_exe': Could not find 'bundler' (1.16.1) required by your /InnerSource/Gemfile.lock. (Gem::GemNotFoundException)
To update to the latest version installed on your system, run `bundle update --bundler`.
To install the missing version, run `gem install bundler:1.16.1`
        from /usr/local/lib/ruby/2.7.0/rubygems.rb:294:in `activate_bin_path'
        from /usr/local/bin/bundle:23:in `<main>'
The command '/bin/sh -c bundle install' returned a non-zero code: 1

back to google and stack overflow... 🤔

@dellagustin-sap
Copy link
Contributor

dellagustin-sap commented Feb 19, 2020

Looking back at how I am currently working:

  1. try, error, solve,
  2. try, error, solve,
  3. ...

I will have some trouble explaining the reasoning behind the lines on the final Dockerfile without polluting it with comments. I will try to make a very complete commit message / PR message.

While doing so, I though a different working mode could be having a feature branch + Milestone + WIP PR, at each try -> fail -> solve cycle I would have a commit explaining how I solved that particular error, and maybe represent the error as a Issue that is part of the Milestone, even if that issue does not refer to master.

Maybe over-engineering, but I think it could be worth a try for the next experimental contribution I am doing.

There is an agility tradeoff, as it would require some additional github rights to setup the milestone and assign the issues to it though.

@lenucksi
Copy link
Member

lenucksi commented Feb 19, 2020

Thanks for approaching this @dellagustin-sap! I've found myself in the "appreciating all the Jekyll things" phase repeatedly only to be overwhelmed by a case a radical pragmatism every time - "screw non-system-wide installation of Jekyll, let's get this done!" ;).
As for the desired features you mentioned initially - I'm fully on board with wanting to have them and Docker looks like a way to go here.

However I'd like to play a bit of the "advocatus diaboli" here in the hopes of saving quite a bit of effort and maintenance in the long run for a 1 or 2 afternoon conversion effort.
I assume the following as a current and desired position:

  • We've got a website that is not excessively complex, all based on a static site generator, Jekyll currently

  • We need to be able to handle Markdown and ASCIIDoc (the learning path content)

  • We want our site to be tested and deployed using CI+CD to GitHub Pages (or possibly somewhere else later) with minimal interaction and need to deal with security updates and maintenance

  • We want our site to be easily editable, previewable, self refreshing, etc locally

  • Currently we use Jekyll as our static site generator, Jekyll does indeed work and is popular.

    • However we face the need for manual security updates and creating a local development environment is quite the effort (see this thread)
    • Jekyll offers quite a bit of plugins, which makes it rather flexible
    • Currently we're testing and deploying using a custom Travis CI YAML and script.
    • There are pre-built GitHub Actions for this too.
  • There is Hugo, another static site generator written in Go and hence offering the usual "single binary" approach.

    • It accepts Markdown and with the usual conversion extensions, just as Jekyll, ASCIIDoc too
    • It's really fast and offers instant rebuilt on file system change
    • Local setup is trivial (MacOS brew, Linux Package Managers or brew, Windows Chocolatey or manual download) and just works, as all you do is install the usual single binary.
    • CI builds can be done using Travis or readymade GitHub Actions.
    • There are conversion scripts to convert the metadata and structure from Jekyll to Hugo

I successfully run my website on Hugo as do quite a lot of other people.
Would you be open to consider the idea of attempting a Hugo conversion for the website and migration to Hugo GitHub Actions instead of the Docker route?
I could also help a bit with this as I already successfully run Hugo.

@dellagustin-sap
Copy link
Contributor

Ok, so the plot thickens...

After following the advice from the error text on my last issue (To update to the latest version installed on your system, run `bundle update --bundler`.), I added the line RUN bundle update --bundler to my Dockerfile, resulting in:

FROM ruby:2.7.0-alpine3.11

WORKDIR /InnerSource
ADD Gemfile .
ADD Gemfile.lock .

RUN apk add --no-cache g++ gcc make musl-dev
RUN bundle update --bundler
RUN bundle install

CMD jekyll serve --config /source/_config.yml,/source/_config_dev.yml -s /source -d /dist

It added a lot of build time, as it seems to be fetching and installing a lot of stuff, but it worked.
This may be a symptom of a flaky dependency settings (i.e. recently released versions of dependencies break the build / serve somehow) - which creates an unstable development environment experience - something we may want to look into the futere.

Now, it builds, it serves, but I can't reach it. Differently from the problem I was having with Docker Toolbox, I am now getting the error ERR_EMPTY_RESPONSE:

image

While researching for the possible cause, I actually found something reasonable that would explain the issue I was having with the connection refused (I already suspected it was something on this direction, as I had this type of issue before). When running locally, jekyll by default only accepts connections from localhost and 127.0.0.1. As we are running on docker, it is as if we were accessing it from another machine, thus the connection is blocked. I found references that mentioned a common solution for both ERR_EMPTY_RESPONSE and ERR_CONNECTION_REFUSED, so I will try that: adding the following arguments to the jekyll commands --host=0.0.0.0, this is supposed to enable connections from outside localhost and 127.0.0.1.

References:

@dellagustin-sap
Copy link
Contributor

Hi @lenucksi,

About InnerSourceCommons/innersourcecommons.org#91 (comment)

First a small note about your comment, I believe you have an issue with some links on the 3rd sub-bullet of the Jekyll topic. You may want to fix that.

Now, the discussion about which solution to use for static website generation tooling to use is, from my perspective, a valid one, but I think it deserves its own issue, how do you feel about creating a new issue and copying the content there?

About the discussion itself, I am always fond o knowing new tooling, but at the moment I can't contribute too much to it, because my knowledge on Jekyll is very sparse, and on Hugo, non-existing.

BR,
Guilherme.

@dellagustin-sap
Copy link
Contributor

dellagustin-sap commented Feb 19, 2020

Aaaand it works!

It is a bit ludicrous that a developer has, still in this day and age, to spend so much time troubleshooting just to get some comfort on his/her development setup...

All right, now I know what to do, I want to test it also on my Docker Toolbox setup and adjust the documentation.

Also, I will try to add a docker-compose.yml file to reduce the setup to a docker-compose up command. One of the things I never did, but I think is possible, is using the current dir as a volume using compose, but I am wiling to try.

I still need to double check If my stretch goal number 1 (well, the first bullet) is actually working - it should, as jekyll serve, should handle that.
The second one I don't expect to get out of the box, but let's see, it will most likely outlive this issue.

The PR will still take some time, as there is a lot of documentation to go with it, but if someone wants to try it, here is the current version of the Dockerfile:

FROM ruby:2.7.0-alpine3.11

WORKDIR /InnerSource
ADD Gemfile .
ADD Gemfile.lock .

RUN apk add --no-cache g++ gcc make musl-dev
RUN bundle update --bundler
RUN bundle install

CMD jekyll serve --host 0.0.0.0 --config /source/_config.yml,/source/_config_dev.yml -s /source -d /dist

To build and run:

  1. docker build .
  2. docker run --rm -it -v $(pwd):/source -p 4000:4000 <image name>

PS: it was so beautiful I had to take a screenshot:
image

@dellagustin-sap
Copy link
Contributor

Update on InnerSourceCommons/innersourcecommons.org#91 (comment), I created a follow up issue for that: #93

I want to fix that one before sending a PR for the docker enablement, as the result of this PR would fail without a fix for #93

@lenucksi
Copy link
Member

lenucksi commented Feb 19, 2020

Hi @lenucksi,

About #91 (comment)

First a small note about your comment, I believe you have an issue with some links on the 3rd sub-bullet of the Jekyll topic. You may want to fix that.

Thanks for noticing, fixed it!

Now, the discussion about which solution to use for static website generation tooling to use is, from my perspective, a valid one, but I think it deserves its own issue, how do you feel about creating a new issue and copying the content there?

I entirely agree and opened #94 for it. Just wanted to field the idea here.

About the discussion itself, I am always fond o knowing new tooling, but at the moment I can't contribute too much to it, because my knowledge on Jekyll is very sparse, and on Hugo, non-existing.

On the positive side that also means that its still easy to pivot. ;)
Hugo effectively feels like Jekyll, mostly some differences in file paths and config markup.
Happy to help with the knowledge I have acquired so far.
Maybe I'll have a bit of time to whip up some demo content.

BR,
Guilherme.

BR,
Johannes

@dellagustin
Copy link
Contributor Author

Based on the research work I created an acceptance criteria, could someone please review it?
I want to also add something about documentation.

@rrrutledge
Copy link
Collaborator

Thanks for this work, @dellagustin.

While serving the website, the solution should be able to rebuild it when the source is changed, without restarting the container

Jekyll already provides this functionality for content files. Hopefully the new solution doesn't remove this ability.

Other parts of acceptance criteria look good.

@rrrutledge
Copy link
Collaborator

Oh, and congrats on the beautiful screenshot! Looking forward to the beautiful PR!

@dellagustin
Copy link
Contributor Author

Back to my Docker Toolbox, I rebuilt the image without RUN bundle update --bundler just to check, I could not see the error I mention in InnerSourceCommons/innersourcecommons.org#91 (comment), but I wanted to double check.

I have no idea what is causing the discrepancy, but adding RUN bundle update --bundler does not harm the build of the image in Docker Toolbox, except perhaps for build time, but I did not measure.

Now, adding --host 0.0.0.0 improved the situation, but not by much, there is still a nasty side effect that I was not expecting - the assets are being fetched from 0.0.0.0 when I access the page on the host using the Docker Machine ip:
image

That is a bit weird, it should not happen and it requires more investigation.
I decided to cut my losses and focus on non-Docker Toolbox hosts for the scope of this issue.
I will increment the definition of done with the task to create a follow up issue for this.

@dellagustin
Copy link
Contributor Author

@rrrutledge about InnerSourceCommons/innersourcecommons.org#91 (comment), I added that part because although I expect it out of the box from jekyll serve, I have so far not tested that yet, and also, I wanted to make it explicit, as it may be other users do not know this is a Jekyll feature (as I did not) - but I don't expect the solution to remove this feature.

@dellagustin
Copy link
Contributor Author

dellagustin commented Feb 21, 2020

Somehow, the stretch goal:

While serving the website, the solution should be able to rebuild it when the source is changed, without restarting the container

was not accomplished by #99 , although this was expected out of the box (maybe my instincts where telling me something when I documented it as stretch goal 😁 )

Update: After testing on Docker for Mac, I can see that the website is automatically updated, so this is probably a issue caused by Docker Toolbox

@dellagustin
Copy link
Contributor Author

Collecting some references for toolbox enablement, and possibly some issues that could come with Docker for Windows:

@dellagustin
Copy link
Contributor Author

I recorded the leftover issues for Docker Toolbox in InnerSourceCommons/innersourcecommons.org#100

@dellagustin-sap
Copy link
Contributor

dellagustin-sap commented Feb 24, 2020

Based on https://tonyho.net/jekyll-docker-windows-and-0-0-0-0/
(See section jekyll serve and URLs)

When jekyll serve is run with --host=0.0.0.0, Jekyll sets the host portion of the site URL to 0.0.0.0 by default, regardless of the url setting in the config. This also affects any absolute URL that Jekyll generates.

This is not ideal for the combination of Jekyll, Docker, and Windows.

Fortunately, Jekyll provides a way to override this:

If JEKYLL_ENV is any value except development (its default value), Jekyll will not overwrite the value of url in your config.

The way I read it: My PR (#99 ) will work on mac, as it understands http://0.0.0.0/ as http://localhost/, but not on windows (be it Docker for windows or Docker Toolbox)

I need to test the JEKYLL_ENV tip, this could actually solve the problems I describe on #100 and also make for setup that works in Docker for Mac, Docker for Windows and Docker Toolbox (with a few tweaks).

maxcapraro referenced this issue Mar 9, 2020
* Fixed sourcemap property - _config_dev.yml

When trying to run the command `jekyll serve` using `_config_dev.yml`,
it failed with the following error:
  Conversion error: Jekyll::Converters::Scss encountered an error while
  converting 'assets/css/atom.scss': undefined method `to_sym' for true:TrueClass Did
you mean? to_s
------------------------------------------------
Jekyll 4.0.0   Please append `--trace` to the `serve` command
               for any additional information or backtrace.
------------------------------------------------
This happens because in `_config_dev.yml` sourcemap is set to `true`,
while the documentation at
https://github.com/jekyll/jekyll-sass-converter stated the allowed
values are `never`, `always` and `development`.

* Docker based development environment

This commit enables the usage of Docker for setting up a development
environment.

It is an implementation for
InnerSourceCommons/innersourcecommons.org#91

With this development, with the command `docker-compose up`, a docker
image is built and a docker contain is run serving the webpage, that
can be accessed on https://localhost:4000

Files:
- `.dockerignore` - ensures that only the necessary files are used in
the context passed to the docker image build, saving build time
- `Dockerfile` - The commands used to build a docker image
- `docker-compose.yml` - Configuration for docker-compose, that enables
a simple development environment setup, automating the image build and
container orchestration

Known limitations:
- Website is not rebuilt automatically when a file is changed, requiring
a container restart (this was expected to work out of the box with
`jekyll serve`, but testing showed it did not work)
- Docker Toolbox is not supported - with this version of docker, the
page can be loaded, but assets are not loaded, as the browser tries to
fetch them from http://0.0.0.0, and the website must be accessed on the
IP returned by `docker-machine ip`. More investigation is necessary.

Explanations:
- `RUN apk add --no-cache g++ gcc make musl-dev` - necessary for
building gem native extensions (eventmachine) - Error message "You have
to install development tools first."
- `RUN bundle update --bundler` - Image build on Docker Toolbox worked
without this, but when trying to build the image on Docker for Mac, it
raised the following error: `find_spec_for_exe': Could not find
'bundler' (1.16.1) required by your /InnerSource/Gemfile.lock.
(Gem::GemNotFoundException)
To update to the latest version installed on your system, run `bundle
update --bundler`.
- `--host 0.0.0.0` - without this line, jekyll will only accept traffice
incoming from `localhost` or `127.0.0.1`, which is not the case when
using Docker for Mac or Docker Toolbox, as it forwards traffic from the host to the
container. Without this line, the browser will show errors
ERR_CONNECTION_REFUSED (Toolbox) or ERR_EMPTY_RESPONSE (Mac).

Remarks:
- Only tested on Docker for Mac and Docker Toolbox

References:
- https://hub.docker.com/_/ruby
- https://docs.docker.com/engine/reference/builder/#dockerignore-file
- https://docs.docker.com/engine/reference/builder/
- docker-library/ruby#163 (How to install
eventmachine)
-
https://stackoverflow.com/questions/41485217/mount-current-directory-as-a-volume-in-docker-on-windows-10
-
https://stackoverflow.com/questions/42893475/how-to-run-jekyll-serve-pointing-to-another-directory
-
https://stackoverflow.com/questions/50540721/docker-toolbox-error-response-from-daemon-invalid-mode-root-docker
-
https://medium.com/@Charles_Stover/fixing-volumes-in-docker-toolbox-4ad5ace0e572
-
https://sashabrava.github.io/2018/making-Jekyll-available-on-local-network.html
- microsoft/vscode-remote-release#764
-
https://stackoverflow.com/questions/16608466/connect-to-a-locally-built-jekyll-server-using-mobile-devices-in-the-lan/16608698

* Docker support enhancement

Added future proof support to Docker for windows
with setting `JEKYLL_ENV` to a value different than
`development`.
With this setting, the ip used in `--host` is not
going to override site.url.
The alternative would be use `build --watch` + a separate
web server for static files, but I did not see any advantage,
and also I wanted to have the livereload option of `serve`.

Added comments on the Dockerfile to explain some
of the non-intuitive parts.

Added support for livereload.

Added EXPOSE statements to the Dockerfile to document ports in use.

References:
- https://jekyllrb.com/docs/configuration/options/#serve-command-options
- https://tonyho.net/jekyll-docker-windows-and-0-0-0-0/
- Cannot set site.url to a different address than the --host flag address in development
  - jekyll/jekyll#5743
- https://docs.docker.com/engine/reference/builder/#expose

* Docker Toolbox enablement

This commit enables the usage of Docker Toolbox with the command
`docker-compose -f docker-compose-toolbox.yml up`.

A similar result could be achieved by editing `_config_dev.yml`
to have 'url':'' and tweak the Dockerfile command to include
the --force_polling option, but I did not want to change the
`_config_dev.yml` without being sure of the consequences for
non docker users.

* Page edit tests documentation

I added a section in CONTRIBUTING.md on how to test the page
edits locally, with and without docker.

So far the instructions only covered testing the build locally,
but not how to serve the page while editing.

Co-authored-by: Guilherme Dellagustin <[email protected]>
lenucksi referenced this issue Mar 16, 2020
* Fixed sourcemap property - _config_dev.yml

When trying to run the command `jekyll serve` using `_config_dev.yml`,
it failed with the following error:
  Conversion error: Jekyll::Converters::Scss encountered an error while
  converting 'assets/css/atom.scss': undefined method `to_sym' for true:TrueClass Did
you mean? to_s
------------------------------------------------
Jekyll 4.0.0   Please append `--trace` to the `serve` command
               for any additional information or backtrace.
------------------------------------------------
This happens because in `_config_dev.yml` sourcemap is set to `true`,
while the documentation at
https://github.com/jekyll/jekyll-sass-converter stated the allowed
values are `never`, `always` and `development`.

* Docker based development environment

This commit enables the usage of Docker for setting up a development
environment.

It is an implementation for
InnerSourceCommons/innersourcecommons.org#91

With this development, with the command `docker-compose up`, a docker
image is built and a docker contain is run serving the webpage, that
can be accessed on https://localhost:4000

Files:
- `.dockerignore` - ensures that only the necessary files are used in
the context passed to the docker image build, saving build time
- `Dockerfile` - The commands used to build a docker image
- `docker-compose.yml` - Configuration for docker-compose, that enables
a simple development environment setup, automating the image build and
container orchestration

Known limitations:
- Website is not rebuilt automatically when a file is changed, requiring
a container restart (this was expected to work out of the box with
`jekyll serve`, but testing showed it did not work)
- Docker Toolbox is not supported - with this version of docker, the
page can be loaded, but assets are not loaded, as the browser tries to
fetch them from http://0.0.0.0, and the website must be accessed on the
IP returned by `docker-machine ip`. More investigation is necessary.

Explanations:
- `RUN apk add --no-cache g++ gcc make musl-dev` - necessary for
building gem native extensions (eventmachine) - Error message "You have
to install development tools first."
- `RUN bundle update --bundler` - Image build on Docker Toolbox worked
without this, but when trying to build the image on Docker for Mac, it
raised the following error: `find_spec_for_exe': Could not find
'bundler' (1.16.1) required by your /InnerSource/Gemfile.lock.
(Gem::GemNotFoundException)
To update to the latest version installed on your system, run `bundle
update --bundler`.
- `--host 0.0.0.0` - without this line, jekyll will only accept traffice
incoming from `localhost` or `127.0.0.1`, which is not the case when
using Docker for Mac or Docker Toolbox, as it forwards traffic from the host to the
container. Without this line, the browser will show errors
ERR_CONNECTION_REFUSED (Toolbox) or ERR_EMPTY_RESPONSE (Mac).

Remarks:
- Only tested on Docker for Mac and Docker Toolbox

References:
- https://hub.docker.com/_/ruby
- https://docs.docker.com/engine/reference/builder/#dockerignore-file
- https://docs.docker.com/engine/reference/builder/
- docker-library/ruby#163 (How to install
eventmachine)
-
https://stackoverflow.com/questions/41485217/mount-current-directory-as-a-volume-in-docker-on-windows-10
-
https://stackoverflow.com/questions/42893475/how-to-run-jekyll-serve-pointing-to-another-directory
-
https://stackoverflow.com/questions/50540721/docker-toolbox-error-response-from-daemon-invalid-mode-root-docker
-
https://medium.com/@Charles_Stover/fixing-volumes-in-docker-toolbox-4ad5ace0e572
-
https://sashabrava.github.io/2018/making-Jekyll-available-on-local-network.html
- microsoft/vscode-remote-release#764
-
https://stackoverflow.com/questions/16608466/connect-to-a-locally-built-jekyll-server-using-mobile-devices-in-the-lan/16608698

* Removed absolute path usage from _head.html

Co-authored-by: Johannes Tigges <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
website Things revolving around our website
Projects
None yet
Development

No branches or pull requests

5 participants