Skip to content

Commit

Permalink
Run entrypoint in DEV only on first creation
Browse files Browse the repository at this point in the history
  • Loading branch information
minottic committed Nov 26, 2024
1 parent 72102fa commit 3465ed7
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}_<service>_dev`. Make sure, to commit and push frequently, especially before removing docker volumes to push the relevant changes.
Expand Down
2 changes: 2 additions & 0 deletions entrypoints/add_chrome.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/sh

[ -e ".finished" ] && return 0

apk update && apk add chromium
2 changes: 2 additions & 0 deletions entrypoints/infinite_loop.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/sh

touch .finished

while true; do sleep 600; done
2 changes: 2 additions & 0 deletions entrypoints/merge_json.sh
Original file line number Diff line number Diff line change
@@ -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 \
Expand Down
2 changes: 2 additions & 0 deletions entrypoints/npm_ci.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/sh

[ -e ".finished" ] && return 0

npm ci
2 changes: 2 additions & 0 deletions entrypoints/setup_git.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/sh

[ -e ".finished" ] && return 0

apk update && apk add git

git remote || INIT=true
Expand Down
2 changes: 2 additions & 0 deletions services/backend/services/v3/entrypoints/merge_json.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions services/backend/services/v4/entrypoints/db_migration.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/sh

[ -e ".finished" ] && return 0

echo "MONGODB_URI=$MONGODB_URI" >.env
npm run migrate:db:up
rm .env

0 comments on commit 3465ed7

Please sign in to comment.