-
Notifications
You must be signed in to change notification settings - Fork 23
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
Changes from 9 commits
faa9c00
d3d0848
f2089ef
371341b
09c7fb5
b321929
ea88331
58899c2
f772769
6e89e07
723b0c5
d576f1b
5a1ac68
f1a8d89
b940862
ef4361e
4264008
6af9b4b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // 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" | ||
| } | ||
| }, | ||
| // Need newer pymysql version or MySQL connection will fail. | ||
| "postCreateCommand": "pip install cryptography pymysql", | ||
| "forwardPorts": [ | ||
| // This is automatically forwarded if using a local container, but not on Codespaces. | ||
| 8000 | ||
| ], | ||
| "customizations": { | ||
| "vscode": { | ||
| "extensions": [ | ||
| "ms-azuretools.vscode-docker" | ||
| ] | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,26 @@ If you simply want to run a local copy of OneZoom, but not modify the code yours | |
|
|
||
| # OneZoom setup | ||
|
|
||
| ## Installing in a Docker Dev Container | ||
|
|
||
| If you are using Visual Studio Code or another editor that supports [Dev Containers](https://containers.dev/), the easiest way to set up a full development environment is to use the included Dev Container configuration. This will automatically create two containers: one for development (_dev_), and another (_web_) with the MySQL database and production web server (nginx + uwsgi), derived from the Docker image mentioned above. Your source code will be mounted simultaneously into both containers: dev will let you run build commands and web will serve it as a web server you can access via port forwarding. You can also run your own server from the dev container by [running web2py.py directly](#starting-and-shutting-down-web2py) -- this is particularly useful for debugging. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done and documented. |
||
|
|
||
| If you are using Visual Studio Code, perform the following steps (you will need to modify these for another editor): | ||
|
|
||
| 1. Follow the instructions at either https://hub.docker.com/r/onezoom/oztree or https://hub.docker.com/r/onezoom/oztree-complete to save a docker image with IUCN data. | ||
| 1. Follow the [VSCode instructions for installing Dev Container support](https://code.visualstudio.com/docs/devcontainers/containers#_installation). | ||
| 1. `git clone https://github.com/OneZoom/OZtree` into the directory of your choice. If using Windows, it is highly recommended to [clone on the WSL2 filesystem](https://code.visualstudio.com/remote/advancedcontainers/improve-performance#_store-your-source-code-in-the-wsl-2-filesystem-on-windows) both for performance reasons and to avoid permissions issues. If you wish to fork the repository and clone your fork, you will need to copy the tags from upstream, otherwise you will see build issues later. You can do this with `git fetch --tags upstream` followed by `git push --tags`. | ||
|
wolfmanstout marked this conversation as resolved.
|
||
| 1. Open the cloned directory in VSCode. | ||
| 1. Create a `.env` file at the root of the project and add `WEB_IMAGE_NAME=onezoom/oztree-with-iucn`, changing the value to whatever image name you choose in step 1. | ||
| 1. Open the command palette and choose "Dev Containers: Reopen in Container". | ||
|
wolfmanstout marked this conversation as resolved.
Outdated
|
||
| 1. Open an integrated terminal and run the following: `cp /opt/web2py/applications/OZtree_original/private/appconfig.ini /opt/web2py/applications/OZtree/private/ && cp /opt/web2py/applications/OZtree_original/databases/*.table /opt/web2py/applications/OZtree/databases/` | ||
|
hyanwong marked this conversation as resolved.
Outdated
|
||
| 1. Run `npm install && grunt dev`. You will need to rerun `grunt dev` any time you make code changes. | ||
|
hyanwong marked this conversation as resolved.
Outdated
|
||
| 1. Visit http://localhost and the website should load! You can also run your own server from the dev container by [running web2py.py directly](#starting-and-shutting-down-web2py). | ||
|
wolfmanstout marked this conversation as resolved.
Outdated
|
||
| 1. (Optional) Once tables are created, and everything is working, you can set `is_testing = False` in `models/db.py` and `migrate = 0` in `private/appconfig.ini`. This will mean that web2py will not make any changes to table structures in the DB, and also that changes to appconfig.ini will require a web2py restart. | ||
|
hyanwong marked this conversation as resolved.
Outdated
|
||
| 1. (Optional) [Create a manager account](#creating-auth-users--groups) in the auth table, e.g. so you can [view docs](#documentation). | ||
|
|
||
| ## Installing locally | ||
|
|
||
| There are two ways in which you can install OneZoom on a personal computer: full installation and partial installation. | ||
|
|
||
| * *Partial installation* does not create a standalone OneZoom site, but simply creates a local web file containing the javascript tree viewer. Instead of your tree viewer getting information from your own computer, it must do so by constantly requesting data from the OneZoom website (via the OneZoom APIs). This restricts your OneZoom viewer in various ways: you cannot make your own bespoke tree, you cannot change languages in the viewer, and you are dependent upon a permanent, fast internet connection. Also note that this installation method is also relatively untested, and there are unfixed problems with e.g. displaying lists of popular species. However, partial installation may be suitable for developers who simply want to re-program features of the tree viewer, such as colours, branch geometry, etc. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| 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 | ||
| COPY --chown=node:node _COPY_CONTENTS_TO_WEB2PY_DIR/routes.py web2py/ | ||
|
hyanwong marked this conversation as resolved.
Outdated
|
||
| # 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 | ||
|
hyanwong marked this conversation as resolved.
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| 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 | ||
|
|
||
| volumes: | ||
| original-repo: |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| 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 | ||
| # Without this, it will chown everything to www-data on the host and break permissions. | ||
| RUN groupmod --gid 1000 www-data \ | ||
| && usermod --uid 1000 --gid 1000 www-data \ | ||
| && chown -R 1000:1000 /opt/web2py/applications | ||
|
hyanwong marked this conversation as resolved.
|
||
| # 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 | ||
Uh oh!
There was an error while loading. Please reload this page.