Running Jekyll in Windows Using Docker

It has been just over a year since I wrote a post on running Jekyll in Windows using Vagrant. The world has relentlessly moved on… we now have Jekyll 3 and Docker has become popular to the point that you might want to check it out. So I revisited the way I was running my local version of my Jekyll blog. The previous way I outlined using Vargrant to run Jekyll on Windows has no issues but I needed to test my Jekyll blog against the upgrade that GitHub Pages is doing and so I decided to also try running Jekyll in Docker just for fun.

There are a couple of different Docker containers that will work for testing your Jekyll site locally on Windows. The first option is the official Jekyll Docker container. With this container you can get up and going with Jekyll by its self or by using the provided pages container. Since GitHub Pages supports Jekyll and has extra packages/components that are available when your Jekyll site is built for GitHub Pages, it is a good idea to use the pages container provided to be sure you are getting the closest match to the GitHub Pages environment.

The second option for Docker containers is one created by Hans Kristian Flaatten. This container uses the github-pages gem that is maintained by GitHub themselves. Using this container will mimic the GitHub Pages enviroment and is very similar to the solution I created using Vagrant to Run Jekyll on Windows because they both use the github-pages gem. This is definitely my preferred way of running my blog locally because I know the environment will be closely mimicking the GitHub Pages environment.

Setting up Jekyll using Jekyll Docker Container on Windows

  1. Install Docker
  2. Open the Docker Quickstart terminal
  3. Clone or Create your Jekyll Project and move into the root folder of your project where you _config.yml is located.
  4. Run the following command in the console:

    $ docker run --rm --label=jekyll --volume=%CD%:/srv/jekyll  -it -p 4000:4000 jekyll/jekyll jekyll serve
    
  5. Visit the local address to view your site! (typically 192.168.99.100:4000 if you are using Docker on Mac or Windows)

note that the above command uses the defualt Jekyll docker container. If you want to use the container desgined for GitHub Pages change the image name to jekyll/jekyll:pages

  1. Install Docker
  2. Open the Docker Quickstart terminal
  3. Clone or Create your Jekyll Project and move into the root folder of your project where you _config.yml is located.
  4. Run the following command in the console:

    $ docker run -v "$PWD":/usr/src/app -p "4000:4000" starefossen/github-pages
    
  5. Visit the local address to view your site! (typically 192.168.99.100:4000 if you are using Docker on Mac or Windows)

Considerations

Project location for Docker on Windows

Where you create/clone your project on you machine matters other wise you may get permission errors or a note that your configuration file is not found. I found this issue on the Jekyll Docker repository where the project was in the wrong location. On Windows and Mac the Virtual Machine that is created to run Docker mounts the user’s home directory (c:\users\foo) by default. If your Jekyll project does not live in that path then you maybe get an error similar to:

Configuration file: none
       Source: /srv/jekyll
       Destination: /srv/jekyll/_site
Incremental build: disabled. Enable with --incremental
      Generating...
                    done in 0.017 seconds.
Auto-regeneration: enabled for '/srv/jekyll'
Configuration file: none
jekyll 3.0.2 | Error:  Permission denied @ dir_s_mkdir - /srv/jekyll/_site
ok: down: /etc/startup3.d/nginx: 1s, normally up
sh: can't kill pid 29: No such process

Upgrading Jekyll

If you have an existing project that is upgrading to Jekyll 3.0 you may need to make a few updates to your Jekyll project _config.yml file to get the project to run properly using GitHub Pages Container. See they details in Jekyll’s upgrade documentation.

Conclusion

It wasn’t strictly necessary to switch to using Docker to run Jekyll and my Jekyll Vagrant box will still work. Choosing to explorer Docker as an alternative was for fun and a learning experience. The world is moving to containerized solutions so it was a good experience running Jekyll in Docker and will make it easy to potentially deploy my blog to another location in the future. As always, I would love to hear your feedback and let me know if you are successful (or not) using this or other solutions to run Jekyll on Windows.

Getting Started with Project Oxford Machine Learning APIs and Deployment on Azure

Project Oxford is cool. I am out at a lot of hackathons where I see students creating some amazing applications. While at the hackathons I see students struggling to get started with Project Oxford in their language of choice. Project Oxford is so powerful that I hate to see students struggle getting started so I created a series of videos and sample projects to get them started quickly. But Project Oxford is not only for hackathons and students. Project Oxford has tons of real world applications such as image and video processing, OCR, and text to speech.

