-
Notifications
You must be signed in to change notification settings - Fork 22
Add Dev Container configuration for easier and more reproducible setup. #698
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
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
faa9c00
Added Dev Container configuration and updated preferred Python version.
wolfmanstout d3d0848
Manually forward port 8000 (auto-forwarding isn't working on GitHub C…
wolfmanstout f2089ef
Put OZtree_original into a shared volume for ease of access.
wolfmanstout 371341b
Improve Dev Container setup docs.
wolfmanstout 09c7fb5
Add optional auth table step to the Dev Container installation.
wolfmanstout b321929
Improve comments in devcontainer.json.
wolfmanstout ea88331
Revert preferred_python3 (will apply this change separately).
wolfmanstout 58899c2
Update to Python 3.10.
wolfmanstout f772769
Update comment to make it clear that the web2py versions should match…
wolfmanstout 6e89e07
Publish devcontainer server on 8080 and improve documentation.
wolfmanstout 723b0c5
Map port 3306 to 3307 for local MySQL debugging.
wolfmanstout d576f1b
Document port 3307.
wolfmanstout 5a1ac68
Improved dev container docs, updated to work with latest changes, mov…
wolfmanstout f1a8d89
Merge remote-tracking branch 'upstream/main' into dev_container
wolfmanstout b940862
Update docker-compose.yml source paths.
wolfmanstout ef4361e
Improved container comments and docs.
wolfmanstout 4264008
Don't suggest setting is_testing to False in dev container instructions.
wolfmanstout 6af9b4b
Merge branch 'main' into dev_container
hyanwong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| FROM mcr.microsoft.com/devcontainers/javascript-node:18 | ||
| WORKDIR /opt | ||
| # Should align with https://github.com/OneZoom/OZtree-docker/blob/main/Dockerfile | ||
| RUN git clone --recursive https://github.com/web2py/web2py.git --depth 1 --branch v2.27.1 --single-branch web2py \ | ||
| && chown -R node:node web2py | ||
| # Required to avoid build issue when running grunt | ||
| ENV NODE_OPTIONS=--openssl-legacy-provider=0 | ||
| ENV PATH=${PATH}:/opt/web2py/applications/OZtree/node_modules/.bin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| // For format details, see https://aka.ms/devcontainer.json. | ||
| { | ||
| "name": "OZTree Dev", | ||
| "dockerComposeFile": "docker-compose.yml", | ||
| "service": "dev", | ||
| "workspaceFolder": "/opt/web2py/applications/OZtree", | ||
| // Features to add to the dev container. More info: https://containers.dev/features. | ||
| "features": { | ||
| "ghcr.io/devcontainers/features/python:1": { | ||
| "version": "3.10" | ||
| } | ||
| }, | ||
| "forwardPorts": [ | ||
| // This is automatically forwarded if using a local container, but not on Codespaces. | ||
| 8000 | ||
| ], | ||
| "customizations": { | ||
| "vscode": { | ||
| "extensions": [ | ||
| "ms-azuretools.vscode-docker" | ||
| ] | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| version: '3.8' | ||
| services: | ||
| dev: | ||
| build: | ||
| context: . | ||
| dockerfile: dev.Dockerfile | ||
| volumes: | ||
| - type: bind | ||
| source: .. | ||
| target: /opt/web2py/applications/OZtree | ||
| consistency: cached | ||
| - original-repo:/opt/web2py/applications/OZtree_original:ro | ||
| # Overrides default command so things don't shut down after the process ends. | ||
| command: /bin/sh -c "while sleep 1000; do :; done" | ||
| network_mode: service:web | ||
| web: | ||
| build: | ||
| context: . | ||
| dockerfile: web.Dockerfile | ||
| args: | ||
| IMAGE_NAME: ${WEB_IMAGE_NAME} | ||
| volumes: | ||
| - type: bind | ||
| source: .. | ||
| target: /opt/web2py/applications/OZtree | ||
| consistency: cached | ||
| - original-repo:/opt/web2py/applications/OZtree_original | ||
| ports: | ||
| - "8080:80" | ||
| - "3307:3306" | ||
|
|
||
| volumes: | ||
| original-repo: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| ARG IMAGE_NAME | ||
| FROM ${IMAGE_NAME} | ||
| # Based on https://code.visualstudio.com/remote/advancedcontainers/add-nonroot-user#_change-the-uidgid-of-an-existing-container-user | ||
| # This changes the www-data UID to 1000 to match the default user on the host, so that when it | ||
| # chowns everything to www-data, it doesn't make it so that the host user cannot write to the files | ||
| # anymore. | ||
| RUN groupmod --gid 1000 www-data \ | ||
| && usermod --uid 1000 --gid 1000 www-data \ | ||
| && chown -R 1000:1000 /opt/web2py/applications | ||
| # Move the original source code into a shared volume, clearing out anything from past runs. | ||
| RUN if [ -d /opt/web2py/applications/OZtree_original ]; then \ | ||
| rm -rf /opt/web2py/applications/OZtree_original; \ | ||
| fi \ | ||
| && mv /opt/web2py/applications/OZtree /opt/web2py/applications/OZtree_original |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still trying to grok the model.
Ok, so only the web container is running mysql. So when running web2py.py directly in the dev container, it's actually connecting to the mysql instance in the web container, thereby going cross container? In other words, they are sharing the DB.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that is all correct. I originally tried a one container configuration, extending from the prod Dockerfile. That didn't work; it was missing dev tools and the vscode integration was very buggy. I still wanted to reuse as much of that Dockerfile as possible so I split out the dev container. This is apparently a standard practice when working with databases, e.g. see this template: https://github.com/devcontainers/templates/tree/main/src/postgres
I chose a Node.js base image and added Python as a feature. I could've done the reverse too. Another alternative is we could use the universal Linux image which has both (https://github.com/devcontainers/images/tree/main/src/universal), but we lose control over the Python and Node.js versions (FWIW the current versions match ours). A couple advantages to that are that the builds would be faster (adding a feature like Python is slow) and storage would be free on GitHub Codespaces (this is their default image and they don't charge for storage of containers based on this, except for additional files added). I'm open to that change if folks prefer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great, thanks for confirming. I think we should just start with that and see how it goes.
About the DB, I exposed the port in the docker-compose to be able to open it from MySQL workbench (running on Windows). e.g.
I went with 3307 locally to avoid conflicting with my Ubuntu MySQL. Might be worth mentioning that in the doc, and maybe just add that to the default docker-compose.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done and documented.