diff --git a/.env b/.env index 92155b9c..60a020ec 100644 --- a/.env +++ b/.env @@ -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 diff --git a/.github/workflows/compose_test.yaml b/.github/workflows/compose_test.yaml index bf9607c2..2eda34a4 100644 --- a/.github/workflows/compose_test.yaml +++ b/.github/workflows/compose_test.yaml @@ -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 diff --git a/.gitignore b/.gitignore index b7f1af7f..ab047ab4 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ node_modules/ .ipynb_checkpoints/ *.ipynb .ruff_cache/ +bbackup/* diff --git a/README.md b/README.md index aae5f0ef..5a5566fa 100644 --- a/README.md +++ b/README.md @@ -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 | `_HTTPS_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). @@ -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. + #### TLS configuration diff --git a/entrypoints/bidirectional_backup.sh b/entrypoints/bidirectional_backup.sh new file mode 100755 index 00000000..0abda663 --- /dev/null +++ b/entrypoints/bidirectional_backup.sh @@ -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 & diff --git a/services/backend/services/v3/services/archivemock/compose.dev.yaml b/services/backend/services/v3/services/archivemock/compose.dev.yaml index 730bfe6e..d497fa97 100644 --- a/services/backend/services/v3/services/archivemock/compose.dev.yaml +++ b/services/backend/services/v3/services/archivemock/compose.dev.yaml @@ -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: diff --git a/services/compose.dev.yaml b/services/compose.dev.yaml index e377256b..66880457 100644 --- a/services/compose.dev.yaml +++ b/services/compose.dev.yaml @@ -11,10 +11,12 @@ services: # 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 node-app-from-local: @@ -22,6 +24,7 @@ services: 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