From 2bfd51141968ad4dda911aa6442042f494b0d3dc Mon Sep 17 00:00:00 2001 From: f-PLT Date: Mon, 5 May 2025 16:15:20 -0400 Subject: [PATCH 01/14] Add compose override for backend development This starts the UI in pre-production build mode, which makes the frontend much quicker to load between compose restarts --- README.md | 34 ++++++++++++++++--------- docker-compose-backend-dev.override.yml | 3 +++ 2 files changed, 25 insertions(+), 12 deletions(-) create mode 100644 docker-compose-backend-dev.override.yml diff --git a/README.md b/README.md index 2fe4e84de..c52c094ff 100644 --- a/README.md +++ b/README.md @@ -16,23 +16,33 @@ Antenna uses [Docker](https://docs.docker.com/get-docker/) & [Docker Compose](ht 127.0.0.1 minio 127.0.0.1 django ``` - -2) The following commands will build all services, run them in the background, and then stream the logs. - -```sh - docker compose up -d - docker compose logs -f django celeryworker ui - # Ctrl+c to close the logs -``` - -3) Optionally, run additional ML processing services: `processing_services` defines ML backends which wrap detections in our FastAPI response schema. The `example` app demos how to add new pipelines, algorithms, and models. See the detailed instructions in `processing_services/README.md`. +3) The following commands will build all services, run them in the background, and then stream the logs. + 1) Standard development + ```sh + docker compose up -d + docker compose logs -f django celeryworker ui + # Ctrl+c to close the logs + ``` + 2) Backend only: will use a pre-built version of the frontend that will not have hot-reloading enabled, but makes startup time faster when restarting the stack. + ```sh + # Build the frontend (only needed the first time starting the stack, or if the frontend changed since your last build) + (cd ui && yarn build) + ``` + ```sh + # Run docker compose with the override config + docker compose -f docker-compose.yml -f docker-compose-backend-dev.override.yml up -d + ``` + If there's a need to update the frontend while using this override, simply re-build the frontend with the `(cd ui && yarn build)` after modifying the frontend code. + + +4) Optionally, run additional ML processing services: `processing_services` defines ML backends which wrap detections in our FastAPI response schema. The `example` app demos how to add new pipelines, algorithms, and models. See the detailed instructions in `processing_services/README.md`. ``` docker compose -f processing_services/example/docker-compose.yml up -d # Once running, in Antenna register a new processing service called: http://ml_backend_example:2000 ``` -4) Access the platform the following URLs: +5) Access the platform the following URLs: - Primary web interface: http://localhost:4000 - API browser: http://localhost:8000/api/v2/ @@ -44,7 +54,7 @@ A default user will be created with the following credentials. Use these to log - Email: `antenna@insectai.org` - Password: `localadmin` -5) Stop all services with: +6) Stop all services with: $ docker compose down diff --git a/docker-compose-backend-dev.override.yml b/docker-compose-backend-dev.override.yml new file mode 100644 index 000000000..3364fcfdd --- /dev/null +++ b/docker-compose-backend-dev.override.yml @@ -0,0 +1,3 @@ +services: + ui: + entrypoint: ["sh", "-c", "yarn preview --debug --host 0.0.0.0 --port 4000"] From 84f1a1e79f7f6cad24b00e479585384909101642 Mon Sep 17 00:00:00 2001 From: f-PLT Date: Mon, 5 May 2025 16:35:29 -0400 Subject: [PATCH 02/14] Add comment to `docker-compose-backend-dev.override.yml` --- docker-compose-backend-dev.override.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docker-compose-backend-dev.override.yml b/docker-compose-backend-dev.override.yml index 3364fcfdd..0c0a2c71d 100644 --- a/docker-compose-backend-dev.override.yml +++ b/docker-compose-backend-dev.override.yml @@ -1,3 +1,5 @@ +# This docker compose configuration should only be used to override the development compose file, docker-compose.yml + services: ui: entrypoint: ["sh", "-c", "yarn preview --debug --host 0.0.0.0 --port 4000"] From 1141055f181a6d34fc9b61a08e94e8821dacc5ce Mon Sep 17 00:00:00 2001 From: f-PLT Date: Mon, 5 May 2025 16:37:19 -0400 Subject: [PATCH 03/14] Update wording in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c52c094ff..828de8ace 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Antenna uses [Docker](https://docs.docker.com/get-docker/) & [Docker Compose](ht docker compose logs -f django celeryworker ui # Ctrl+c to close the logs ``` - 2) Backend only: will use a pre-built version of the frontend that will not have hot-reloading enabled, but makes startup time faster when restarting the stack. + 2) Backend only: will use a pre-built version of the frontend that will not have hot-reloading enabled, but will make startup time faster when restarting the stack. ```sh # Build the frontend (only needed the first time starting the stack, or if the frontend changed since your last build) (cd ui && yarn build) From 155cf71e2ad14de780ad2c0b3790d22482e46c8c Mon Sep 17 00:00:00 2001 From: f-PLT Date: Tue, 6 May 2025 16:47:43 -0400 Subject: [PATCH 04/14] Remove docs service from local dev compose --- docker-compose.yml | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 09ec5eba2..fc01fffd7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -66,21 +66,6 @@ services: - CHOKIDAR_USEPOLLING=true - API_PROXY_TARGET=http://django:8000 - docs: - image: ami_local_docs - build: - context: . - dockerfile: ./compose/local/docs/Dockerfile - env_file: - - ./.envs/.local/.django - volumes: - - ./docs:/docs:z - - ./config:/app/config:z - - ./ami:/app/ami:z - ports: - - "9025:9000" - command: /start-docs - redis: image: redis:6 container_name: ami_local_redis From 9bd8327ae00cd1e626b6626f1bb86b461a48fb7c Mon Sep 17 00:00:00 2001 From: f-PLT Date: Tue, 6 May 2025 17:22:42 -0400 Subject: [PATCH 05/14] Switch the default entrypoints for the UI service in local dev compose --- README.md | 18 ++++++++++++------ compose/local/ui/Dockerfile | 2 +- ...=> docker-compose-frontend-dev.override.yml | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) rename docker-compose-backend-dev.override.yml => docker-compose-frontend-dev.override.yml (58%) diff --git a/README.md b/README.md index 828de8ace..e001889ff 100644 --- a/README.md +++ b/README.md @@ -17,23 +17,29 @@ Antenna uses [Docker](https://docs.docker.com/get-docker/) & [Docker Compose](ht 127.0.0.1 django ``` 3) The following commands will build all services, run them in the background, and then stream the logs. - 1) Standard development + 1) Standard development: will use a pre-built version of the frontend that will not have hot-reloading enabled, but will make startup time faster when restarting the stack. ```sh + # Build the frontend (only needed the first time starting the stack and after modification to the frontend component) + (cd ui && yarn install && yarn build) + ``` + ```sh + # Start the whole compose stack docker compose up -d + + # To stream the logs docker compose logs -f django celeryworker ui # Ctrl+c to close the logs ``` - 2) Backend only: will use a pre-built version of the frontend that will not have hot-reloading enabled, but will make startup time faster when restarting the stack. + If there's a need to update the frontend while using this override, simply re-build the frontend to load the new changes. ```sh - # Build the frontend (only needed the first time starting the stack, or if the frontend changed since your last build) (cd ui && yarn build) ``` + + 2) With Hot Reload UI: Hot reload is enabled for frontend development, but the primary web interface will be slow to load at startup and later restarts. ```sh # Run docker compose with the override config - docker compose -f docker-compose.yml -f docker-compose-backend-dev.override.yml up -d + docker compose -f docker-compose.yml -f docker-compose-frontend-dev.override.yml up -d ``` - If there's a need to update the frontend while using this override, simply re-build the frontend with the `(cd ui && yarn build)` after modifying the frontend code. - 4) Optionally, run additional ML processing services: `processing_services` defines ML backends which wrap detections in our FastAPI response schema. The `example` app demos how to add new pipelines, algorithms, and models. See the detailed instructions in `processing_services/README.md`. diff --git a/compose/local/ui/Dockerfile b/compose/local/ui/Dockerfile index f3493dd60..d5a41ac4f 100644 --- a/compose/local/ui/Dockerfile +++ b/compose/local/ui/Dockerfile @@ -14,4 +14,4 @@ ENV BROWSER=none EXPOSE 4000 # Check for changed app dependencies on every start -CMD ["sh", "-c", "yarn install && yarn start --debug --host 0.0.0.0 --port 4000"] +CMD ["sh", "-c", "yarn preview --debug --host 0.0.0.0 --port 4000"] diff --git a/docker-compose-backend-dev.override.yml b/docker-compose-frontend-dev.override.yml similarity index 58% rename from docker-compose-backend-dev.override.yml rename to docker-compose-frontend-dev.override.yml index 0c0a2c71d..7170feff5 100644 --- a/docker-compose-backend-dev.override.yml +++ b/docker-compose-frontend-dev.override.yml @@ -2,4 +2,4 @@ services: ui: - entrypoint: ["sh", "-c", "yarn preview --debug --host 0.0.0.0 --port 4000"] + entrypoint: ["sh", "-c", "yarn install && yarn start --debug --host 0.0.0.0 --port 4000"] From bd5060e2030d7cd2beb3a0a52a247f6bb0d0bb8b Mon Sep 17 00:00:00 2001 From: f-PLT Date: Wed, 7 May 2025 08:17:12 -0400 Subject: [PATCH 06/14] Add dockerignore to UI so local node module and build files are ignored --- ui/.dockerignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 ui/.dockerignore diff --git a/ui/.dockerignore b/ui/.dockerignore new file mode 100644 index 000000000..3e2e84b08 --- /dev/null +++ b/ui/.dockerignore @@ -0,0 +1,2 @@ +build/ +node_modules/ From 698c12a72c3dc2a6b1f1eba640f97bc92f3c99b7 Mon Sep 17 00:00:00 2001 From: f-PLT Date: Wed, 7 May 2025 09:10:54 -0400 Subject: [PATCH 07/14] Add try catch to vite.config for commitHash --- ui/vite.config.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/ui/vite.config.ts b/ui/vite.config.ts index d15cf415e..0133e0513 100644 --- a/ui/vite.config.ts +++ b/ui/vite.config.ts @@ -5,9 +5,15 @@ import eslint from 'vite-plugin-eslint' import svgr from 'vite-plugin-svgr' import viteTsconfigPaths from 'vite-tsconfig-paths' -const commitHash = childProcess - .execSync('git rev-parse --short HEAD') - .toString() +let commitHash: string + +try { + commitHash = childProcess + .execSync('git rev-parse --short HEAD') + .toString() +} catch (err) { + commitHash = 'Local docker image - please ensure this is latest version' +} export default defineConfig(({ mode }) => { // Load env file based on `mode` in the current working directory. From 6a84c04e03041829f8a4278f0a4062524efb2c66 Mon Sep 17 00:00:00 2001 From: f-PLT Date: Wed, 7 May 2025 09:11:29 -0400 Subject: [PATCH 08/14] Make base UI Docker image self-sufficient --- compose/local/ui/Dockerfile | 9 ++++++++- docker-compose-frontend-dev.override.yml | 4 ++++ docker-compose.yml | 4 ---- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/compose/local/ui/Dockerfile b/compose/local/ui/Dockerfile index d5a41ac4f..47b1287a2 100644 --- a/compose/local/ui/Dockerfile +++ b/compose/local/ui/Dockerfile @@ -4,14 +4,21 @@ FROM node:18 # Set the working directory in the container WORKDIR /app +COPY ./ /app + # Configure git to trust the /app directory +# Not necessary for default, but needed for frontend compose override to have proper +# build number RUN git config --global --add safe.directory /app # Don't try to open a browser ENV BROWSER=none +# Build the ui +RUN yarn install \ + && yarn build + # Expose the port the app runs on EXPOSE 4000 -# Check for changed app dependencies on every start CMD ["sh", "-c", "yarn preview --debug --host 0.0.0.0 --port 4000"] diff --git a/docker-compose-frontend-dev.override.yml b/docker-compose-frontend-dev.override.yml index 7170feff5..95a144630 100644 --- a/docker-compose-frontend-dev.override.yml +++ b/docker-compose-frontend-dev.override.yml @@ -2,4 +2,8 @@ services: ui: + volumes: + - ./.git:/app/.git:ro + - ./ui:/app + - node_modules:/app/node_modules entrypoint: ["sh", "-c", "yarn install && yarn start --debug --host 0.0.0.0 --port 4000"] diff --git a/docker-compose.yml b/docker-compose.yml index fc01fffd7..d6995c3dc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -56,10 +56,6 @@ services: dockerfile: ../compose/local/ui/Dockerfile ports: - "4000:4000" - volumes: - - ./.git:/app/.git:ro - - ./ui:/app - - node_modules:/app/node_modules depends_on: - django environment: From 54d1a4320bffcbfd6d4185a7f62b7472c411a7b9 Mon Sep 17 00:00:00 2001 From: f-PLT Date: Wed, 7 May 2025 09:48:05 -0400 Subject: [PATCH 09/14] Remove node_modules from volumes, as not really necessary and prone to minor problems --- docker-compose-frontend-dev.override.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/docker-compose-frontend-dev.override.yml b/docker-compose-frontend-dev.override.yml index 95a144630..defd03a72 100644 --- a/docker-compose-frontend-dev.override.yml +++ b/docker-compose-frontend-dev.override.yml @@ -5,5 +5,4 @@ services: volumes: - ./.git:/app/.git:ro - ./ui:/app - - node_modules:/app/node_modules entrypoint: ["sh", "-c", "yarn install && yarn start --debug --host 0.0.0.0 --port 4000"] From 9274bc464b3a48c2ca64cb260c91b0bde9a6d7ed Mon Sep 17 00:00:00 2001 From: f-PLT Date: Wed, 7 May 2025 09:48:59 -0400 Subject: [PATCH 10/14] Update README.md --- README.md | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index e001889ff..32d003c7c 100644 --- a/README.md +++ b/README.md @@ -18,10 +18,6 @@ Antenna uses [Docker](https://docs.docker.com/get-docker/) & [Docker Compose](ht ``` 3) The following commands will build all services, run them in the background, and then stream the logs. 1) Standard development: will use a pre-built version of the frontend that will not have hot-reloading enabled, but will make startup time faster when restarting the stack. - ```sh - # Build the frontend (only needed the first time starting the stack and after modification to the frontend component) - (cd ui && yarn install && yarn build) - ``` ```sh # Start the whole compose stack docker compose up -d @@ -30,9 +26,10 @@ Antenna uses [Docker](https://docs.docker.com/get-docker/) & [Docker Compose](ht docker compose logs -f django celeryworker ui # Ctrl+c to close the logs ``` - If there's a need to update the frontend while using this override, simply re-build the frontend to load the new changes. + If there's a need to update the frontend while the compose stack is running, use the following command to rebuild the frontend and load the new changes + (and remember to refresh your browser after!). ```sh - (cd ui && yarn build) + docker compose stop ui && docker compose build ui && docker compose up ui -d ``` 2) With Hot Reload UI: Hot reload is enabled for frontend development, but the primary web interface will be slow to load at startup and later restarts. From 8e3450ce3e2639ee11ff3302722e435e35728a04 Mon Sep 17 00:00:00 2001 From: f-PLT Date: Wed, 7 May 2025 13:52:32 -0400 Subject: [PATCH 11/14] Update the README.md --- README.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 32d003c7c..1a9b4ece7 100644 --- a/README.md +++ b/README.md @@ -26,17 +26,21 @@ Antenna uses [Docker](https://docs.docker.com/get-docker/) & [Docker Compose](ht docker compose logs -f django celeryworker ui # Ctrl+c to close the logs ``` - If there's a need to update the frontend while the compose stack is running, use the following command to rebuild the frontend and load the new changes + To update the UI Docker container, use the following command to rebuild the frontend and load the new changes (and remember to refresh your browser after!). ```sh docker compose stop ui && docker compose build ui && docker compose up ui -d ``` - 2) With Hot Reload UI: Hot reload is enabled for frontend development, but the primary web interface will be slow to load at startup and later restarts. + 2) With Hot Reload UI**: Hot reload is enabled for frontend development, but the primary web interface will be slow to load at startup and later restarts. ```sh # Run docker compose with the override config docker compose -f docker-compose.yml -f docker-compose-frontend-dev.override.yml up -d ``` + _**Do note that this will create a `ui/node_modules` folder if one does not exist yet. This folder is created by the mounting of the `/ui` folder + in the [docker-compose-frontend-dev.override.yml](docker-compose-frontend-dev.override.yml), and is written by a `root` user. + It will need to be removed, or you will need to modify its access permissions with the `chown` command if you later want to work on the frontend using the [instructions here](#frontend)._ + 4) Optionally, run additional ML processing services: `processing_services` defines ML backends which wrap detections in our FastAPI response schema. The `example` app demos how to add new pipelines, algorithms, and models. See the detailed instructions in `processing_services/README.md`. From 0b40394b8a0d9bfcd1cb96e6e1bc3cd7469ae8ec Mon Sep 17 00:00:00 2001 From: f-PLT Date: Wed, 7 May 2025 14:24:54 -0400 Subject: [PATCH 12/14] Modify vit.config.ts --- ui/vite.config.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/ui/vite.config.ts b/ui/vite.config.ts index 0133e0513..7c2871855 100644 --- a/ui/vite.config.ts +++ b/ui/vite.config.ts @@ -5,16 +5,19 @@ import eslint from 'vite-plugin-eslint' import svgr from 'vite-plugin-svgr' import viteTsconfigPaths from 'vite-tsconfig-paths' -let commitHash: string - +let temporaryCommitHash: string try { - commitHash = childProcess + temporaryCommitHash = childProcess .execSync('git rev-parse --short HEAD') .toString() -} catch (err) { - commitHash = 'Local docker image - please ensure this is latest version' +} catch (error) { + console.warn('Could not get git commit hash:', error) + temporaryCommitHash = '- Local docker image: please ensure this is latest version -' } +const commitHash = temporaryCommitHash + + export default defineConfig(({ mode }) => { // Load env file based on `mode` in the current working directory. // Set the third parameter to '' to load all env regardless of the `VITE_` prefix. From 3e2d374518dd0fedc40fd837aa09518edd53937a Mon Sep 17 00:00:00 2001 From: f-PLT Date: Wed, 7 May 2025 14:38:34 -0400 Subject: [PATCH 13/14] Fix typo in vit.config.ts --- ui/vite.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/vite.config.ts b/ui/vite.config.ts index 7c2871855..d65ecd750 100644 --- a/ui/vite.config.ts +++ b/ui/vite.config.ts @@ -12,7 +12,7 @@ try { .toString() } catch (error) { console.warn('Could not get git commit hash:', error) - temporaryCommitHash = '- Local docker image: please ensure this is latest version -' + temporaryCommitHash = '- Local docker image: please ensure this is the latest version -' } const commitHash = temporaryCommitHash From 8b6331e899c0ff6dc8711a165f2f18b93adb5d70 Mon Sep 17 00:00:00 2001 From: f-PLT Date: Tue, 9 Sep 2025 15:36:14 -0400 Subject: [PATCH 14/14] Fix sentence structure --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d36705750..d397cb502 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Antenna uses [Docker](https://docs.docker.com/get-docker/) & [Docker Compose](ht 127.0.0.1 django ``` 3) The following commands will build all services, run them in the background, and then stream the logs. - 1) Standard development: will use a pre-built version of the frontend that will not have hot-reloading enabled, but will make startup time faster when restarting the stack. + 1) Standard development: will use a pre-built version of the frontend that will not have hot-reloading enabled. However, it will make startup time faster when restarting the stack. ```sh # Start the whole compose stack docker compose up -d