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 21, 2024
1 parent 29ffc0c commit 3b1ab1b
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 18 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
31 changes: 13 additions & 18 deletions entrypoints/setup_git.sh
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
#!/bin/sh

apk update && apk add git

git remote || INIT=true
[ -e ".finished" ] && return 0

apk update && apk add git
echo "${GITHUB_REPO}" | grep -q "#" && TAG="${GITHUB_REPO#*#}" || TAG=

if [ "${INIT}" ]
git init
chown -R "$(find . -maxdepth 1 -exec ls -ld {} + | awk '{print $3":"$4}' | tail -n1)" .git
git config --global --add safe.directory "${PWD}"
REPO="${GITHUB_REPO%%#*}"
git remote add origin "${REPO}"
git fetch
DEFAULT_BRANCH=$(git remote show origin | sed -n '/HEAD branch/s/.*: //p')
git reset --hard origin/"${DEFAULT_BRANCH}"
git clean -fd
if [ -n "${TAG}" ]
then
git init
chown -R "$(find . -maxdepth 1 -exec ls -ld {} + | awk '{print $3":"$4}' | tail -n1)" .git
git config --global --add safe.directory "${PWD}"
REPO="${GITHUB_REPO%%#*}"
git remote add origin "${REPO}"
git fetch
DEFAULT_BRANCH=$(git remote show origin | sed -n '/HEAD branch/s/.*: //p')
git reset --hard origin/"${DEFAULT_BRANCH}"
git clean -fd
if [ -n "${TAG}" ]
then
git checkout "${TAG}"
fi
git checkout "${TAG}"
fi
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 3b1ab1b

Please sign in to comment.