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-07-03 10:49:15 -05:00
|
|
|
IMGNAME="uxbox-devenv"
|
2016-11-20 14:08:24 -05:00
|
|
|
|
2019-07-03 10:49:15 -05:00
|
|
|
function kill-devenv-container {
|
2019-02-20 15:24:03 -05:00
|
|
|
echo "Cleaning development container $IMGNAME:$REV..."
|
2019-07-03 10:49:15 -05:00
|
|
|
docker ps -a -f name=$IMGNAME -q | xargs --no-run-if-empty docker kill
|
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-06-03 09:53:31 -05:00
|
|
|
function build-devenv {
|
2019-02-19 23:58:25 -05:00
|
|
|
echo "Building development image $IMGNAME:$REV..."
|
2019-07-03 10:49:15 -05:00
|
|
|
docker build --rm=true \
|
|
|
|
-t $IMGNAME:$REV \
|
|
|
|
-t $IMGNAME:latest \
|
|
|
|
--build-arg EXTERNAL_UID=$(id -u) \
|
|
|
|
--label="io.uxbox.devenv" \
|
|
|
|
docker/devenv
|
2016-11-20 14:08:24 -05:00
|
|
|
}
|
|
|
|
|
2019-07-03 10:49:15 -05:00
|
|
|
function build-devenv-if-not-exists {
|
|
|
|
if [[ ! $(docker images $IMGNAME:$REV -q) ]]; then
|
2019-06-03 09:53:31 -05:00
|
|
|
build-devenv
|
2016-11-20 14:08:24 -05:00
|
|
|
fi
|
2019-07-03 10:49:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function run-devenv {
|
|
|
|
kill-devenv-container;
|
|
|
|
build-devenv-if-not-exists;
|
2016-11-20 14:08:24 -05:00
|
|
|
|
2017-02-14 12:23:32 -05:00
|
|
|
mkdir -p $HOME/.m2
|
2019-02-14 07:04:05 -05:00
|
|
|
rm -rf ./frontend/node_modules
|
2019-06-19 09:42:32 -05:00
|
|
|
mkdir -p \
|
|
|
|
./frontend/resources/public/css \
|
|
|
|
./frontend/resources/public/view/css
|
2017-02-14 12:23:32 -05:00
|
|
|
|
2019-06-03 09:53:31 -05:00
|
|
|
CONTAINER=$IMGNAME:latest
|
2019-02-20 15:24:03 -05:00
|
|
|
|
|
|
|
echo "Running development image $CONTAINER..."
|
2019-06-03 09:53:31 -05:00
|
|
|
docker run --rm -ti \
|
2016-11-20 14:40:30 -05:00
|
|
|
-v `pwd`:/home/uxbox/uxbox \
|
2016-11-20 14:08:24 -05:00
|
|
|
-v $HOME/.m2:/home/uxbox/.m2 \
|
|
|
|
-v $HOME/.gitconfig:/home/uxbox/.gitconfig \
|
2019-02-19 23:58:25 -05:00
|
|
|
-p 3449:3449 -p 6060:6060 -p 9090:9090 \
|
2019-07-03 10:49:15 -05:00
|
|
|
--name "uxbox-devenv" \
|
2019-02-20 15:24:03 -05:00
|
|
|
$CONTAINER
|
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-06-24 12:38:51 -05:00
|
|
|
run-frontend-tests || exit 1;
|
2019-06-19 11:31:48 -05:00
|
|
|
echo "Testing backend..."
|
2019-06-24 12:38:51 -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-07-03 10:49:15 -05:00
|
|
|
build-devenv-if-not-exists;
|
|
|
|
|
|
|
|
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-07-03 10:49:15 -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-06-03 09:53:31 -05:00
|
|
|
function build-release-frontend-local {
|
2019-07-03 10:49:15 -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
|
|
|
|
|
|
|
|
CONTAINER=$IMGNAME:latest
|
|
|
|
|
|
|
|
echo "Running development image $CONTAINER to build frontend release..."
|
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-06-11 15:56:24 -05:00
|
|
|
$CONTAINER ./scripts/build-release.sh
|
2019-02-15 14:27:52 -05:00
|
|
|
}
|
|
|
|
|
2019-06-03 09:53:31 -05:00
|
|
|
function build-release-frontend {
|
|
|
|
build-release-frontend-local || exit 1;
|
|
|
|
rm -rf docker/release.frontend/dist || exit 1;
|
2019-07-03 10:49:15 -05:00
|
|
|
cp -vr frontend/dist docker/release.frontend/ || exit 1;
|
|
|
|
|
|
|
|
docker build --rm=true \
|
2019-07-03 11:46:46 -05:00
|
|
|
-t uxbox-production-frontend:$REV \
|
|
|
|
-t uxbox-production-frontend:latest \
|
2019-07-03 10:49:15 -05:00
|
|
|
docker/release.frontend/;
|
|
|
|
|
2019-06-03 09:53:31 -05:00
|
|
|
rm -rf docker/release.frontend/dist || exit 1;
|
2018-11-25 04:48:40 -05:00
|
|
|
}
|
|
|
|
|
2019-06-11 14:10:07 -05:00
|
|
|
function build-release-backend-local {
|
2019-06-23 11:47:33 -05:00
|
|
|
echo "Prepare backend release..."
|
2019-06-24 12:38:51 -05:00
|
|
|
|
2019-07-03 10:49:15 -05:00
|
|
|
rm -rf ./backend/dist
|
|
|
|
|
2019-06-24 12:38:51 -05:00
|
|
|
rsync -avr \
|
|
|
|
--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
|
|
|
|
|
|
|
function build-release-backend {
|
|
|
|
build-release-backend-local || exit 1;
|
|
|
|
rm -rf docker/release.backend/dist || exit 1;
|
2019-07-03 10:49:15 -05:00
|
|
|
cp -vr backend/dist docker/release.backend/ || exit 1;
|
|
|
|
|
|
|
|
docker build --rm=true \
|
2019-07-03 11:46:46 -05:00
|
|
|
-t uxbox-production-backend:$REV \
|
|
|
|
-t uxbox-production-backend:latest \
|
2019-07-03 10:49:15 -05:00
|
|
|
docker/release.backend/;
|
|
|
|
|
2019-06-03 09:53:31 -05:00
|
|
|
rm -rf docker/release.backend/dist || exit 1;
|
2019-02-14 19:49:06 -05:00
|
|
|
}
|
|
|
|
|
2019-06-03 09:53:31 -05:00
|
|
|
function build-release {
|
2019-06-11 14:10:07 -05:00
|
|
|
echo "Building frontend release..."
|
2019-06-03 09:53:31 -05:00
|
|
|
build-release-frontend || exit 1;
|
2019-06-11 14:10:07 -05:00
|
|
|
echo "Building backend release..."
|
2019-06-03 09:53:31 -05:00
|
|
|
build-release-backend || exit 1;
|
2019-02-15 14:27:52 -05:00
|
|
|
}
|
|
|
|
|
2019-06-11 14:10:07 -05:00
|
|
|
function run-release {
|
2019-07-03 10:49:15 -05:00
|
|
|
if [[ ! $(docker images uxbox-backend:latest) ]]; then
|
|
|
|
build-release
|
|
|
|
fi
|
2019-06-11 14:10:07 -05:00
|
|
|
|
2019-07-03 10:49:15 -05:00
|
|
|
if [[ ! $(docker images uxbox-frontend:latest) ]]; then
|
2019-06-11 14:10:07 -05:00
|
|
|
build-release
|
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Running production images..."
|
|
|
|
sudo docker-compose -f ./docker/docker-compose.yml up -d
|
|
|
|
}
|
|
|
|
|
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-06-10 16:49:51 -05:00
|
|
|
echo "- clean Stop and clean up docker containers"
|
|
|
|
echo "- build-devenv Build docker container for development with tmux"
|
|
|
|
echo "- run-devenv Run (and build if necessary) development container (frontend at localhost:3449, backend at localhost:6060)"
|
2019-06-24 12:38:51 -05:00
|
|
|
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"
|
2019-06-10 16:49:51 -05:00
|
|
|
echo "- build-release Build 'production ready' docker images for both backend and frontend"
|
|
|
|
echo "- build-release-frontend Build a 'production ready' docker images for frontend only"
|
|
|
|
echo "- build-release-backend Build a 'production ready' docker images for backend only"
|
2019-06-11 14:10:07 -05:00
|
|
|
echo "- run-release Run 'production ready' docker images for both backend and frontend"
|
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
|
|
|
kill-devenv-container
|
|
|
|
remove-devenv-images
|
2019-02-20 15:24:03 -05:00
|
|
|
;;
|
2019-06-03 09:53:31 -05:00
|
|
|
build-devenv)
|
|
|
|
build-devenv
|
2016-11-20 14:08:24 -05:00
|
|
|
;;
|
2019-06-03 09:53:31 -05:00
|
|
|
run-devenv)
|
|
|
|
run-devenv
|
2019-02-14 19:49:06 -05:00
|
|
|
;;
|
2019-06-24 12:38:51 -05:00
|
|
|
run-all-tests)
|
|
|
|
run-all-tests
|
2019-06-19 09:42:32 -05:00
|
|
|
;;
|
2019-06-24 12:38:51 -05:00
|
|
|
run-frontend-tests)
|
|
|
|
run-frontend-tests
|
2019-06-19 09:42:32 -05:00
|
|
|
;;
|
2019-06-24 12:38:51 -05:00
|
|
|
run-backend-tests)
|
|
|
|
run-backend-tests
|
2019-06-19 09:42:32 -05:00
|
|
|
;;
|
2019-06-03 09:53:31 -05:00
|
|
|
build-release)
|
|
|
|
build-release
|
|
|
|
;;
|
|
|
|
build-release-frontend)
|
|
|
|
build-release-frontend
|
|
|
|
;;
|
|
|
|
build-release-backend)
|
|
|
|
build-release-backend
|
|
|
|
;;
|
2019-06-11 14:10:07 -05:00
|
|
|
run-release)
|
|
|
|
run-release
|
|
|
|
;;
|
2016-11-20 14:08:24 -05:00
|
|
|
*)
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
esac
|