By the end of the videos you will have a full working sample and learn a few tricks like using the Kudu Dashboard along the way.

  1. Introduction to Project Oxford Machine Learning API’s
  2. How to set up your local Python environment for development and testing
  3. Configuring GitHub Continuous Deployment on Azure with Project Oxford Application

Sample projects

The sample project that used in the series is located at https://github.com/jsturtevant/happy-image-tester-django. If you prefer Node.js I have a made a similar project located at https://github.com/jsturtevant/happy-image-tester-nodejs.

Project Oxford API’s

You can find API wrappers for many of the languages:

How to install Elixir using Chocolatey on Windows

I got hooked on Elixir after reading Programming Elixir by Dave Thomas so I had to figure out how to install it on Windows. Turns out that installing Elixir on Windows is very easy using Chocolatey. If you haven’t heard of Chocolately before, it is the missing package manager for Windows (similar to apt-get or homebrew). When combined with Boxstarter, it can be used to automatically set up your development environment.

Installing Elixir

To install Elixir using Chocolaty:

  1. Make sure you have Chocolaty installed.
  2. Open an administrative cmd prompt
  3. Type choco install elixir (add -y to skip install prompts)
  4. Restart your cmd prompt.

That is it! The last command will not only install the latest version of Elixir but it will install Erlang which is a prerequisite for Elixir. It will also add Elixir to your PATH (if not you can find the commands at C:\ProgramData\chocolatey\lib\Elixir\bin and manually add it) so you can open up a command prompt and type iex to start Elixir’s Interactive Mode.

Have fun getting started with Elixir!

How to view, add, edit and remove files in Azure Web App using the Kudu service Dashboard

While debugging your Azure Web App deployments it is sometimes useful to view the files that are deployed to the service. Several situations come to mind. For example, trying to debug your database connection strings or possibly determining which files actually got deployed and where they sit in the file system. Or maybe you need to check if all your dependencies have been installed. Maybe a firewall blocks your FTP access.

But how do you do view the files if you are using a Platform as a Service (PaaS) solution such as Web Apps? PaaS doesn’t set up a virtual machine that you can remote into in the traditional sense and instead abstracts all that complexity away for you. Enter the Kudu Service Dashboard.

What is Kudu?

Kudu is a set of tools and extensibility points for App Service applications. Anytime you set up a git deployment in Azure Web Sites, Kudu is running and managing the deployment. Kudu also allows you to see environment variables, see processes running on the machine, use a cmd console and much more. It also provides a way for you to create extensions for Azure Websites that give you powerful capabilities like Image Optimization or adding Go support.

Not only can it do all that and more but it can also run outside of Azure on your on server. You can even fork the source code and tell Azure to use your own version of Kudu.

How do you start using it?

How to view Kudu service dashboard

There are two ways to access Kudu:

  1. Simply modify your website URL and by adding scm to it. If you site is http://mysite.azurewebsites.net/, then the root URL of the Kudu service is https://mysite.scm.azurewebsites.net/. Note the added scm token.

  2. Using the Azure Portal. First Navigate to your Web App, Select Tools -> Kudu -> Go:

launch Kudu from azure portal

How to View, Add, Edit, and Remove files in Azure Web App using Kudu

Finally this post was about how you actually view, edit, add, and remove files from the Web App. Once you have your Kudu service Dashboard open you will see some basic information and links for more complex tasks:

Kudu home page

View Current Files

View current files in your application by Clicking on Debug Console -> CMD:

Kudu view files

Once you are viewing the folder structure you can get to your application home directory by clicking the site folder:

Kudu site folder

And then the double clicking wwwroot folder:

Kudu site folder

This is where all your files live. You can even customize this location. In this case, only the default starter HTML page is available but in the case of a larger application there would be many files.

Kudu your files live here

Edit Files

To edit a file click the pencil icon:

launch Kudu from azure portal

Add Files

To add a file you can drag it from your file system to the folder. It is important to drag it directly onto the folder viewer.

launch Kudu from azure portal

Remove Files

Toe remove a file click the minus icon:

launch Kudu from azure portal

Conclusion

It is really simple to use the Kudu Service to view, edit, add, and remove files from your Web App. But as you can see there are a lot of capabilities that Kudu brings to Azure Web apps. Another really useful ability that Kudu gives you is the ability to view log files.

Have fun getting to know Kudu and all the possibilities it brings to the table.

Softwrap: A Visual Studio Code Extension

NOTE: This extention is no longer needed. Visual Studio now supports word wrap. The defualt short cut is ALT -Z

I use Visual Studio for most of my development work but I have always had a second editor that was smaller, lightweight and fast, to help accomplish those quick one off edits. A second editor always comes in handy when working on a configuration files, text files or maybe just peeking at code in another project.

I have always used NotePad++ for quick edits because of the speed at which it opens files and I currently use Atom to write my blog posts as it has support for Jekyll. But, as a primarily .NET developer, I find that most of the editors don’t have great out of the box support for C# syntax. Sure I can set it up with great tooling like Omnisharp but that’s an extra thing I have to configure, even if it is made easy with tools.

Visual Studio Code was announced just last year and has had some great momentum as an editor and so I had to take a look at it for my quick editing experience. So far I am very impressed with speed but I also get the syntax highlighting out of the box that I was missing from other editors. There are some other great features it has borrowed from Visual Studio that make it an attractive choice such as IntelliSense, debugging, and Code Lens. Not to mention it is also open source.

Soft wrap in VS Code

VS Code is still in beta so they are adding features all the time. As I have started to use it more often, especially for editing text files and Markdown, I noticed that it was missing a “soft wrap” feature for wrapping lines of text, which made it hard to read long lines without having to scroll.

I looked around a bit but couldn’t find any information on how to wrap the text lines. Even Google/Bing didn’t come up with any results. So I reach out on twitter and got a response from Errich Gamma.

To enable Soft wrap in VS Code you have to open your user settings file (open command pallet, type ‘settings’, select ‘Open User Settings’) and add the following line:

{
// there might be other custom settings you have in this file.
"editor.wrappingColumn": 0
}

The default value is 300 and if you take a look at the default settings you will find the following comment which specifies setting the editor.wrappingColumn value to zero will cause a line wrap equivalent to a “soft wrap”:

// Controls after how many characters the editor will wrap to the next line. Setting this to 0 turns on viewport width wrapping

Softwrap the Visual Studio Code Extension

Obviously, manually opening the User Setting file and editing the editor.wrappingColumn value was going to get old quickly. So I did what any programmer would do… automate the process.

The result is Softwrap, an extension for VS Code, that enable you to quickly switch back and for between a “soft wrap” and your more friendly code wrap. Using Softwrap is simple:

  1. Open Command Pallet
  2. Type ‘Softwrap’ in the command window
  3. Hit Enter.

That is it! Softwrap will toggle on/off and preserve the value it was previously set to even if you had a custom value for editor.wrappingColumn already set in your User Settings file. You can check out the source at my GitHub repository.

Softwrap Implementation Notes

Overall I was really impressed with VS Code’s Extension system and documentation. It was only announced about a month ago and yet it is fairly robust and detailed documentation.

Reading and Writing the User Settings File

The limitation I ran into when trying to write to the User Settings file was that there is no VS Code API for it (see github issue). Again, I got a quick response on twitter that this was something that is under consideration but not yet implemented. The suggestion was to directly modify the file itself as a work around.

This was fairly simple to do because VS Code is sitting on top of Electron and we can leverage all the power and infrastructure of Node.js and the strong ecosystem that comes with it. It was easy enough to use the File System module to read/write the User Settings file.

Finding the Settings Files cross-platform

It was not easy to find the location of all the settings files accross each platform. I finally found the documentation here and these two posts on how to work with Node.js cross-platform:

Comments in User Settings File

VS Code uses a custom JSON schema that allows comments in the settings file. My current implementation does not support comments and will strip them out. This is probably not the best way to handle the situation but will have to do for now.

Conclusion

Visual Studio Code is a strong candidate for my go to editor when editing quick files. It was very quick to build out an extension for VS Code and the community is there for support.

Because it has some advanced support for debugging, editing, and has a robust extension system I am even considering it for my go to tool for ASP.NET 5 development, certainly it is the best option for Node.js development.