From faa9c00ea15b5df1db4294dc3d5cb70e03a46ecf Mon Sep 17 00:00:00 2001 From: James Stout Date: Sun, 17 Dec 2023 06:25:09 +0000 Subject: [PATCH 01/16] Added Dev Container configuration and updated preferred Python version. --- .devcontainer/devcontainer.json | 22 ++++++++++++++++++++++ .gitignore | 1 + Gruntfile.js | 2 +- README.markdown | 22 ++++++++++++++++++++++ dev.Dockerfile | 9 +++++++++ docker-compose.yml | 25 +++++++++++++++++++++++++ web.Dockerfile | 8 ++++++++ 7 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 .devcontainer/devcontainer.json create mode 100644 dev.Dockerfile create mode 100644 docker-compose.yml create mode 100644 web.Dockerfile diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 000000000..485966efa --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,22 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the +// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-docker-compose +{ + "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.8" + } + }, + "postCreateCommand": "pip install cryptography pymysql", + "customizations": { + "vscode": { + "extensions": [ + "ms-azuretools.vscode-docker" + ] + } + } +} diff --git a/.gitignore b/.gitignore index 1a25bdc19..242bc2614 100755 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ OZprivate/rawJS/OZTreeModule/dist/* OZprivate/rawJS/OZTreeModule/docs/_compiled.markdown node_modules OZprivate/ServerScripts/Tests/BlatSearch.code_cache +.env diff --git a/Gruntfile.js b/Gruntfile.js index 3c215beff..f985cb1aa 100755 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -5,7 +5,7 @@ const path = require('path'); partial_install_site = "http://www.onezoom.org"; partial_local_install_site = "http://127.0.0.1:8000"; // if you are running a local installation -preferred_python3 = "python3.7"; // in case you have multiple python3 versions installed +preferred_python3 = "python3.8"; // in case you have multiple python3 versions installed web2py_py = path.join(path.dirname(path.dirname(process.cwd())), 'web2py.py'); /** Generate a function to execute a web2py script, handing over all arguments */ diff --git a/README.markdown b/README.markdown index 19e6ef45d..3c36989c1 100755 --- a/README.markdown +++ b/README.markdown @@ -4,6 +4,28 @@ 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. + +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`. +1. Open the 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". +1. Once all scripts have finished running, you will need to make a couple one-time changes to your local source to sync your source with the web container. First, reopen the repository in your local directory. +1. Visit https://github.com/OneZoom/OZtree-docker/blob/main/appconfig.ini and copy the contents into `private/appconfig.ini`. +1. Open an integrated terminal and run the following: `docker exec $(docker ps -f name=onezoom-web --quiet) sh -c "cp /opt/web2py/applications/OZtree_original/databases/*.table /opt/web2py/applications/OZtree/databases"` +1. Reopen the project within your container. +1. Open an integrated terminal and run `npm install && grunt dev`. +1. Visit http://localhost and the website should load! As noted earlier, you can also run your own server from the dev container by [running web2py.py directly](#starting-and-shutting-down-web2py). +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. + +## 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. diff --git a/dev.Dockerfile b/dev.Dockerfile new file mode 100644 index 000000000..d4ae16d48 --- /dev/null +++ b/dev.Dockerfile @@ -0,0 +1,9 @@ +FROM mcr.microsoft.com/devcontainers/javascript-node:18 +WORKDIR /opt +# Copied from https://github.com/OneZoom/OZtree-docker/blob/main/Dockerfile +RUN git clone --recursive https://github.com/web2py/web2py.git --depth 1 --branch v2.21.1 --single-branch web2py \ + && chown -R node:node web2py +COPY --chown=node:node _COPY_CONTENTS_TO_WEB2PY_DIR/routes.py 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 diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..55b8edc22 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,25 @@ +version: '3.8' +services: + dev: + build: + context: . + dockerfile: dev.Dockerfile + volumes: + - type: bind + source: . + target: /opt/web2py/applications/OZtree + consistency: cached + # 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 diff --git a/web.Dockerfile b/web.Dockerfile new file mode 100644 index 000000000..92079d77b --- /dev/null +++ b/web.Dockerfile @@ -0,0 +1,8 @@ +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 +RUN mv /opt/web2py/applications/OZtree /opt/web2py/applications/OZtree_original From d3d084802c1aec348453c17809e8453cc42d4022 Mon Sep 17 00:00:00 2001 From: James Stout Date: Sun, 17 Dec 2023 23:23:05 +0000 Subject: [PATCH 02/16] Manually forward port 8000 (auto-forwarding isn't working on GitHub Codespaces). --- .devcontainer/devcontainer.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 485966efa..74bd3d41b 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -12,6 +12,9 @@ } }, "postCreateCommand": "pip install cryptography pymysql", + "forwardPorts": [ + 8000 + ], "customizations": { "vscode": { "extensions": [ From f2089eff90dc9ac63feb7a37bc1dd05e223d25a8 Mon Sep 17 00:00:00 2001 From: James Stout Date: Thu, 21 Dec 2023 23:00:40 +0000 Subject: [PATCH 03/16] Put OZtree_original into a shared volume for ease of access. --- README.markdown | 4 +--- docker-compose.yml | 5 +++++ web.Dockerfile | 6 +++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/README.markdown b/README.markdown index 3c36989c1..d78cf6735 100755 --- a/README.markdown +++ b/README.markdown @@ -16,10 +16,8 @@ If you are using Visual Studio Code, perform the following steps (you will need 1. Open the 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". -1. Once all scripts have finished running, you will need to make a couple one-time changes to your local source to sync your source with the web container. First, reopen the repository in your local directory. 1. Visit https://github.com/OneZoom/OZtree-docker/blob/main/appconfig.ini and copy the contents into `private/appconfig.ini`. -1. Open an integrated terminal and run the following: `docker exec $(docker ps -f name=onezoom-web --quiet) sh -c "cp /opt/web2py/applications/OZtree_original/databases/*.table /opt/web2py/applications/OZtree/databases"` -1. Reopen the project within your container. +1. Open an integrated terminal and run the following: `cp /opt/web2py/applications/OZtree_original/databases/*.table /opt/web2py/applications/OZtree/databases` 1. Open an integrated terminal and run `npm install && grunt dev`. 1. Visit http://localhost and the website should load! As noted earlier, you can also run your own server from the dev container by [running web2py.py directly](#starting-and-shutting-down-web2py). 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. diff --git a/docker-compose.yml b/docker-compose.yml index 55b8edc22..1191d1ee6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,6 +9,7 @@ services: 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 @@ -23,3 +24,7 @@ services: source: . target: /opt/web2py/applications/OZtree consistency: cached + - original-repo:/opt/web2py/applications/OZtree_original + +volumes: + original-repo: diff --git a/web.Dockerfile b/web.Dockerfile index 92079d77b..e6b5d84a1 100644 --- a/web.Dockerfile +++ b/web.Dockerfile @@ -5,4 +5,8 @@ FROM ${IMAGE_NAME} RUN groupmod --gid 1000 www-data \ && usermod --uid 1000 --gid 1000 www-data \ && chown -R 1000:1000 /opt/web2py/applications -RUN mv /opt/web2py/applications/OZtree /opt/web2py/applications/OZtree_original +# 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 From 371341b6d3438cd25f2b523227ea1365275f8bca Mon Sep 17 00:00:00 2001 From: James Stout Date: Mon, 25 Dec 2023 06:34:42 +0000 Subject: [PATCH 04/16] Improve Dev Container setup docs. --- README.markdown | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/README.markdown b/README.markdown index d78cf6735..1f514110c 100755 --- a/README.markdown +++ b/README.markdown @@ -13,14 +13,13 @@ If you are using Visual Studio Code, perform the following steps (you will need 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`. -1. Open the directory in VSCode. +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". -1. Visit https://github.com/OneZoom/OZtree-docker/blob/main/appconfig.ini and copy the contents into `private/appconfig.ini`. -1. Open an integrated terminal and run the following: `cp /opt/web2py/applications/OZtree_original/databases/*.table /opt/web2py/applications/OZtree/databases` -1. Open an integrated terminal and run `npm install && grunt dev`. -1. Visit http://localhost and the website should load! As noted earlier, you can also run your own server from the dev container by [running web2py.py directly](#starting-and-shutting-down-web2py). -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. +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/` +1. Run `npm install && grunt dev`. You will need to rerun `grunt dev` any time you make code changes. +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). +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. ## Installing locally From 09c7fb50ed4b61406bb564379bbc5c4a9acea5db Mon Sep 17 00:00:00 2001 From: James Stout Date: Mon, 25 Dec 2023 06:47:10 +0000 Subject: [PATCH 05/16] Add optional auth table step to the Dev Container installation. --- README.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/README.markdown b/README.markdown index 1f514110c..6218c76ce 100755 --- a/README.markdown +++ b/README.markdown @@ -20,6 +20,7 @@ If you are using Visual Studio Code, perform the following steps (you will need 1. Run `npm install && grunt dev`. You will need to rerun `grunt dev` any time you make code changes. 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). 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. +1. (Optional) [Create a manager account](#creating-auth-users--groups) in the auth table, e.g. so you can [view docs](#documentation). ## Installing locally From b321929c14c00653fff317ed96c37f6f387f4ce0 Mon Sep 17 00:00:00 2001 From: James Stout Date: Tue, 2 Jan 2024 22:26:20 +0000 Subject: [PATCH 06/16] Improve comments in devcontainer.json. --- .devcontainer/devcontainer.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 74bd3d41b..c1320aaaa 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,5 +1,4 @@ -// For format details, see https://aka.ms/devcontainer.json. For config options, see the -// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-docker-compose +// For format details, see https://aka.ms/devcontainer.json. { "name": "OZTree Dev", "dockerComposeFile": "../docker-compose.yml", @@ -11,8 +10,10 @@ "version": "3.8" } }, + // 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": { From ea88331ef8ac91bd673a6cfb134b8c0036aa1fed Mon Sep 17 00:00:00 2001 From: James Stout Date: Tue, 16 Jan 2024 01:44:36 +0000 Subject: [PATCH 07/16] Revert preferred_python3 (will apply this change separately). --- Gruntfile.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gruntfile.js b/Gruntfile.js index f985cb1aa..3c215beff 100755 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -5,7 +5,7 @@ const path = require('path'); partial_install_site = "http://www.onezoom.org"; partial_local_install_site = "http://127.0.0.1:8000"; // if you are running a local installation -preferred_python3 = "python3.8"; // in case you have multiple python3 versions installed +preferred_python3 = "python3.7"; // in case you have multiple python3 versions installed web2py_py = path.join(path.dirname(path.dirname(process.cwd())), 'web2py.py'); /** Generate a function to execute a web2py script, handing over all arguments */ From 58899c290c8def62859c9c3cd2feb2907da66a8b Mon Sep 17 00:00:00 2001 From: James Stout Date: Wed, 17 Jan 2024 06:40:25 +0000 Subject: [PATCH 08/16] Update to Python 3.10. --- .devcontainer/devcontainer.json | 2 +- dev.Dockerfile | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index c1320aaaa..cc982f0d1 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -7,7 +7,7 @@ // Features to add to the dev container. More info: https://containers.dev/features. "features": { "ghcr.io/devcontainers/features/python:1": { - "version": "3.8" + "version": "3.10" } }, // Need newer pymysql version or MySQL connection will fail. diff --git a/dev.Dockerfile b/dev.Dockerfile index d4ae16d48..b33660ccf 100644 --- a/dev.Dockerfile +++ b/dev.Dockerfile @@ -1,7 +1,7 @@ FROM mcr.microsoft.com/devcontainers/javascript-node:18 WORKDIR /opt -# Copied from https://github.com/OneZoom/OZtree-docker/blob/main/Dockerfile -RUN git clone --recursive https://github.com/web2py/web2py.git --depth 1 --branch v2.21.1 --single-branch web2py \ +# Recent version compatible with Python 3.10. +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/ # Required to avoid build issue when running grunt From f7727696646a18cfb0d588ba6ee137e92234e342 Mon Sep 17 00:00:00 2001 From: James Stout Date: Thu, 18 Jan 2024 06:37:52 +0000 Subject: [PATCH 09/16] Update comment to make it clear that the web2py versions should match across Dockerfiles. --- dev.Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev.Dockerfile b/dev.Dockerfile index b33660ccf..1ee54b07d 100644 --- a/dev.Dockerfile +++ b/dev.Dockerfile @@ -1,6 +1,6 @@ FROM mcr.microsoft.com/devcontainers/javascript-node:18 WORKDIR /opt -# Recent version compatible with Python 3.10. +# 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/ From 6e89e07e8c25fdd5850a8ff0e8a924f25d97125a Mon Sep 17 00:00:00 2001 From: James Stout Date: Sat, 20 Jan 2024 23:08:41 +0000 Subject: [PATCH 10/16] Publish devcontainer server on 8080 and improve documentation. --- README.markdown | 4 ++-- docker-compose.yml | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.markdown b/README.markdown index 6218c76ce..7f4bbb566 100755 --- a/README.markdown +++ b/README.markdown @@ -15,10 +15,10 @@ If you are using Visual Studio Code, perform the following steps (you will need 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`. 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". +1. Open the command palette and choose "Dev Containers: Reopen in Container". This may take several minutes to run. 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/` 1. Run `npm install && grunt dev`. You will need to rerun `grunt dev` any time you make code changes. -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). +1. Visit http://localhost:8080 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). 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. 1. (Optional) [Create a manager account](#creating-auth-users--groups) in the auth table, e.g. so you can [view docs](#documentation). diff --git a/docker-compose.yml b/docker-compose.yml index 1191d1ee6..c56acf21f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -25,6 +25,8 @@ services: target: /opt/web2py/applications/OZtree consistency: cached - original-repo:/opt/web2py/applications/OZtree_original + ports: + - "8080:80" volumes: original-repo: From 723b0c5a47c97790f88a0a0f603100047333633e Mon Sep 17 00:00:00 2001 From: James Stout Date: Sun, 21 Jan 2024 22:12:39 +0000 Subject: [PATCH 11/16] Map port 3306 to 3307 for local MySQL debugging. --- docker-compose.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/docker-compose.yml b/docker-compose.yml index c56acf21f..15707b245 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,6 +27,7 @@ services: - original-repo:/opt/web2py/applications/OZtree_original ports: - "8080:80" + - "3307:3306" volumes: original-repo: From d576f1b45e0e90322d0a93cd7a0fd430f8fe192b Mon Sep 17 00:00:00 2001 From: James Stout Date: Sun, 21 Jan 2024 22:14:59 +0000 Subject: [PATCH 12/16] Document port 3307. --- README.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/README.markdown b/README.markdown index 7f4bbb566..9e52acc9f 100755 --- a/README.markdown +++ b/README.markdown @@ -21,6 +21,7 @@ If you are using Visual Studio Code, perform the following steps (you will need 1. Visit http://localhost:8080 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). 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. 1. (Optional) [Create a manager account](#creating-auth-users--groups) in the auth table, e.g. so you can [view docs](#documentation). +1. (Optional) MySQL is available on port 3307 if you wish to debug using local tools outside the container. ## Installing locally From 5a1ac68e1761780747095d44b676f747aca66d5b Mon Sep 17 00:00:00 2001 From: James Stout Date: Tue, 6 Feb 2024 22:10:24 -0800 Subject: [PATCH 13/16] Improved dev container docs, updated to work with latest changes, moved files to .devcontainer. --- dev.Dockerfile => .devcontainer/dev.Dockerfile | 1 - .devcontainer/devcontainer.json | 4 +--- docker-compose.yml => .devcontainer/docker-compose.yml | 0 web.Dockerfile => .devcontainer/web.Dockerfile | 0 README.markdown | 4 ++-- 5 files changed, 3 insertions(+), 6 deletions(-) rename dev.Dockerfile => .devcontainer/dev.Dockerfile (86%) rename docker-compose.yml => .devcontainer/docker-compose.yml (100%) rename web.Dockerfile => .devcontainer/web.Dockerfile (100%) diff --git a/dev.Dockerfile b/.devcontainer/dev.Dockerfile similarity index 86% rename from dev.Dockerfile rename to .devcontainer/dev.Dockerfile index 1ee54b07d..4724919f7 100644 --- a/dev.Dockerfile +++ b/.devcontainer/dev.Dockerfile @@ -3,7 +3,6 @@ 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/ # 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 diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index cc982f0d1..483f8e646 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,7 +1,7 @@ // For format details, see https://aka.ms/devcontainer.json. { "name": "OZTree Dev", - "dockerComposeFile": "../docker-compose.yml", + "dockerComposeFile": "docker-compose.yml", "service": "dev", "workspaceFolder": "/opt/web2py/applications/OZtree", // Features to add to the dev container. More info: https://containers.dev/features. @@ -10,8 +10,6 @@ "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 diff --git a/docker-compose.yml b/.devcontainer/docker-compose.yml similarity index 100% rename from docker-compose.yml rename to .devcontainer/docker-compose.yml diff --git a/web.Dockerfile b/.devcontainer/web.Dockerfile similarity index 100% rename from web.Dockerfile rename to .devcontainer/web.Dockerfile diff --git a/README.markdown b/README.markdown index 9e52acc9f..b5172b276 100755 --- a/README.markdown +++ b/README.markdown @@ -16,8 +16,8 @@ If you are using Visual Studio Code, perform the following steps (you will need 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". This may take several minutes to run. -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/` -1. Run `npm install && grunt dev`. You will need to rerun `grunt dev` any time you make code changes. +1. Your repository is mounted at `/opt/web2py/applications/OZtree` and the original production docker container application is mounted at `cp /opt/web2py/applications/OZtree_original`. In order to sync your repository with the production database state, 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/` +1. Run `npm ci && grunt dev`. You will need to rerun `grunt dev` any time you make code changes. 1. Visit http://localhost:8080 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). 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. 1. (Optional) [Create a manager account](#creating-auth-users--groups) in the auth table, e.g. so you can [view docs](#documentation). From b9408623b4e1001a6251d7199db123bde7167ce9 Mon Sep 17 00:00:00 2001 From: James Stout Date: Wed, 7 Feb 2024 06:47:42 +0000 Subject: [PATCH 14/16] Update docker-compose.yml source paths. --- .devcontainer/docker-compose.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml index 15707b245..2c1a6e5dc 100644 --- a/.devcontainer/docker-compose.yml +++ b/.devcontainer/docker-compose.yml @@ -6,7 +6,7 @@ services: dockerfile: dev.Dockerfile volumes: - type: bind - source: . + source: .. target: /opt/web2py/applications/OZtree consistency: cached - original-repo:/opt/web2py/applications/OZtree_original:ro @@ -21,7 +21,7 @@ services: IMAGE_NAME: ${WEB_IMAGE_NAME} volumes: - type: bind - source: . + source: .. target: /opt/web2py/applications/OZtree consistency: cached - original-repo:/opt/web2py/applications/OZtree_original From ef4361e54f80e2ccf2558927ecca28dda9e69c10 Mon Sep 17 00:00:00 2001 From: James Stout Date: Sat, 10 Feb 2024 22:57:18 +0000 Subject: [PATCH 15/16] Improved container comments and docs. --- .devcontainer/web.Dockerfile | 4 +++- README.markdown | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.devcontainer/web.Dockerfile b/.devcontainer/web.Dockerfile index e6b5d84a1..9ae5dfab1 100644 --- a/.devcontainer/web.Dockerfile +++ b/.devcontainer/web.Dockerfile @@ -1,7 +1,9 @@ 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. +# 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 diff --git a/README.markdown b/README.markdown index 3adeeabf9..c62a23340 100755 --- a/README.markdown +++ b/README.markdown @@ -16,7 +16,7 @@ If you are using Visual Studio Code, perform the following steps (you will need 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`. 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. Create a `.env` file in the `.devcontainer` directory 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". This may take several minutes to run. 1. Your repository is mounted at `/opt/web2py/applications/OZtree` and the original production docker container application is mounted at `cp /opt/web2py/applications/OZtree_original`. In order to sync your repository with the production database state, 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/` 1. Run `npm ci && grunt dev`. You will need to rerun `grunt dev` any time you make code changes. From 4264008320656b093d63b9163cdb3911681fc524 Mon Sep 17 00:00:00 2001 From: James Stout Date: Sat, 10 Feb 2024 23:10:12 +0000 Subject: [PATCH 16/16] Don't suggest setting is_testing to False in dev container instructions. --- README.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.markdown b/README.markdown index c62a23340..3731c860a 100755 --- a/README.markdown +++ b/README.markdown @@ -21,7 +21,7 @@ If you are using Visual Studio Code, perform the following steps (you will need 1. Your repository is mounted at `/opt/web2py/applications/OZtree` and the original production docker container application is mounted at `cp /opt/web2py/applications/OZtree_original`. In order to sync your repository with the production database state, 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/` 1. Run `npm ci && grunt dev`. You will need to rerun `grunt dev` any time you make code changes. 1. Visit http://localhost:8080 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). -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. +1. (Optional) Once tables are created, and everything is working, you can set `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. 1. (Optional) [Create a manager account](#creating-auth-users--groups) in the auth table, e.g. so you can [view docs](#documentation). 1. (Optional) MySQL is available on port 3307 if you wish to debug using local tools outside the container.