<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.9.2">Jekyll</generator><link href="http://kbrnsr.com/feed.xml" rel="self" type="application/atom+xml" /><link href="http://kbrnsr.com/" rel="alternate" type="text/html" /><updated>2022-12-08T14:35:34+00:00</updated><id>http://kbrnsr.com/feed.xml</id><title type="html">A material boy living in a material world</title><subtitle>A  log  containing my musings and explorations of the deep fundamental truths of the Universe.</subtitle><author><name>Kabeer Nasir</name><email>kabeer-contactme1@kbrnsr.com</email></author><entry><title type="html">Setup and run an existing GitHub Pages Jekyll blog with Docker Compose and VS Code Dev Containers</title><link href="http://kbrnsr.com/setup-and-run-an-existing-gitHub-pages-jekyll-blog-with-docker-compose-and-vs-code-dev-containers/" rel="alternate" type="text/html" title="Setup and run an existing GitHub Pages Jekyll blog with Docker Compose and VS Code Dev Containers" /><published>2022-11-17T12:13:00+00:00</published><updated>2022-11-17T12:13:00+00:00</updated><id>http://kbrnsr.com/setup-and-run-an-existing-gitHub-pages-jekyll-blog-with-docker-compose-and-vs-code-dev-containers</id><content type="html" xml:base="http://kbrnsr.com/setup-and-run-an-existing-gitHub-pages-jekyll-blog-with-docker-compose-and-vs-code-dev-containers/">&lt;p&gt;The motivation for writing this guide is mainly because this is a blog and I have no posts.
No, what I hope is that someone, someday, will be searching for some random issue, end up here, and go home with a solution to their problem, exactly like I have done with so many random sites.
I won’t be describing how to set up the blog itself and the necessary configuration for it, but the whole blog, with all the bells and whistles, is available on &lt;a href=&quot;https://github.com/kbrnsr/kbrnsr.github.io&quot;&gt;kbrnsr/kbrnsr.github.io&lt;/a&gt; for your perusal.&lt;/p&gt;

&lt;h2 id=&quot;table-of-contents&quot;&gt;Table of contents&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;#prerequisites&quot;&gt;Prerequisites&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#initial-setup&quot;&gt;Initial setup&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#environment-file&quot;&gt;Environment file&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#vs-code&quot;&gt;VS Code&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#docker-compose&quot;&gt;Docker Compose&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#conclusion&quot;&gt;Conclusion&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;prerequisites&quot;&gt;Prerequisites&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;VS Code v1.73.1.&lt;/li&gt;
  &lt;li&gt;Docker v20.10.21.&lt;/li&gt;
  &lt;li&gt;Docker Compose v2.12.2.&lt;/li&gt;
  &lt;li&gt;VS Code Dev Containers extension (ms-vscode-remote.remote-containers) v0.262.3.&lt;/li&gt;
  &lt;li&gt;VS Code setup with https for git repositories.&lt;/li&gt;
  &lt;li&gt;A properly configured GitHub Pages blog.&lt;/li&gt;
  &lt;li&gt;(Optional) Docker Desktop v4.14.1.&lt;/li&gt;
  &lt;li&gt;(Optional) VS Code Dev Containers extension setup with dotfiles repository.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;initial-setup&quot;&gt;Initial setup&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;/assets/videos/vscode-dev-containers-add-dev-container-configuration-files.webp&quot; alt=&quot;vscode-dev-containers-add-dev-container-configuration-files&quot; /&gt;&lt;/p&gt;

&lt;p&gt;I recommend running the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Dev Containers: Add Dev Container Configuration Files&lt;/code&gt; wizard to auto-magically create all the necessary files or continue to the next step if you already have your project set up.
If you’re still reading this part, then remember to choose an option that starts multiple services. For example &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Ruby on Rails &amp;amp; Postgres&lt;/code&gt;. This will serve as an excellent starting point for further customization.&lt;/p&gt;

&lt;h2 id=&quot;environment-file&quot;&gt;Environment file&lt;/h2&gt;
&lt;p&gt;The env file for Docker Compose needs to be in the project root.
Why?
Well, the default behavior for Compose is to pick up the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.env&lt;/code&gt; file from the same folder as it’s defined in, but this won’t work with the Dev Containers extension, which wants to pick it up from the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.devcontainer&lt;/code&gt; folder or in the worst case the local workspace folder root.
It will &lt;strong&gt;not&lt;/strong&gt; pick it up if defined in any other folder.&lt;/p&gt;

&lt;p&gt;Create the file &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.env&lt;/code&gt; in the project root:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-Shell&quot;&gt;COMPOSE_PROJECT_NAME=kbrnsr.github.io
CONTAINER_WORKSPACE_FOLDER=/workspaces/github
RUBY_VERSION=3.1.2
&lt;/code&gt;&lt;/pre&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;COMPOSE_PROJECT_NAME&lt;/code&gt; should be the same as the project folder name since it is used later in the Compose file.
It is especially useful if you have multiple services in Compose since every service container will be prepended with this name. In Docker Desktop it will group every service container under this name.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CONTAINER_WORKSPACE_FOLDER&lt;/code&gt; is the folder in which the project’s parent folder will be mounted.
My definition is a little special since I have a customized git setup.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RUBY_VERSION&lt;/code&gt; is very straightforward, just set it to the Ruby version you want to use.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;vs-code&quot;&gt;VS Code&lt;/h2&gt;

&lt;p&gt;Create the file &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.devcontainer/devcontainer.json&lt;/code&gt; in your project root with the following content:&lt;/p&gt;

