Skip to content

Github Codespaces configuration #43061

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

Merged
merged 4 commits into from
Sep 21, 2021
Merged

Github Codespaces configuration #43061

merged 4 commits into from
Sep 21, 2021

Conversation

edwinv
Copy link
Contributor

@edwinv edwinv commented Aug 20, 2021

Summary

Github Codespaces allows (new) Rails contributors to easily boot a fully functional environment to make and test changes to Rails. In order for this repository to work will with Codespaces, we need some configuration, this is added in this PR.

The Dockerfile and boot.sh are inspired on the Development Dependencies Install manual and bootstrap.sh file.

Other Information

The devcontainer works, but has a minor issue:

In order to be able to run code right away, we need to run bundle install as a postCreateCommand. Due to the large Gemfile, executing this command takes long. Codespaces doesn't give proper user feedback about the time it takes, therefore a user can be confused why the environment is not fully functional. I haven't found a solution for this problem yet, suggestions welcome!

@rails-bot rails-bot bot added the docs label Aug 20, 2021
@vovimayhem
Copy link

Ain't better to use docker-compose with the devcontainer? downloading images for mysql, postgres, redis might be quicker and more maintainable than installing them on the Docker image...

@vovimayhem
Copy link

vovimayhem commented Aug 22, 2021

Also, a entrypoint script might be added to check bundler (and yarn) dependencies... something similar to this: https://github.com/vovimayhem/rails-last-n-of-each-demo/blob/main/bin/dev-entrypoint

@edwinv
Copy link
Contributor Author

edwinv commented Aug 22, 2021

Ain't better to use docker-compose with the devcontainer? downloading images for mysql, postgres, redis might be quicker and more maintainable than installing them on the Docker image...

It doesn't seem to be possible to use the dockerComposeFile setup in Codespaces right now. This means we need to run Docker inside the container to run Docker images. There is a Docker library script available, but is seems to be more work to add Docker support inside the container than to just install the packages from the package manager. Furthermore, the current setup is more similar to the rails-dev-box approach. When we would run dependencies in Docker, I expect changes in the configuration for connecting to the dependencies, meaning we might break things for current users.

Also, a entrypoint script might be added to check bundler (and yarn) dependencies... something similar to this: https://github.com/vovimayhem/rails-last-n-of-each-demo/blob/main/bin/dev-entrypoint

This is handled in boot.sh right now.

@edwinv
Copy link
Contributor Author

edwinv commented Aug 23, 2021

I've added the Gemfile and package.json to the Dockerfile so we can install the gems on build instead of on startup. This greatly improves the startup time for the devcontainer to be available. In the recent commit, I've added poppler-utils and the latest imagemagick version to make sure all activestorage specs pass.

The devcontainer has been tested by running the specs for all Rails components. All specs are passing, so this should be a stable workspace for development.

You can test this PR by starting a Github Codespace from the green "Edit" button in the right top corner is the screen. In the Codespace you can use the terminal to execute commands.

@edwinv edwinv marked this pull request as ready for review August 23, 2021 10:53
# [Optional] Uncomment this section to install additional OS packages.
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends \
mariadb-server libmariadbclient-dev \
Copy link
Member

Choose a reason for hiding this comment

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

My mariadb and not mysql?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm more familiar with PostgreSQL, so I needed to look this up when I was writing the Dockerfile. Since Debian 9, MySQL is no longer available in the default apt repositories. MariaDB is the new default database engine. Because MariaDB is backwards compatible with MySQL and in most situations a better choice for new projects, I assumed it isn't a problem to follow the OS default database engine approach instead of doing more work to install MySQL.

Because Github actions still run MySQL, compatibility with a real MySQL installation would still be validated when making code changes.

@rafaelfranca rafaelfranca merged commit 9fb53e0 into rails:main Sep 21, 2021
@ghiculescu
Copy link
Member

@edwinv not an expert on this, but I get the feeling more configuration is needed for this to fully work.

https://docs.github.com/en/codespaces/developing-in-codespaces/creating-a-codespace suggests it's only available to some account levels, and https://github.com/features/codespaces says this:

image

I can open a codespace by going to https://github.com/rails/rails and pressing the "." key (I couldn't see any buttons in the UI to do it), but the codespace it spins up doesn't have terminal access so I can't run tests:

image

@edwinv
Copy link
Contributor Author

edwinv commented Sep 21, 2021

@edwinv not an expert on this, but I get the feeling more configuration is needed for this to fully work.

https://docs.github.com/en/codespaces/developing-in-codespaces/creating-a-codespace suggests it's only available to some account levels, and https://github.com/features/codespaces says this:

...

According to the same page, access to Codespace is per repository owner and not per user. As I'm able to start Codespaces in the rails organization, I assume the organization has everything setup correctly. Personally I'm on an older Github plan that doesn't include Codespaces and I indeed have no access to it in my own repositories, but still can start Codespaces for other open source projects.

I can open a codespace by going to https://github.com/rails/rails and pressing the "." key (I couldn't see any buttons in the UI to do it), but the codespace it spins up doesn't have terminal access so I can't run tests:

...

The . shortcut is merely a preview of the repository. If you want to use a Codespace, you can use the green "Code" button on the repo frontpage to start a Codespace:

CleanShot 2021-09-21 at 18 59 54@2x

@ghiculescu
Copy link
Member

Gotcha. Yeah, I don't have that option:

image

@edwinv
Copy link
Contributor Author

edwinv commented Sep 21, 2021

Gotcha. Yeah, I don't have that option:

....

Weird. I interpreted from the communication from Github that it's commonly available in the mentioned plans. This seems like a Github issue and not something the repo configuration can fix.

@ghiculescu
Copy link
Member

Codespaces needed to be enabled for the rails org. Rafael has done that. There’s a new issue though, where we are both seeing this error when building a codespace

image

@edwinv
Copy link
Contributor Author

edwinv commented Sep 21, 2021

I seems like @rafaelfranca has fixed this with 7df466c, the latest main works for me.

@jrochkind
Copy link
Contributor

Does codespace option under "Code" button only show up for Rails committers? I don't get the option either.

@edwinv
Copy link
Contributor Author

edwinv commented Sep 27, 2021

Does codespace option under "Code" button only show up for Rails committers? I don't get the option either.

It seems GitHub is extending the beta gradually. Although from my understanding this is a per-repo setting, it might also depend on your user account. I have Codespaces beta access for some time now.

From the Codespaces FAQ:

Codespaces is rolling out progressively on August 11th, 2021 and can be enabled in settings by organization owners for Team and Enterprise Cloud plans. For users in individual plans, we’re extending the existing Codespaces beta. For those in the beta, access will remain and we’ll share updates on what’s coming in the near future.

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

Successfully merging this pull request may close these issues.

5 participants