Guide to Setting Up Discourse Development Environment - GitHub Codespace

Developing Using GitHub Codespaces

GitHub Codespace is a great development option. It’s great because it’s hosted in the cloud, I can easily ensure that everyone developing here has the same environment, no dealing with local docker installations, easy access to making my local dev instance available publicly, and also just using new technology is fun.

I’m currently re-learning development and decided to pickup GitHub Codespaces in addition to learning some Discourse development, so I made this guide for anyone else looking to develop on Discourse in GitHub Codespace rather than setting up a local environment.

I decided to write this guide after going through a slew of issues getting this working with GitHub Codespace myself:

This guide will assume nothing, so we don’t miss a single step to getting you up and running. I suspect some of this process can be improved at the core repo level for the GitHub Codespace configuration, or at least due to my lack of understanding. Don’t hesitate to point these out.

Fork the Discourse repository

  1. Navigate to https://github.com/discourse/discourse

  2. Click the Fork button in the top-right of the page and click the green 'Create fork` button on the subsequent page.

  3. After a brief moment, you’ll be taken to your new fork of the discourse/discourse repository:

Setup Your GitHub Codespace

  1. Click the green <> Code button

  2. Switch to the Codespaces tab and click the green Create codoespace on main button.

  3. You’ll be taken to a new window where GitHub will start creating your codespace. This should take 1-3 minutes:
    chrome_LYoRTOWojo

  4. After a few minutes, you’ll be presented with your GitHub Codespace (which is just VS Code in your browser):

Setup Your Codespace Environment

There are some configurations to make to your codespace environment before you’re up and running.

  1. Create a new bash shell by click Ctrl + Shift + backtick on Windows/Linux, or Cmd + Shift + backtick on Mac. Your shell should have you starting int he /var/www/discourse directory.

  2. Navigate to the discourse directory:

cd workspace/discourse

  1. Install everything from the project Gemfile
bundle install --gemfile ./Gemfile

The command is quite long, but you’ll see something like this:

  1. Add a new config.hosts to the development.rb
    1. From the directory you’re currently in (/var/www/discourse/workspace/discourse) open the file config/environments/development.rb.
    2. Find the line config.hosts << /\A(([a-z0-9-]+)\.)*localhost(\:\d+)?\Z/ and create a new line below it with the following, then save the file:
config.hosts << /^(.*)\.app\.github\.dev$/

The tail-end of your file should look like this (notice line 102 in my screenshot):

  1. Back down in your terminal, run bundle exec rake admin:create to create your first admin account. The command will ask you to choose an email and a password (password must be at least 10 characters)

Start Your Engines Server

It will take 1-2 minutes to build and start the server. At this point, you should now have everything you need to run and access your application.

  1. In the same terminal you’re in, run the following command to start your server:
bin/ember-cli -u

  1. Switch from the Terminal tab to the PORTS tab in your console:

  2. Click on the Forwarded Address for port 4200 using Ctrl + click for Windows/Linux, or Cmd + click for Mac and you’ll be greeted with your development environment!

Hopefully this helps someone else in getting started with GitHub Codespaces! :tada:

9 Likes

Great, it’s a good option when traveling light

1 Like

Or in my case, I really don’t want to develop on windows and docker, but also don’t want to switch to a Unix environment at home (though I use one at work).

I just like the idea that everything is right there in my GitHub repo.

1 Like