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
|
|
|
|
|
|
|
REV=`git rev-parse --short HEAD`
|
|
|
|
IMGNAME="uxbox"
|
|
|
|
|
|
|
|
function kill_container {
|
2019-02-20 15:24:03 -05:00
|
|
|
echo "Cleaning development container $IMGNAME:$REV..."
|
2018-11-25 04:48:40 -05:00
|
|
|
if $(sudo docker ps | grep -q $IMGNAME); then
|
|
|
|
sudo docker ps | grep $IMGNAME | awk '{print $1}' | xargs --no-run-if-empty sudo docker kill
|
2016-11-20 14:08:24 -05:00
|
|
|
fi
|
2019-02-20 15:24:03 -05:00
|
|
|
if $(sudo docker ps -a | grep -q $IMGNAME); then
|
|
|
|
sudo docker ps -a | grep $IMGNAME | awk '{print $1}' | xargs --no-run-if-empty sudo docker rm
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function remove_image {
|
|
|
|
echo "Clean old development image $IMGNAME..."
|
|
|
|
sudo docker images | grep $IMGNAME | awk '{print $3}' | xargs --no-run-if-empty sudo docker rmi
|
2016-11-20 14:08:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function build_image {
|
|
|
|
kill_container
|
2019-02-20 15:24:03 -05:00
|
|
|
remove_image
|
2019-02-19 23:58:25 -05:00
|
|
|
echo "Building development image $IMGNAME:$REV..."
|
|
|
|
sudo docker build --rm=true -t $IMGNAME:$REV docker/
|
2016-11-20 14:08:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
function run_image {
|
|
|
|
kill_container
|
|
|
|
|
2018-11-25 04:48:40 -05:00
|
|
|
if ! $(sudo docker images | grep $IMGNAME | grep -q $REV); then
|
2016-11-20 14:08:24 -05:00
|
|
|
build_image
|
|
|
|
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-02-20 15:24:03 -05:00
|
|
|
CONTAINER=$IMGNAME:$REV
|
|
|
|
#CONTAINER=monogramm/uxbox:develop
|
|
|
|
|
|
|
|
echo "Running development image $CONTAINER..."
|
2016-11-20 14:08:24 -05:00
|
|
|
sudo docker run -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-02-15 14:27:52 -05:00
|
|
|
function test {
|
|
|
|
kill_container
|
|
|
|
|
2019-02-20 15:24:03 -05:00
|
|
|
echo "TODO Testing backend (require running postgresql)..."
|
2019-02-17 18:23:34 -05:00
|
|
|
cd ./backend
|
|
|
|
#lein test
|
|
|
|
cd ..
|
|
|
|
|
2019-02-15 14:27:52 -05:00
|
|
|
echo "Testing frontend..."
|
|
|
|
cd ./frontend
|
|
|
|
./scripts/build-tests
|
|
|
|
node ./out/tests.js
|
|
|
|
cd ..
|
|
|
|
}
|
|
|
|
|
2019-02-14 19:49:06 -05:00
|
|
|
function release_local {
|
2018-11-25 04:48:40 -05:00
|
|
|
cd frontend
|
2018-11-25 07:49:44 -05:00
|
|
|
echo "Building frontend release..."
|
2018-11-25 04:48:40 -05:00
|
|
|
rm -rf ./dist
|
2019-02-14 07:04:05 -05:00
|
|
|
rm -rf ./node_modules
|
2018-11-25 07:39:47 -05:00
|
|
|
npm install
|
2018-11-25 04:48:40 -05:00
|
|
|
npm run dist
|
|
|
|
./scripts/dist-main
|
|
|
|
./scripts/dist-view
|
|
|
|
./scripts/dist-worker
|
|
|
|
echo "Frontend release generated in $(pwd)/dist"
|
|
|
|
|
|
|
|
cd ../backend
|
2018-11-25 07:49:44 -05:00
|
|
|
echo "Building backend release..."
|
2018-11-25 04:48:40 -05:00
|
|
|
rm -rf ./dist
|
2018-11-25 07:34:33 -05:00
|
|
|
./scripts/dist.sh
|
2018-11-25 04:48:40 -05:00
|
|
|
echo "Backend release generated in $(pwd)/dist"
|
|
|
|
|
|
|
|
cd ..
|
|
|
|
}
|
|
|
|
|
2019-02-14 19:49:06 -05:00
|
|
|
function release_image {
|
|
|
|
echo "Building frontend release..."
|
|
|
|
rm -rf ./frontend/dist ./frontend/node_modules ./frontend/dist
|
2019-02-15 17:09:04 -05:00
|
|
|
sudo docker build --rm=true -t ${IMGNAME}_frontend:$REV frontend/
|
2019-02-14 19:49:06 -05:00
|
|
|
echo "Frontend release image generated"
|
|
|
|
|
|
|
|
echo "Building backend release..."
|
|
|
|
rm -rf ./backend/dist
|
2019-02-15 17:09:04 -05:00
|
|
|
sudo docker build --rm=true -t ${IMGNAME}_backend:$REV backend/
|
2019-02-14 19:49:06 -05:00
|
|
|
echo "Backend release image generated"
|
|
|
|
}
|
|
|
|
|
2019-02-15 14:27:52 -05:00
|
|
|
function run_release {
|
|
|
|
kill_container
|
|
|
|
|
2019-02-15 16:35:49 -05:00
|
|
|
echo "Running production images..."
|
2019-02-15 14:27:52 -05:00
|
|
|
sudo docker-compose 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-02-20 15:24:03 -05:00
|
|
|
echo "USAGE: $0 [ clean | build | run | test | release-local | release-docker | run-release ]"
|
2016-11-20 14:08:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
case $1 in
|
2019-02-20 15:24:03 -05:00
|
|
|
clean)
|
|
|
|
kill_container
|
|
|
|
remove_image
|
|
|
|
;;
|
2016-11-20 14:08:24 -05:00
|
|
|
build)
|
|
|
|
build_image
|
|
|
|
;;
|
|
|
|
run)
|
|
|
|
run_image
|
|
|
|
;;
|
2019-02-15 14:27:52 -05:00
|
|
|
test)
|
|
|
|
test
|
|
|
|
;;
|
2019-02-14 19:49:06 -05:00
|
|
|
release-local)
|
|
|
|
release_local
|
|
|
|
;;
|
|
|
|
release-docker)
|
2018-11-25 04:48:40 -05:00
|
|
|
release_image
|
|
|
|
;;
|
2019-02-15 14:27:52 -05:00
|
|
|
run-release)
|
|
|
|
run_release
|
|
|
|
;;
|
2016-11-20 14:08:24 -05:00
|
|
|
*)
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
esac
|