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/`
|
2016-11-20 14:08:24 -05:00
|
|
|
IMGNAME="uxbox"
|
|
|
|
|
2019-06-03 09:53:31 -05:00
|
|
|
function kill-container {
|
2019-02-20 15:24:03 -05:00
|
|
|
echo "Cleaning development container $IMGNAME:$REV..."
|
2019-06-03 09:53:31 -05:00
|
|
|
if $(docker ps | grep -q $IMGNAME); then
|
|
|
|
docker ps | grep $IMGNAME | awk '{print $1}' | xargs --no-run-if-empty docker kill
|
2016-11-20 14:08:24 -05:00
|
|
|
fi
|
2019-06-03 09:53:31 -05:00
|
|
|
if $(docker ps -a | grep -q $IMGNAME); then
|
|
|
|
docker ps -a | grep $IMGNAME | awk '{print $1}' | xargs --no-run-if-empty docker rm
|
2019-02-20 15:24:03 -05:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-06-03 09:53:31 -05:00
|
|
|
function remove-image {
|
2019-02-20 15:24:03 -05:00
|
|
|
echo "Clean old development image $IMGNAME..."
|
2019-06-03 09:53:31 -05:00
|
|
|
docker images | grep $IMGNAME | 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 {
|
|
|
|
kill-container
|
2019-02-19 23:58:25 -05:00
|
|
|
echo "Building development image $IMGNAME:$REV..."
|
2019-06-03 09:53:31 -05:00
|
|
|
docker build --rm=true -t $IMGNAME:$REV -t $IMGNAME:latest docker/devenv
|
2016-11-20 14:08:24 -05:00
|
|
|
}
|
|
|
|
|
2019-06-03 09:53:31 -05:00
|
|
|
function run-devenv {
|
|
|
|
kill-container
|
2016-11-20 14:08:24 -05:00
|
|
|
|
2019-06-03 09:53:31 -05:00
|
|
|
if ! $(docker images | grep $IMGNAME | grep -q $REV); then
|
|
|
|
build-devenv
|
2016-11-20 14:08:24 -05:00
|
|
|
fi
|
|
|
|
|
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
|
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-02-20 15:24:03 -05:00
|
|
|
$CONTAINER
|
2016-11-20 14:08:24 -05:00
|
|
|
}
|
|
|
|
|
2019-06-03 09:53:31 -05:00
|
|
|
function build-release-frontend-local {
|
|
|
|
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" \
|
|
|
|
$IMGNAME:latest ./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;
|
|
|
|
cp -r frontend/dist docker/release.frontend/ || exit 1;
|
|
|
|
docker build --rm=true -t ${IMGNAME}-frontend:$REV -t ${IMGNAME}-frontend:latest docker/release.frontend/
|
|
|
|
rm -rf docker/release.frontend/dist || exit 1;
|
2018-11-25 04:48:40 -05:00
|
|
|
}
|
|
|
|
|
2019-06-03 09:53:31 -05:00
|
|
|
function build-release-backend {
|
|
|
|
rm -rf docker/release.backend/dist || exit 1;
|
|
|
|
rsync -avr \
|
|
|
|
--exclude="/test" \
|
|
|
|
--exclude="/resources/public/media" \
|
|
|
|
--exclude="/target" \
|
|
|
|
--exclude="/scripts" \
|
|
|
|
--exclude="/.*" \
|
|
|
|
backend/ docker/release.backend/dist/;
|
|
|
|
docker build --rm=true -t ${IMGNAME}-backend:$REV -t ${IMGNAME}-backend:latest docker/release.backend/
|
|
|
|
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 {
|
|
|
|
build-release-frontend || exit 1;
|
|
|
|
build-release-backend || exit 1;
|
2019-02-15 14:27:52 -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-02-20 15:24:03 -05:00
|
|
|
echo "USAGE: $0 [ clean | build | run | test | release-local | release-docker | run-release ]"
|
2019-05-15 17:48:09 -05:00
|
|
|
echo "Options:"
|
|
|
|
echo "- clean Stop and clean up docker containers"
|
2019-06-03 09:53:31 -05:00
|
|
|
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)"
|
|
|
|
echo "- build-release Build a 'production ready' release docker images"
|
2016-11-20 14:08:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
case $1 in
|
2019-02-20 15:24:03 -05:00
|
|
|
clean)
|
2019-06-03 09:53:31 -05:00
|
|
|
kill-container
|
|
|
|
remove-image
|
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
|
|
|
;;
|
|
|
|
release-docker)
|
2018-11-25 04:48:40 -05:00
|
|
|
release_image
|
|
|
|
;;
|
2019-02-15 14:27:52 -05:00
|
|
|
run-release)
|
|
|
|
run_release
|
|
|
|
;;
|
2019-06-03 09:53:31 -05:00
|
|
|
build-release)
|
|
|
|
build-release
|
|
|
|
;;
|
|
|
|
build-release-frontend)
|
|
|
|
build-release-frontend
|
|
|
|
;;
|
|
|
|
build-release-backend)
|
|
|
|
build-release-backend
|
|
|
|
;;
|
2016-11-20 14:08:24 -05:00
|
|
|
*)
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
esac
|