github_pages_template

Template for my GitHub Pages configuration.

Main
Posts
Post: Getting Started
Written by: Theron E. Weimer, Jr.
On: 2021-03-09 00:00:00 +0000
Updated: 2021-03-10 11:51:00 -0500

Get Jekyll working within VSCode

It doesn’t appear that there is currently an extension for VSCode/VSCodium to Run a Jekyll site. However, this codemunkies article (which references this article by Carlos Mendible) provided a great example of using Docker Desktop (Windows docs) and devcontainers.

For reference, enable Windows Subsystem for Linux version 2 (WSL2) documentation, and integrate with Docker.

  1. Make sure that Windows Subsystem for Linux is enabled as well as the Virtual Machine feature.

     dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
     dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
    
  2. Install the WSL2 kernel.
  3. Optional: Set WSL2 as the default.

     wsl --set-default-version 2
    
  4. Ensure that the WSL image installed is version 2.

     wsl --list --verbose
    

    Convert an image to WSL2.

     wsl --set-version <Distro> 2
    
  5. Make sure the Windows 10 Hyper-V feature is enabled. Reference the Microsoft documentation for Windows containers and enable Hyper-V.

     Get-WindowsOptionalFeature -Online
    

    Note the feature name is “HypervisorPlatform” now.

     Enable-WindowsOptionalFeature -Online -FeatureName HypervisorPlatform -All
    

    or via Turn Windows features on and off

  6. Install Docker Desktop

     choco install docker-desktop
    

    If the Chocolatey installer doesn’t seem to install properly, use the installer from hub.docker.com.

  7. Enable Docker integration with WSL2 image. When Docker Desktop starts, go to Settings > Resources > WSL Integration
  8. Install the VSCode extension. Currently, the Remote - Containers extension is not working in VSCodium, so it is necessary to use VSCode.
  9. Create the .devcontainer directory and files.

     mkdir -p .devcontainer
     curl https://raw.githubusercontent.com/steve-codemunkies/steve-codemunkies.github.io/main/.devcontainer/Dockerfile --output .devcontainer/Dockerfile
     curl https://raw.githubusercontent.com/steve-codemunkies/steve-codemunkies.github.io/main/.devcontainer/devcontainer.json --output .devcontainer/devcontainer.json
    
  10. Update the Dockerfile to support bundler for use with GitHub Pages.

    Added after FROM:

     # Necessary to run bundler within Docker.
     # https://bundler.io/guides/bundler_docker_guide.html
     ENV GEM_HOME="/usr/local/bundle"
     ENV PATH $GEM_HOME/bin:$GEM_HOME/gems/bin:$PATH
    

    Add after installing Jekyll:

     # [Optional] Uncomment this line to install bundler to use with GitHub Pages.
     RUN gem install bundler
    
  11. Create the VSCode tasks file.

     mkdir -p .vscode
     curl https://raw.githubusercontent.com/steve-codemunkies/steve-codemunkies.github.io/main/.vscode/tasks.json --output .vscode/tasks.json
    
  12. Edit the tasks.json file to suit the project.

    Use bundler to install necessary gems.

     {
         "label": "Bundle Install",
         "command": "bundle install",
         "args": [],
         "type": "shell",
         "problemMatcher": []
     }
    

    Use bundler to run Jekyll.

     "command": "bundle",
     "args": [
         "exec",
         "jekyll",
     ...
    
  13. When VSCode prompts to “Reopen in a Container”, do so and the image will be built.