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
-
Navigate to
https://github.com/discourse/discourse
-
Click the
Fork
button in the top-right of the page and click the green 'Create fork` button on the subsequent page.
-
After a brief moment, you’ll be taken to your new fork of the discourse/discourse repository:
Setup Your GitHub Codespace
-
Click the green
<> Code
button
-
Switch to the Codespaces tab and click the green
Create codoespace on main
button.
-
You’ll be taken to a new window where GitHub will start creating your codespace. This should take 1-3 minutes:
-
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.
-
Create a new bash shell by click
Ctrl + Shift + backtick
on Windows/Linux, orCmd + Shift + backtick
on Mac. Your shell should have you starting int he/var/www/discourse
directory.
-
Navigate to the discourse directory:
cd workspace/discourse
- Install everything from the project Gemfile
bundle install --gemfile ./Gemfile
The command is quite long, but you’ll see something like this:
- Add a new config.hosts to the development.rb
- From the directory you’re currently in (
/var/www/discourse/workspace/discourse
) open the fileconfig/environments/development.rb
. - 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:
- From the directory you’re currently in (
config.hosts << /^(.*)\.app\.github\.dev$/
The tail-end of your file should look like this (notice line 102 in my screenshot):
- 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.
- In the same terminal you’re in, run the following command to start your server:
bin/ember-cli -u
-
Switch from the
Terminal
tab to thePORTS
tab in your console:
-
Click on the
Forwarded Address
for port 4200 usingCtrl + click
for Windows/Linux, orCmd + click
for Mac and you’ll be greeted with your development environment!
Hopefully this helps someone else in getting started with GitHub Codespaces!