Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.
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
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@
"start:dev:ND": "node app/main.js",
"start:dev:local": "(export RCT_DB_HOST=${RCT_DB_HOST:-localhost}; bash -c 'set -o allexport && ls && source ./docker/dev.env && set +o allexport && npm run start:dev')",
"deploy:db:local": "./database/setup-db.sh --env ./docker/dev.env",
"dev": "./rctmake prune,run,app:attach,stop --target dev",
"dev": "./rctmake rm,run,app:attach,stop --target dev",
"idev": "node -e \"app = require('./app/application.js'); const { databaseManager: dbm, syncManager: scm } = app\" -i",
"node-dev-env": "(export RCT_DB_HOST=$(docker inspect o2rct_database-dev -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'); bash -c 'set -o allexport && ls && source ./docker/dev.env && set +o allexport && node')",
"test": "./rctmake prune,run --target test",
"prune": "./rctmake prune",
"test": "./rctmake rm,run --target test",
"rm": "./rctmake rm",
"app:attach": "./rctmake app:attach",
"app:battach": "./rctmake app:battach",
"db:check": "./rctmake prune,run,follow -t dev -S o2rct_database-dev ",
"db:check": "./rctmake rm,run,follow -t dev -S o2rct_database-dev ",
"db:attach": "./rctmake db:attach",
"db:battach": "./rctmake db:battach",
"db:clean": "./rctmake db:clean",
Expand Down
49 changes: 36 additions & 13 deletions rctmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ SCRIPT_NAME="$(basename $0)"

DEV_MODE=dev
TEST_MODE=test
APP_CONTAINER_NAME_BASE="o2rct_application"
O2RCT_ID=o2rct
APP_CONTAINER_NAME_BASE="$O2RCT_ID""_application"
APP_CONTAINERS_OPT="$APP_CONTAINER_NAME_BASE-([$DEV_MODE|$TEST_MODE])"
APP_WORKINGDIR='/opt/RunConditionTable'

DB_CONTAINER_NAME_BASE="o2rct_database"
DB_CONTAINER_NAME_BASE="$O2RCT_ID""_database"
DP_CONTAINERS_OPT="$DB_CONTAINER_NAME-($DEV_MODE|$TEST_MODE))"
DB_WORKINGDIR='/postgres/run'

Expand Down Expand Up @@ -56,12 +57,14 @@ Usage:
STAGE can be a:
1. run|run[RUN_SUBSTATGES] - run application (deploys containers). By defualt
run stage behaves as docker-compose ... up --build.
RUN_SUBSTATGES are colon separated docker-compose tasks like run,create,up,...
RUN_SUBSTATGES are / (slash) separated docker-compose tasks like create,up,...
e.g.: ./$SCRIPT_NAME run -t dev
./$SCRIPT_NAME run[create/up] -t test
./$SCRIPT_NAME run[up] -t test

2. stop - stop containers
3. prune - delete containers, all virtual volumens and virtual network

3. rm - delete containers, all virtual volumens and virtual network
4. follow - like docker-compose follow
5. logs - like docker-compose logs

Expand All @@ -86,8 +89,12 @@ Usage:
19. dump:(export|ex) -A|--archive-name <FILE> - export cached dump to tar.gz archive specified by the flag
20. dump:(import|im) -A|--archive-name <FILE> - import dumps from tar.gz archvie specified by the flag ito cache

21. prune - remove everything related to RCT and dockers


Other options:
-S|--service <SERVICE> - flag can be specified for run, follow, stop and prune stages.
-b|--build) - force to build images, even if they exists already
-S|--service <SERVICE> - flag can be specified for run, follow, stop and rm stages.
<SERVICE> $APP_CONTAINERS_OPT or $DB_CONTAINERS_OPT is the name of the service the stages are performed for.
-p|--rct-http-port PORT - flag for setting env var RCT_HTTP_PORT
-m|--target-modifier START_TARGET_MODIFIER - add modififying sufix to npm task like start:dev:START_TARGET_MODIFIER or start:test:START_TARGET_MODIFIER, depends on choosen TARGET
Expand Down Expand Up @@ -176,6 +183,10 @@ else
DB_EXPOSED_PORT=$2;
shift 2;
;;
-b|--build)
BUILD='--build';
shift 1;
;;
*)
usage "Incorrect flag: $1"
;;
Expand All @@ -196,10 +207,10 @@ else
fi;

export SUBTARGET;
export APP_CONTAINER_NAME="o2rct_application-$TARGET$SUBTARGET";
export DB_CONTAINER_NAME="o2rct_database-$TARGET$SUBTARGET";
export APP_CONTAINER_NAME="$O2RCT_ID""_application-$TARGET$SUBTARGET";
export DB_CONTAINER_NAME="$O2RCT_ID""_database-$TARGET$SUBTARGET";

DOCKER_COMP_CMD_NO_ENV="docker compose -p $TARGET$SUBTARGET-o2rct
DOCKER_COMP_CMD_NO_ENV="docker compose -p $TARGET$SUBTARGET-$O2RCT_ID
-f $MAIN_DOCKER_COMPOSE_YML
-f $DOCKER_DIR/docker-compose-$TARGET.yml
-f $DOCKER_DIR/docker-compose-network.yml
Expand Down Expand Up @@ -241,15 +252,26 @@ for stage in $STAGES; do
echo " *** do $stage";
case $stage in
prune)
$DOCKER_COMP_CMD_NO_ENV rm --stop --force -v $SERVICES && (docker network rm $TARGET$SUBTARGET-o2rct_network || exit_codes_filter 1);
# remove contatiner, networks...
for TS in $(docker network ls | grep $O2RCT_ID | awk '{ print $2 }' | awk -F- '{print $1}'); do
T=${TS%?}
S=${TS: -1};
$0 rm --target $T --subtarget $S;
done;
# remove images
docker rmi $(docker images | grep $O2RCT_ID | awk '{ print $1":"$2 }')
;;

rm)
$DOCKER_COMP_CMD_NO_ENV rm --stop --force -v $SERVICES && (docker network rm $TARGET$SUBTARGET-$O2RCT_ID""_network || exit_codes_filter 1);
;;

run*)
RUN_SUBSTATGES=$(echo ${stage#run} | sed -E "s/(\[|\:|\])/ /g");
RUN_SUBSTATGES=$(echo ${stage#run} | sed -E "s/(\[|\/|\])/ /g");
RUN_SUBSTATGES=$(echo $RUN_SUBSTATGES | sed -E "s/(^[[:space:]]*)|([[:space:]]*$)//g");
if [ -z "$RUN_SUBSTATGES" ]; then
echo 'default run[run,create,up]; up in detached mode';
RUN_SUBSTATGES="run create up";
echo 'default run[create/up]; up in detached mode';
RUN_SUBSTATGES="create up";
fi
echo $RUN_SUBSTATGES;
for rs in $RUN_SUBSTATGES; do
Expand All @@ -260,6 +282,7 @@ for stage in $STAGES; do
rs="up --exit-code-from application";
fi;
fi;
rs=$([[ "$rs" == 'create' ]] && echo "$rs $BUILD" || echo "$rs");
echo "*** *** do run : $rs";
run "$rs";
done
Expand Down