Crystal Castles blog
…a blog about the Crystal Language
Heads up, if you want to just skip to the end, click this link to get a basic Crystal environment launched in GitPod.
GitPod is a cloud based IDE. Please go visit their site to find out more and try it out by clicking the “ready to code” button above.
What I want to talk about today is putting your Crystal development onto GitPod. Which takes a bit of work right now, because Crystal isn’t supported out the box.
If you’ve used Docker before, you’ll find it pretty simple and in this little guide, I’m going to keep it as simple as possible to get you up and running.
You can get your project into GitPod very easily. First grab the URL of your project (this also works on GitLab and BitBucket BTW). Open a new browser tab and type https://gitpod.io/#
and paste in your URL.
Like this https://gitpod.io/#https://github.com/myname/myrepo
GitPod will boot up an IDE environment for you, which will allow you to edit the files in your project and give you a terminal shell to the environment too.
GitPod will offer to setup the environment for you, and ask you things like such as init/build commands and guess what language / framework you’re using.
For our Crystal project, gitpod doesn’t know how to setup the environment yet. However, it’s pretty simple… so let’s get into the nuts and bolts.
We can add a .gitpod.yml
file to our repo to configure it. We’ll also need to add a .gitpod.Dockerfile
to use a Crystal specific Docker image instead of the ones that they provide at GitPod out the box.
The simplest Crystal development environment is what I’m going for here:
image:
file: .gitpod.Dockerfile
tasks:
- command: crystal spec -v
Let’s also define the Crystal specific .gitpod.Dockerfile
too:
It’s very simple…
FROM crystallang/crystal
Add these into the repo and commit / push the change back to GitHub.
If you just did that in GitPod itself, you shoud stop the workspace, (choose workspace > stop workspace) then view Workspaces and delete the stopped workspace. This is so you can start it up again without caching the workspace environment, and guarantee the Docker image is re-built from the new Crystal environment.
You can also update the README.md
of your project to have a gitpod badge, which will launch the project straight into gitpod’s IDE.
[](https://gitpod.io/#https://github.com/username/project)
l Once you’re ready to code in GitPod, click that badge and away you go.
GitPod’s code editor does support Visual Code Extensions, and will let you select them from the extensions panel (Shift + Cmd + x on a Mac)
At the moment, the two Crystal Lang extensions available aren’t on Open VSX the directory of VS Code Extensions GitPod uses. But don’t worry. You can download the .vsix
file for any VS Code extension and drag it into the GitPod Extensions panel and it’ll install.
I am using the vscode-crystal-lang extension, here’s my full .gitpod.yml
with it installed.
image:
file: .gitpod.Dockerfile
tasks:
- command: crystal spec -v
vscode:
extensions:
- faustinoaq.crystal-lang@0.4.0:I0h+4m6OeYiYhRWQPFRabA==
To configure the plugin we need to add .theia/settings.json
to our repo.
{
"crystal-lang.compiler": "/usr/bin/crystal",
"crystal-lang.problems": "build"
}
To check the location of the crystal compiler, do which crystal
.
See https://github.com/crystal-lang-tools/vscode-crystal-lang/wiki/Settings for more info about the extension settings.