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 support #358

Open
wants to merge 18 commits into
base: develop
Choose a base branch
from
Open

Add Devcontainer support #358

wants to merge 18 commits into from

Conversation

TShapinsky
Copy link
Member

@TShapinsky TShapinsky commented Oct 24, 2024

Devcontainers are an easy way to provide developers with a consistent build environment.

This container comes with buildingmotif python dependencies (all extras) pre installed as well angular cli. It supports both x86_64 and arm64 (to support newer macs).

Devcontainers are supported by several popular code editors and also have a cli for use without one of the supported editors. Users on VSCode will (upon opening the repo) be prompted as to whether they would like to use the dev container or not. If they click yes it will pull the container from github, spin it up and install the extensions I have specified.

TODO:

  • Does the setup work on windows? I'm passing through the host docker socket to the container so that docker can still be used while working within the container. The socket is in a consistent place on mac and linux (/var/run/docker.sock) but I'm not clear as to whether this path on windows is contained within the WSL tree or windows regular file structure.
  • Should volumes be mounted to the paths containing the python packages and node_modules? Right now node_modules lives within the project and the python packages are system wide. When you reload the container you lose any changes you had made to the packages. This could be a good thing, as it provides a stable starting point, but it could get annoying in some cases.
  • Are there additional extensions which should be installed by default? Right now there aren't any node/angular specific ones.
  • Bake pre-commit dependencies into image

@TShapinsky
Copy link
Member Author

@MatthewSteen @gtfierro I'd love to have either of your opinions on this if you have the time to take a look.

@gtfierro
Copy link
Collaborator

This is pretty cool! I got it running with devcontainer up --workspace-folder . and then ran the tests with devcontainer exec --workspace-folder . poetry run pytest -s -vvvv tests . This worked on MacOS and I will probably give it a try on one of my linux boxes later this week.

Should volumes be mounted to the paths containing the python packages and node_modules? Right now node_modules lives within the project and the python packages are system wide. When you reload the container you lose any changes you had made to the packages. This could be a good thing, as it provides a stable starting point, but it could get annoying in some cases.

Do you mean the Python packages are system wide in the devcontainer? Or do they use a copy of the libraries that's on my own machine?

I do occasionally drop into the dependencies to add some debugging statements but I can try to be careful about not reloading the devcontainer while those are in there. I guess I'm not familiar with when the devcontainer reloads -- is this automatic or do I have to trigger it?

@TShapinsky
Copy link
Member Author

Do you mean the Python packages are system wide in the devcontainer? Or do they use a copy of the libraries that's on my own machine?

I wanted to have the python dependencies installed in the devcontainer without copying the entire project in during build time. To accomplish this I copy just the pyproject.toml and poetry.lock into the container and configure poetry to not use virtual environments as a virtual environment created in this process wouldn't be matched to the buildingmotif workspace which is later mounted.

In my regular BuildingMOTIF setup I like to have my virtual environment in a .venv folder in the project, however this can cause some issues with vs code's jupyter integration as it will try to pick up that python install as the correct environment. This won't work since some of those packages are machine sensitive and a macos package mounted onto a debian vm won't run. This isn't a problem outside of vs code as running notebook should behave properly. But for VS code I added a configuration in the devcontainer which masks a .venv folder from being detected by jupyter notebooks.

This approach isn't needed for node dependencies as I believe they are platform agnostic. So node will just use the node_modules folder within buildingmotif-app

I do occasionally drop into the dependencies to add some debugging statements but I can try to be careful about not reloading the devcontainer while those are in there. I guess I'm not familiar with when the devcontainer reloads -- is this automatic or do I have to trigger it?

It seems like the container is reloaded everytime you start it. When I exit VS code the container goes down. A way around this could be mounting a volume, but that would make it so that you would need to reinstall the python packages as you'd be voluming over them.

I'm not entirely happy with the current setup as if you change your depedencies relative to develop you'll be installing those every time you boot the container. The alternative here is to change to devcontainer.json to use the Dockerfile or mount a volume. I'm hesitant to add persistence as I believe the point of the devcontainer is to provide a common environment that is easily reproducable.

Finally, in my mind the devcontainer is probably best suited to people who aren't getting too in the weeds and just want to get an environment to play around with BuildingMOTIF. I don't really think all of us should move to using a devcontainer outside of making sure it stays working (we could potentially use it as our CI base image to enforce this).

Copy link
Member

@MatthewSteen MatthewSteen left a comment

Choose a reason for hiding this comment

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

I'll try to test this on Windows if you haven't already.

Need to add how to use this to the docs, probably with a new page at docs/references/user_documentation.md.

.devcontainer/devcontainer.json Outdated Show resolved Hide resolved
.github/workflows/devcontainer.yml Outdated Show resolved Hide resolved
@TShapinsky
Copy link
Member Author

@MatthewSteen I switched the way I was exposing docker, so it should be pretty stable now. It is now using the official docker outside of docker feature.

@TShapinsky
Copy link
Member Author

The last thing I need to do is switch the CI to run on develop only instead of this branch. But I'm waiting for review before I do that incase there are more things to change.

@TShapinsky
Copy link
Member Author

@MatthewSteen I just tried this out on my desktop running windows 10. It seems to setup fine, interested to see what the error you got was.

@MatthewSteen
Copy link
Member

@TShapinsky I'm the following error, which sounds like Poetry needs to be installed.

[13284 ms] Start: Run in container: /bin/sh -c pre-commit install
[13284 ms] Start: Run in container: /bin/sh -c poetry install --all-extras
[14067 ms] postCreateCommand failed with exit code 1. Skipping any further user-provided commands.

@TShapinsky
Copy link
Member Author

TShapinsky commented Nov 7, 2024

@TShapinsky I'm the following error, which sounds like Poetry needs to be installed.

[13284 ms] Start: Run in container: /bin/sh -c pre-commit install
[13284 ms] Start: Run in container: /bin/sh -c poetry install --all-extras
[14067 ms] postCreateCommand failed with exit code 1. Skipping any further user-provided commands.

Hmm, that's strange. The dockerfile includes poetry and installs all of the dependencies already. Is your working directory clean?

Also is your VS code entirely up to date?

@MatthewSteen
Copy link
Member

Hmm, that's strange. The dockerfile includes poetry and installs all of the dependencies already. Is your working directory clean?

Yes, I cloned the repo to the Windows side of my machine, then checked out this branch.

Also is your VS code entirely up to date?

Yes.

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.

3 participants