2016-11-20 14:08:24 -05:00
|
|
|
#!/usr/bin/env bash
|
2019-02-15 14:46:51 -05:00
|
|
|
set -e
|
2016-11-20 14:08:24 -05:00
|
|
|
|
2019-06-05 03:26:50 -05:00
|
|
|
REV=`git log -n 1 --pretty=format:%h -- docker/`
|
2019-10-22 09:00:41 -05:00
|
|
|
IMGNAME="uxbox_devenv"
|
2019-02-20 15:24:03 -05:00
|
|
|
|
2019-07-03 10:49:15 -05:00
|
|
|
function remove-devenv-images {
|
2019-02-20 15:24:03 -05:00
|
|
|
echo "Clean old development image $IMGNAME..."
|
2019-07-03 10:49:15 -05:00
|
|
|
docker images $IMGNAME -q | awk '{print $3}' | xargs --no-run-if-empty docker rmi
|
2016-11-20 14:08:24 -05:00
|
|
|
}
|
|
|
|
|
2019-09-20 10:31:03 -05:00
|
|
|
function build-devenv {
|
|
|
|
echo "Building development image $IMGNAME:latest with UID $EXTERNAL_UID..."
|
|
|
|
|
2019-08-09 08:33:14 -05:00
|
|
|
local EXTERNAL_UID=${1:-$(id -u)}
|
2019-11-22 12:09:13 -05:00
|
|
|
docker-compose -p uxbox-devenv -f docker/devenv/docker-compose.yaml \
|
2019-09-20 10:31:03 -05:00
|
|
|
build --build-arg EXTERNAL_UID=$EXTERNAL_UID --force-rm;
|
2016-11-20 14:08:24 -05:00
|
|
|
}
|
|
|
|
|
2019-09-20 10:31:03 -05:00
|
|
|
function build-devenv-if-not-exists {
|
|
|
|
if [[ ! $(docker images $IMGNAME:latest -q) ]]; then
|
|
|
|
build-devenv $@
|
2016-11-20 14:08:24 -05:00
|
|
|
fi
|
2019-07-03 10:49:15 -05:00
|
|
|
}
|
|
|
|
|
2019-09-20 10:31:03 -05:00
|
|
|
function start-devenv {
|
|
|
|
build-devenv-if-not-exists $@;
|
2019-11-22 12:09:13 -05:00
|
|
|
docker-compose -p uxbox-devenv -f docker/devenv/docker-compose.yaml up -d;
|
2019-09-20 10:31:03 -05:00
|
|
|
}
|
2016-11-20 14:08:24 -05:00
|
|
|
|
2019-09-20 10:31:03 -05:00
|
|
|
function stop-devenv {
|
2019-11-22 12:09:13 -05:00
|
|
|
docker-compose -p uxbox-devenv -f docker/devenv/docker-compose.yaml stop -t 2;
|
2019-09-20 10:31:03 -05:00
|
|
|
}
|
2017-02-14 12:23:32 -05:00
|
|
|
|
2019-09-20 10:31:03 -05:00
|
|
|
function run-devenv {
|
2019-11-22 12:09:13 -05:00
|
|
|
if [[ ! $(docker ps -f "name=uxbox-devenv-main" -q) ]]; then
|
2019-09-20 10:31:03 -05:00
|
|
|
start-devenv
|
|
|
|
fi
|
2019-02-20 15:24:03 -05:00
|
|
|
|
2019-11-22 12:09:13 -05:00
|
|
|
docker exec -ti uxbox-devenv-main /home/uxbox/start.sh;
|
2016-11-20 14:08:24 -05:00
|
|
|
}
|
|
|
|
|
2019-06-24 12:38:51 -05:00
|
|
|
function run-all-tests {
|
2019-06-19 11:31:48 -05:00
|
|
|
echo "Testing frontend..."
|
2019-08-09 08:33:14 -05:00
|
|
|
run-frontend-tests $@ || exit 1;
|
2019-06-19 11:31:48 -05:00
|
|
|
echo "Testing backend..."
|
2019-08-09 08:33:14 -05:00
|
|
|
run-backend-tests $@ || exit 1;
|
2019-06-19 11:31:48 -05:00
|
|
|
}
|
|
|
|
|
2019-06-24 12:38:51 -05:00
|
|
|
function run-frontend-tests {
|
2019-09-20 10:31:03 -05:00
|
|
|
build-devenv-if-not-exists $@;
|
2019-07-03 10:49:15 -05:00
|
|
|
|
|
|
|
CONTAINER=$IMGNAME:latest
|
|
|
|
|
|
|
|
echo "Running development image $CONTAINER to test backend..."
|
|
|
|
docker run -ti --rm \
|
|
|
|
-w /home/uxbox/uxbox/frontend \
|
|
|
|
-v `pwd`:/home/uxbox/uxbox \
|
|
|
|
-v $HOME/.m2:/home/uxbox/.m2 \
|
|
|
|
$CONTAINER ./scripts/build-and-run-tests.sh
|
2019-06-19 11:31:48 -05:00
|
|
|
}
|
|
|
|
|
2019-06-24 12:38:51 -05:00
|
|
|
function run-backend-tests {
|
2019-09-20 10:31:03 -05:00
|
|
|
build-devenv-if-not-exists $@;
|
2019-06-24 12:38:51 -05:00
|
|
|
|
|
|
|
CONTAINER=$IMGNAME:latest
|
|
|
|
|
|
|
|
docker run -ti --rm \
|
|
|
|
-w /home/uxbox/uxbox/backend \
|
|
|
|
-v `pwd`:/home/uxbox/uxbox \
|
|
|
|
-v $HOME/.m2:/home/uxbox/.m2 \
|
|
|
|
$CONTAINER ./scripts/run-tests-in-docker.sh
|
2019-06-19 11:31:48 -05:00
|
|
|
}
|
|
|
|
|
2019-07-04 02:24:20 -05:00
|
|
|
function build-frontend-local {
|
2019-10-22 07:03:07 -05:00
|
|
|
build-devenv-if-not-exists;
|
2019-06-11 14:10:07 -05:00
|
|
|
|
2019-06-11 15:39:41 -05:00
|
|
|
mkdir -p $HOME/.m2
|
|
|
|
rm -rf ./frontend/node_modules
|
|
|
|
|
2019-07-04 02:24:20 -05:00
|
|
|
CONTAINER=$IMGNAME:latest;
|
|
|
|
BUILD_TYPE=$1;
|
2019-06-11 15:39:41 -05:00
|
|
|
|
2019-07-04 02:24:20 -05:00
|
|
|
echo "Running development image $CONTAINER to build frontend $BUILD_TYPE ..."
|
2019-06-03 09:53:31 -05:00
|
|
|
docker run -ti --rm \
|
|
|
|
-w /home/uxbox/uxbox/frontend \
|
|
|
|
-v `pwd`:/home/uxbox/uxbox \
|
|
|
|
-v $HOME/.m2:/home/uxbox/.m2 \
|
|
|
|
-e UXBOX_API_URL="/api" \
|
|
|
|
-e UXBOX_VIEW_URL="/view" \
|
2019-07-04 02:24:20 -05:00
|
|
|
$CONTAINER ./scripts/build-$BUILD_TYPE.sh
|
2019-02-15 14:27:52 -05:00
|
|
|
}
|
|
|
|
|
2019-08-08 12:17:25 -05:00
|
|
|
function build-frontend-image {
|
|
|
|
build-frontend-local "dist" || exit 1;
|
2019-07-04 04:56:52 -05:00
|
|
|
rm -rf docker/frontend/dist || exit 1;
|
|
|
|
cp -vr frontend/dist docker/frontend/ || exit 1;
|
2019-07-03 10:49:15 -05:00
|
|
|
|
|
|
|
docker build --rm=true \
|
2019-08-08 12:17:25 -05:00
|
|
|
-t uxbox-frontend:$REV \
|
|
|
|
-t uxbox-frontend:latest \
|
2019-07-04 04:56:52 -05:00
|
|
|
docker/frontend/;
|
2019-07-03 10:49:15 -05:00
|
|
|
|
2019-07-04 04:56:52 -05:00
|
|
|
rm -rf docker/frontend/dist || exit 1;
|
2018-11-25 04:48:40 -05:00
|
|
|
}
|
|
|
|
|
2019-08-08 12:17:25 -05:00
|
|
|
function build-frontend-dbg-image {
|
|
|
|
build-frontend-local "dbg-dist" || exit 1;
|
2019-07-04 04:56:52 -05:00
|
|
|
rm -rf docker/frontend/dist || exit 1;
|
|
|
|
cp -vr frontend/dist docker/frontend/ || exit 1;
|
2019-07-04 02:24:20 -05:00
|
|
|
|
|
|
|
docker build --rm=true \
|
2019-08-08 12:17:25 -05:00
|
|
|
-t uxbox-frontend-dbg:$REV \
|
|
|
|
-t uxbox-frontend-dbg:latest \
|
2019-07-04 04:56:52 -05:00
|
|
|
docker/frontend/;
|
2019-07-04 02:24:20 -05:00
|
|
|
|
2019-07-04 04:56:52 -05:00
|
|
|
rm -rf docker/frontend/dist || exit 1;
|
2019-07-04 02:24:20 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function build-backend-local {
|
2019-07-04 04:56:52 -05:00
|
|
|
echo "Prepare backend dist..."
|
2019-06-24 12:38:51 -05:00
|
|
|
|
2019-07-03 10:49:15 -05:00
|
|
|
rm -rf ./backend/dist
|
|
|
|
|
2019-07-04 02:40:17 -05:00
|
|
|
rsync -ar \
|
2019-06-24 12:38:51 -05:00
|
|
|
--exclude="/test" \
|
|
|
|
--exclude="/resources/public/media" \
|
|
|
|
--exclude="/target" \
|
|
|
|
--exclude="/scripts" \
|
|
|
|
--exclude="/.*" \
|
|
|
|
./backend/ ./backend/dist/
|
2019-06-23 14:30:16 -05:00
|
|
|
}
|
2019-06-11 14:10:07 -05:00
|
|
|
|
2019-08-08 12:17:25 -05:00
|
|
|
function build-backend-image {
|
2019-07-04 02:24:20 -05:00
|
|
|
build-backend-local || exit 1;
|
2019-07-04 04:56:52 -05:00
|
|
|
rm -rf docker/backend/dist || exit 1;
|
|
|
|
cp -vr backend/dist docker/backend/ || exit 1;
|
2019-07-03 10:49:15 -05:00
|
|
|
|
|
|
|
docker build --rm=true \
|
2019-08-08 12:17:25 -05:00
|
|
|
-t uxbox-backend:$REV \
|
|
|
|
-t uxbox-backend:latest \
|
2019-07-04 04:56:52 -05:00
|
|
|
docker/backend/;
|
2019-07-03 10:49:15 -05:00
|
|
|
|
2019-07-04 04:56:52 -05:00
|
|
|
rm -rf docker/backend/dist || exit 1;
|
2019-02-14 19:49:06 -05:00
|
|
|
}
|
|
|
|
|
2019-07-04 03:36:49 -05:00
|
|
|
function build-images {
|
2019-09-20 10:31:03 -05:00
|
|
|
build-devenv-if-not-exists $@;
|
|
|
|
|
2019-08-08 12:17:25 -05:00
|
|
|
echo "Building frontend image ..."
|
|
|
|
build-frontend-image || exit 1;
|
|
|
|
echo "Building frontend dbg image ..."
|
|
|
|
build-frontend-dbg-image || exit 1;
|
|
|
|
echo "Building backend image ..."
|
|
|
|
build-backend-image || exit 1;
|
2019-02-15 14:27:52 -05:00
|
|
|
}
|
|
|
|
|
2019-07-04 03:36:49 -05:00
|
|
|
function run {
|
2019-08-08 12:17:25 -05:00
|
|
|
if [[ ! $(docker images uxbox-backend:latest) ]]; then
|
|
|
|
build-backend-image
|
2019-07-04 02:24:20 -05:00
|
|
|
fi
|
|
|
|
|
2019-08-08 12:17:25 -05:00
|
|
|
if [[ ! $(docker images uxbox-frontend:latest) ]]; then
|
|
|
|
build-frontend-image
|
2019-07-03 10:49:15 -05:00
|
|
|
fi
|
2019-06-11 14:10:07 -05:00
|
|
|
|
2019-08-08 12:17:25 -05:00
|
|
|
if [[ ! $(docker images uxbox-frontend-dbg:latest) ]]; then
|
|
|
|
build-frontend-dbg-image
|
2019-06-11 14:10:07 -05:00
|
|
|
fi
|
|
|
|
|
2019-08-08 12:17:25 -05:00
|
|
|
echo "Running images..."
|
2019-07-04 04:56:52 -05:00
|
|
|
docker-compose -p uxbox -f ./docker/docker-compose.yml up -d
|
2019-07-04 03:41:32 -05:00
|
|
|
}
|
|
|
|
|
2019-08-08 10:05:05 -05:00
|
|
|
function log {
|
|
|
|
docker-compose -p uxbox -f docker/docker-compose.yml logs -f --tail=50
|
|
|
|
}
|
|
|
|
|
2019-07-04 03:41:32 -05:00
|
|
|
function stop {
|
|
|
|
echo "Stoping containers..."
|
2019-07-04 04:56:52 -05:00
|
|
|
docker-compose -p uxbox -f ./docker/docker-compose.yml stop
|
2019-06-11 14:10:07 -05:00
|
|
|
}
|
|
|
|
|
2016-11-20 14:08:24 -05:00
|
|
|
function usage {
|
2019-02-15 14:27:52 -05:00
|
|
|
echo "UXBOX build & release manager v$REV"
|
2019-06-10 16:49:51 -05:00
|
|
|
echo "USAGE: $0 OPTION"
|
2019-05-15 17:48:09 -05:00
|
|
|
echo "Options:"
|
2019-07-04 04:56:52 -05:00
|
|
|
echo "- clean Stop and clean up docker containers"
|
2019-09-20 10:31:03 -05:00
|
|
|
echo ""
|
|
|
|
echo "- build-devenv Build docker development oriented image; (can specify external user id in parameter)"
|
|
|
|
echo "- start-devenv Start the development oriented docker-compose service."
|
|
|
|
echo "- stop-devenv Stops the development oriented docker-compose service."
|
|
|
|
echo "- run-devenv Attaches to the running devenv container and starts development environment"
|
|
|
|
echo " based on tmux (frontend at localhost:3449, backend at localhost:6060)."
|
|
|
|
echo ""
|
|
|
|
echo "- run-all-tests Execute unit tests for both backend and frontend."
|
|
|
|
echo "- run-frontend-tests Execute unit tests for frontend only."
|
|
|
|
echo "- run-backend-tests Execute unit tests for backend only."
|
|
|
|
echo ""
|
2019-07-04 04:56:52 -05:00
|
|
|
echo "- build-images Build a 'release ready' docker images for both backend and frontend"
|
2019-08-08 12:17:25 -05:00
|
|
|
echo "- build-frontend-image Build a 'release ready' docker image for frontend (debug version)"
|
2019-08-09 08:51:52 -05:00
|
|
|
echo "- build-frontend-dbg-image Build a debug docker image for frontend"
|
|
|
|
echo "- build-backend-image Build a 'release ready' docker images for backend"
|
2019-08-08 12:17:25 -05:00
|
|
|
echo "- log Attach to docker logs."
|
2019-07-04 04:56:52 -05:00
|
|
|
echo "- run Run 'production ready' docker compose"
|
|
|
|
echo "- stop Stop 'production ready' docker compose"
|
2016-11-20 14:08:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
case $1 in
|
2019-02-20 15:24:03 -05:00
|
|
|
clean)
|
2019-07-03 10:49:15 -05:00
|
|
|
remove-devenv-images
|
2019-02-20 15:24:03 -05:00
|
|
|
;;
|
2019-09-20 10:31:03 -05:00
|
|
|
|
|
|
|
## devenv related commands
|
|
|
|
|
|
|
|
build-devenv)
|
|
|
|
build-devenv ${@:2}
|
|
|
|
;;
|
|
|
|
start-devenv)
|
|
|
|
start-devenv ${@:2}
|
2016-11-20 14:08:24 -05:00
|
|
|
;;
|
2019-06-03 09:53:31 -05:00
|
|
|
run-devenv)
|
2019-08-09 08:33:14 -05:00
|
|
|
run-devenv ${@:2}
|
2019-02-14 19:49:06 -05:00
|
|
|
;;
|
2019-09-20 10:31:03 -05:00
|
|
|
stop-devenv)
|
|
|
|
stop-devenv ${@:2}
|
|
|
|
;;
|
|
|
|
|
|
|
|
## testin related commands
|
|
|
|
|
2019-06-24 12:38:51 -05:00
|
|
|
run-all-tests)
|
2019-08-09 08:33:14 -05:00
|
|
|
run-all-tests ${@:2}
|
2019-06-19 09:42:32 -05:00
|
|
|
;;
|
2019-06-24 12:38:51 -05:00
|
|
|
run-frontend-tests)
|
2019-08-09 08:33:14 -05:00
|
|
|
run-frontend-tests ${@:2}
|
2019-06-19 09:42:32 -05:00
|
|
|
;;
|
2019-06-24 12:38:51 -05:00
|
|
|
run-backend-tests)
|
2019-08-09 08:33:14 -05:00
|
|
|
run-backend-tests ${@:2}
|
2019-06-19 09:42:32 -05:00
|
|
|
;;
|
2019-07-04 02:24:20 -05:00
|
|
|
|
2019-09-20 10:31:03 -05:00
|
|
|
# production related comands
|
|
|
|
|
2019-07-04 03:36:49 -05:00
|
|
|
build-images)
|
|
|
|
build-images
|
2019-06-03 09:53:31 -05:00
|
|
|
;;
|
2019-08-08 12:17:25 -05:00
|
|
|
build-frontend-dbg-image)
|
2019-08-09 09:37:55 -05:00
|
|
|
build-frontend-dbg-image
|
2019-06-03 09:53:31 -05:00
|
|
|
;;
|
2019-08-08 12:17:25 -05:00
|
|
|
build-frontend-image)
|
2019-08-09 09:37:55 -05:00
|
|
|
build-frontend-image
|
2019-07-04 02:24:20 -05:00
|
|
|
;;
|
2019-08-08 12:17:25 -05:00
|
|
|
build-backend-image)
|
2019-08-09 09:37:55 -05:00
|
|
|
build-backend-image
|
2019-07-04 03:36:49 -05:00
|
|
|
;;
|
2019-07-04 03:41:32 -05:00
|
|
|
|
2019-07-04 03:36:49 -05:00
|
|
|
run)
|
|
|
|
run
|
2019-07-04 02:24:20 -05:00
|
|
|
;;
|
2019-08-08 14:24:43 -05:00
|
|
|
|
2019-08-08 10:05:05 -05:00
|
|
|
log)
|
|
|
|
log
|
|
|
|
;;
|
2019-08-08 14:24:43 -05:00
|
|
|
|
2019-07-04 03:41:32 -05:00
|
|
|
stop)
|
|
|
|
stop
|
|
|
|
;;
|
2019-07-04 02:24:20 -05:00
|
|
|
|
2016-11-20 14:08:24 -05:00
|
|
|
*)
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
esac
|