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 ENV var to control DEV workdir mount to host #396

Merged
merged 5 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ BE_VERSION=v4
## Run SciCat services in DEV mode
# DEV=true

## In addition to DEV=true, it enables bidirectional synchronization between ${PWD}/bbackup/${APP} on the host and the dev volume
# DEV_BBACKUP=true

## Set the services HTTPS URL
# BACKEND_HTTPS_URL=https://backend-example.com
# FRONTEND_HTTPS_URL=https://frontend-example.com
1 change: 1 addition & 0 deletions .github/workflows/compose_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ jobs:
export OIDC_ENABLED=${{ matrix.OIDC_ENABLED }}
export BE_VERSION=${{ matrix.BE_VERSION }}
export DEV=${{ matrix.DEV }}
export DEV_BBACKUP=${DEV}
docker compose --profile '*' \
-f compose.yaml ${DEV:+-f .github/compose.dev.test.yaml} \
up --wait --wait-timeout 600
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ node_modules/
.ipynb_checkpoints/
*.ipynb
.ruff_cache/
bbackup/*
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ For example `docker compose --profile analysis` sets up a jupyter hub with some
| env | `OIDC_ENABLED` | `true`: oidc auth | `''` | * | Creates an OIDC identity provider and sets the BE to use it as authentication backend | |
| env | `DEV` | `true`: backend,frontend,searchapi,archivemock in DEV mode | `''` | * | The SciCat services' environment is prepared to ease the [development in a standardized environment](#dev-configuration) | |
| env | `<SERVICE>_HTTPS_URL` | `<URL>`: HTTPS termination | `''` | * | Requests the TLS certificate for the URL to LetsEncrypt through the [proxy](#tls-configuration) | |
| env | `DEV_BBACKUP` | `true`: bidirectional synchronization of DEV volume | `''` | * | Enables [DEV bidirectional synchronization](#dev-bidirectional-synchronization) between ${PWD}/bbackup/${APP} on the host and the dev volume | |


After optionally setting any configuration option, one can still select the services to run as described [here](#select-the-services).
Expand Down Expand Up @@ -189,6 +190,10 @@ To ease writing DEV configuration, a dev template is provided [here](./services/

The repo is checkout at that particular commit only if the docker volume does not yet exist.

##### DEV bidirectional synchronization

Setting `DEV_BBACKUP=true` in the [.env](./.env) file enables bidirectional synchronization between the DEV volume of each component (e.g. `frontend_dev`) and a directory on the host placed at `${PWD}/bbackup/${APP}` (e.g. `${PWD}/bbackup/${APP}`). This is sometimes convenient both to have a backup of the volume and to enable the use of additional tools installed on the host, which require file access.

</details>

#### TLS configuration
Expand Down
10 changes: 10 additions & 0 deletions entrypoints/bidirectional_backup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

apk add --no-cache unison

[ -z "$(ls -A /bbackup)" ] && cp -r "${WORKDIR}"/. /bbackup

flock -n /bbackup/.unison \
unison "${WORKDIR}" /bbackup \
-repeat watch -batch -auto \
-prefer /bbackup &
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
service: web-app
labels: !reset null
volumes:
- archivemock_dev:/job_mock
- ${DEV_BBACKUP:+${PWD}/bbackup/${COMPOSE_PROJECT_NAME}/archivemock:}/bbackup

volumes:
archivemock_dev:
Expand Down
3 changes: 3 additions & 0 deletions services/compose.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@
# These volumes allow to run init scripts before running the service
- ${PWD}/entrypoints/loop_entrypoints.sh:/usr/local/bin/loop_entrypoints.sh
- ${PWD}/entrypoints/infinite_loop.sh:/usr/local/bin/infinite_loop.sh
- ${PWD}/entrypoints/bidirectional_backup.sh:/docker-entrypoints/${DEV_BBACKUP:+1}00.sh
- ${PWD}/entrypoints/chown_root.sh:/docker-entrypoints/00.sh
- ${PWD}/entrypoints/setup_git.sh:/docker-entrypoints/01.sh
environment:
GITHUB_REPO: ${GITHUB_REPO:-}
WORKDIR: ${WORKDIR:-/home/node/app}
user: root
restart: no

Check warning on line 21 in services/compose.dev.yaml

View workflow job for this annotation

GitHub Actions / yaml-lint

21:14 [truthy] truthy value should be one of [false, true]
node-app-from-local:
extends: web-app
volumes:
# This prevents git unpushed changes from being lost on container restart
- ${DEV_VOLUME:-${APP}}_dev:${WORKDIR:-/home/node/app}
- ${DEV_BBACKUP:+${PWD}/bbackup/${COMPOSE_PROJECT_NAME}/${DEV_VOLUME:-${APP}}:}/bbackup
# These allow to keep changes from npm install/build from Dockerfile CMDs
- ${WORKDIR:-/home/node/app}/dist
- ${WORKDIR:-/home/node/app}/node_modules
Expand Down
Loading