&lt;div class=&quot;language-json highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
	&lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;kbrnsr.github.io&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
	&lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;dockerComposeFile&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;../docker-compose.yaml&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
	&lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;service&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;app&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
	&lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;workspaceFolder&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;/workspaces/github/${localWorkspaceFolderBasename}&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
	&lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;shutdownAction&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;stopCompose&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
	&lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;postStartCommand&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;git config --global --add safe.directory ${containerWorkspaceFolder} &amp;amp;&amp;amp; bundle exec jekyll serve --watch --force_polling --verbose --livereload bundler exec jekyll serve --livereload --host 0.0.0.0&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;name&lt;/code&gt; is used only internally by VS Code GUI, this can be set up to whatever your heart desires.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dockerComposeFile&lt;/code&gt; should be the location of your Docker Compose file relative to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.devcontainer&lt;/code&gt; folder.
In my case it’s in the project root, note that the extension for the Compose file is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.yaml&lt;/code&gt; and not &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.yml&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;service&lt;/code&gt; depends on the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;services&lt;/code&gt; defined in the Compose file, choose the service you want to use to start up as a dev container.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;workspaceFolder&lt;/code&gt; is the workspace folder inside the container.
I have defined it as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/workspaces/github/${localWorkspaceFolderBasename}&lt;/code&gt;, where &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/workspaces/github&lt;/code&gt; is the same as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CONTAINER_WORKSPACE_FOLDER&lt;/code&gt; in the environment file and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;${localWorkspaceFolderBasename}&lt;/code&gt; is the workspace folder name on the local filesystem.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;shutdownAction&lt;/code&gt; is what VS Code is supposed to do when it exits or in any other situation where the dev container needs to stop.
Here it will stop Compose.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;postStartCommand&lt;/code&gt; defines what the dev container will do after starting.
In my case, I need to run a command to make git understand that the container workspace folder is okay to work with as well as startup the Jekyll live server.
The host for the live server needs to be &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0.0.0.0&lt;/code&gt; or it won’t work properly.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;docker-compose&quot;&gt;Docker Compose&lt;/h2&gt;

&lt;p&gt;Create the file &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;docker-compose.yaml&lt;/code&gt; in your project root with the following content:&lt;/p&gt;

&lt;pre&gt;&lt;code class=&quot;language-YAML&quot;&gt;version: '3.8'
services:
  app:
    build:
      context: .
      dockerfile: .docker/Dockerfile
      args:
        - RUBY_VERSION
    ports:
      - &quot;127.0.0.1:4000:4000&quot;
      - &quot;127.0.0.1:35729:35729&quot;
    volumes:
      - ./.:${CONTAINER_WORKSPACE_FOLDER}/${COMPOSE_PROJECT_NAME}:cached
    working_dir: ${CONTAINER_WORKSPACE_FOLDER}/${COMPOSE_PROJECT_NAME}
    # Overrides default command so things don't shut down after the process ends.
    command: sleep infinity
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;As mentioned earlier, the dev container configuration will use the service &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;app&lt;/code&gt; so this will be the part covered here.
It doesn’t use any predefined docker image ergo it needs to be built.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;context&lt;/code&gt; is the location the docker build process will use relative to the Compose file.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dockerfile&lt;/code&gt; is the Dockerfile to be used relative to the compose file.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;args&lt;/code&gt; here will send arguments down to the Dockerfile during the build process, here it will send &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RUBY_VERSION&lt;/code&gt; as defined in the environment file.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ports&lt;/code&gt; will publish ports &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;4000&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;35729&lt;/code&gt; from inside the container to the local system, without these ports you won’t be able to connect to the Jekyll live server in case you wish to use Docker Compose outside of VS Code.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;volumes&lt;/code&gt; will map the folder &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;./.&lt;/code&gt; to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;${CONTAINER_WORKSPACE_FOLDER}/${COMPOSE_PROJECT_NAME}&lt;/code&gt; where the variables are defined in the environment file.
This part can be really useful if you for example had a node project and wanted to put &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;node_modules&lt;/code&gt; in a separate volume to increase performance.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;working_dir&lt;/code&gt; is the default container folder to use whenever we run a command.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;command&lt;/code&gt; is the command to run after startup, to make sure it doesn’t get closed automatically it should be set to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sleep infinity&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;There are of course many ways to skin a cat, but this is my way.&lt;br /&gt;
It might not necessarily be the best method, but if you’ve reached this point, and find something unclear then do send me an email.
If there’s something that can be improved upon, then fork the blog repository, change anything you want and send me a pull request.&lt;/p&gt;

&lt;p&gt;One of the things I could have improved, but haven’t taken the time to implement is making the whole project work with only Docker Compose.
This would have been useful if I ever decided to switch over from VS Code to another integrated development environment.&lt;/p&gt;</content><author><name>Kabeer Nasir</name><email>kabeer-contactme1@kbrnsr.com</email></author><category term="vscode" /><category term="docker-compose" /><category term="docker" /><category term="ruby" /><category term="jekyll" /><category term="github" /><category term="github-pages" /><summary type="html">The motivation for writing this guide is mainly because this is a blog and I have no posts. No, what I hope is that someone, someday, will be searching for some random issue, end up here, and go home with a solution to their problem, exactly like I have done with so many random sites. I won’t be describing how to set up the blog itself and the necessary configuration for it, but the whole blog, with all the bells and whistles, is available on kbrnsr/kbrnsr.github.io for your perusal.</summary></entry></feed>