From 8d15bba54b38baaba3f9d4e7f8d3f1857dba48ee Mon Sep 17 00:00:00 2001 From: minottic Date: Thu, 21 Nov 2024 12:08:31 +0100 Subject: [PATCH] Run entrypoint in DEV only on first creation --- README.md | 2 ++ entrypoints/add_chrome.sh | 2 ++ entrypoints/infinite_loop.sh | 2 ++ entrypoints/merge_json.sh | 2 ++ entrypoints/npm_ci.sh | 2 ++ entrypoints/setup_git.sh | 2 ++ services/backend/services/v3/entrypoints/merge_json.sh | 2 ++ services/backend/services/v4/entrypoints/db_migration.sh | 2 ++ 8 files changed, 16 insertions(+) diff --git a/README.md b/README.md index 5c9dffa9..aae5f0ef 100644 --- a/README.md +++ b/README.md @@ -175,6 +175,8 @@ docker compose -f compose.yaml -f .github/compose.dev.test.yaml ... It is very convenient if using [VSCode](https://code.visualstudio.com/docs/devcontainers/attach-container), as, after the docker services are running, one can attach to it and start developing using all VSCode features, including version control and debugging. +Please note that [entrypoints](#entrypoints) when `DEV=true` are only run when the component's container is created for the first time. This is done to avoid clashes with local changes. + To ease writing DEV configuration, a dev template is provided [here](./services/compose.dev.yaml) and each component inhearits from it, as you can see [here](./services/frontend/compose.dev.yaml) setting the componenent specific variables from the relative [.env file](./services/frontend/.env). :warning: Docker compose applies a [precedence mechanism](https://docs.docker.com/compose/how-tos/environment-variables/variable-interpolation/#local-env-file-versus-project-directory-env-file) whenever the same variable is defined in `.env` files in nested folders, with precedence to the folder where the default `COMPOSE_FILE` lives. This means that the current template cannot be used in case of nested components, at least for the parts where local variables are used. There is no conflict with variables defined multiple times in `.env` files at the same level. :warning: To prevent git unpushed changes from being lost when a container is restarted, the work folder of each service, when in DEV mode, is mounted to a docker volume, with naming convention `${COMPOSE_PROJECT_NAME}__dev`. Make sure, to commit and push frequently, especially before removing docker volumes to push the relevant changes. diff --git a/entrypoints/add_chrome.sh b/entrypoints/add_chrome.sh index 94a08dff..1d6d32a6 100644 --- a/entrypoints/add_chrome.sh +++ b/entrypoints/add_chrome.sh @@ -1,3 +1,5 @@ #!/bin/sh +[ -e ".finished" ] && return 0 + apk update && apk add chromium diff --git a/entrypoints/infinite_loop.sh b/entrypoints/infinite_loop.sh index b137461f..9f65a3b6 100755 --- a/entrypoints/infinite_loop.sh +++ b/entrypoints/infinite_loop.sh @@ -1,3 +1,5 @@ #!/bin/sh +touch .finished + while true; do sleep 600; done diff --git a/entrypoints/merge_json.sh b/entrypoints/merge_json.sh index cf284a62..61e8313f 100755 --- a/entrypoints/merge_json.sh +++ b/entrypoints/merge_json.sh @@ -1,5 +1,7 @@ #!/bin/sh +[ -e ".finished" ] && return 0 + apk update && apk add jq gettext jq -s 'reduce .[] as $item ({}; . * $item)' /config/*.json | envsubst \ diff --git a/entrypoints/npm_ci.sh b/entrypoints/npm_ci.sh index ca6f97b6..251b8c31 100644 --- a/entrypoints/npm_ci.sh +++ b/entrypoints/npm_ci.sh @@ -1,3 +1,5 @@ #!/bin/sh +[ -e ".finished" ] && return 0 + npm ci diff --git a/entrypoints/setup_git.sh b/entrypoints/setup_git.sh index f5d4985c..6b6ddac3 100755 --- a/entrypoints/setup_git.sh +++ b/entrypoints/setup_git.sh @@ -1,5 +1,7 @@ #!/bin/sh +[ -e ".finished" ] && return 0 + apk update && apk add git git remote || INIT=true diff --git a/services/backend/services/v3/entrypoints/merge_json.sh b/services/backend/services/v3/entrypoints/merge_json.sh index e146bf84..d648cbdf 100755 --- a/services/backend/services/v3/entrypoints/merge_json.sh +++ b/services/backend/services/v3/entrypoints/merge_json.sh @@ -1,5 +1,7 @@ #!/bin/sh +[ -e ".finished" ] && return 0 + for config in $(find /config -maxdepth 1 -type f -exec basename {} \; | cut -d '.' -f 1 | sort -u) do # shellcheck disable=SC2016 diff --git a/services/backend/services/v4/entrypoints/db_migration.sh b/services/backend/services/v4/entrypoints/db_migration.sh index 5182ec80..07912233 100755 --- a/services/backend/services/v4/entrypoints/db_migration.sh +++ b/services/backend/services/v4/entrypoints/db_migration.sh @@ -1,5 +1,7 @@ #!/bin/sh +[ -e ".finished" ] && return 0 + echo "MONGODB_URI=$MONGODB_URI" >.env npm run migrate:db:up rm .env