Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: devcontainer to make development easier #230

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

TrueBrain
Copy link
Member

@TrueBrain TrueBrain commented Oct 29, 2021

So this requires a bit of story.
tldr; this is PR is to test the waters, to see if we like this approach, and if the benefits of "anyone can jump in" outweigh the "but there are IDE-specific things in the repo".

But if you want to pitch in, I really urge you to read what I write below :)

For a while now I notice that there are people who have the best intentions to help out with things like our website, but also bananas-server, master-server-web, game-coordinator, etc. But mainly they get stuck in how to setup the development environment.

It is not that the environments themselves are complex, but each repository has its own required setup to work. Take for example game-coordinator, it requires a redis to run, but it is also composed of three applications: coordinator, stun and turn. These all three needs a bit of configuration. Nothing that is not documented, but to "just jump in and develop" is not the case.

I even notice that myself. This week frosch mentioned that a bug in master-server is most likely easily solved by changing a set into a set(nx=True). But to test this, it takes me time to setup the right environment and validate that. As it is a really minor thing, I postpone this. (read: I cannot just jump in)

For BaNaNaS related repository, we have had several people just give up because they couldn't follow the README. Now we can argue that the README is not clear and should be updated, but really .. it contains everything you need. It is just "a lot" if you never worked with it. In the BaNaNaS case specifically, you kinda want some dummy files to play around with .. and that is just difficult to get done on a moments notice.

So, I have been wondering what "devcontainers" is all about. GitHub claims it solves all those problems, so I gave it a spin with this repository (this repository is not the most complicated we have, but also not the easiest). Basically devcontainers can be used in two ways:

  • Via VSCode Remote Containers
  • Via GitHub Codespaces

The idea behind devcontainers is that it contains everything you need to get a working setup. Including databases, storages, ... Additionally, it helps you as much as possible to just "jump in". But, one drawback, it is strongly biased towards the use of VSCode. It is slowly being made a bit more broad, but I have no illusions it will always remain VSCode-ish. For example, only since recent it is easier to ssh into Codespaces to use emacs or vim to develop with. And I couldn't find any other editor that implements devcontainers (I love to be proven wrong here!).
More details about devcontainers, and what they are about, can be found here.

Either way, this is PR is to test the waters, to see if we like this approach, and if the benefits of "anyone can jump in" outweigh the "but there are IDE-specific things in the repo".

If you are signed up for GitHub Codespaces, you can press the green "Code" button on https://github.com/TrueBrain/OpenTTD-website and hit "New codespace".

image

Within a minute or-so you are in VSCode ready to edit the website. Via F1 -> Run Tasks -> Start server, you can start the server. A popup will ask you to open a tab to see the website. And that makes writing blog-posts etc a lot easier, as you can see how the layout will be. But it also allows for easier CSS changes, validating of PRs, etc etc. And .. you can do it from anywhere you like ;)
If you don't want to use Codespaces, you can use VSCode Remote Containers extension. After installing the extension you can go to F1 -> Remote-Containers: Clone Repository in Container Volume. Fill in https://github.com/TrueBrain/OpenTTD-website and off you go. A few minutes later (assuming you have Docker installed) you can edit the website exactly as described above.

(and before anyone asks, after merging these PR, the above URLs of course changes into this repository; but I pushed it to my fork so you can try it out!)

If this idea works, and we like this approach, I want to try to do bananas-server next. This also requires a working OpenTTD game to communicate with the bananas-server for testing (next to checking out some dummy BaNaNaS files etc). I am considering using Emscripten for this, so it works from your browser. This hopefully makes it really trivial to try things out with Codespaces.
For the VSCode Remote Containers route, you can just start OpenTTD with OTTD_CONTENT_CS="localhost", to test against.

Either way .. if it is up to me, this is the first of many of very similar PRs to make our development environments a lot easier for anyone to work with .. to just "jump in and develop". Hopefully that attracts more developers to help out.

Let me know what you think, please try it out (make sure to signup for Codespaces ;)), and if you have any improvements / suggestions, I am all ears!

TrueBrain added 3 commits Oct 30, 2021
Devcontainer integrates nicely with GitHub Codespaces or
VSCode Remote Containers. It makes working on this repository
easier by automating all the tasks leading up to a functional
development environment.
This means jumping into developing this repository is a lot faster;
currently creating the devcontainer takes ~10 minutes, which means
it is hard to just "jump in".
If we use "features", the devcontainer will build (from source!)
Python on-demand. This takes ~3 minutes. We can skip this by copying
the Python interpreter from the pre-build Python image, while building
our devcontainer.

This is basically a quirk of the fact we are a hybrid repo: both
Ruby and Python are used. This is somewhat unusual.
@TrueBrain TrueBrain marked this pull request as draft Oct 30, 2021
{
"name": "Ruby",
"runArgs": ["--init"],
"image": "ghcr.io/truebrain/openttd-website:devcontainer",
Copy link
Contributor

@glx22 glx22 Oct 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't match workflow output 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants