0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-22 14:39:45 -05:00
penpot/manage.sh

263 lines
7 KiB
Bash
Raw Normal View History

2016-11-20 20:08:24 +01:00
#!/usr/bin/env bash
set -e
2016-11-20 20:08:24 +01:00
REV=`git log -n 1 --pretty=format:%h -- docker/`
2019-07-03 17:49:15 +02:00
IMGNAME="uxbox-devenv"
2016-11-20 20:08:24 +01:00
2019-07-03 17:49:15 +02:00
function kill-devenv-container {
2019-02-20 21:24:03 +01:00
echo "Cleaning development container $IMGNAME:$REV..."
2019-07-03 17:49:15 +02:00
docker ps -a -f name=$IMGNAME -q | xargs --no-run-if-empty docker kill
2019-02-20 21:24:03 +01:00
}
2019-07-03 17:49:15 +02:00
function remove-devenv-images {
2019-02-20 21:24:03 +01:00
echo "Clean old development image $IMGNAME..."
2019-07-03 17:49:15 +02:00
docker images $IMGNAME -q | awk '{print $3}' | xargs --no-run-if-empty docker rmi
2016-11-20 20:08:24 +01:00
}
2019-07-04 11:56:52 +02:00
function build-devenv-image {
2019-02-20 05:58:25 +01:00
echo "Building development image $IMGNAME:$REV..."
2019-07-03 17:49:15 +02: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 20:08:24 +01:00
}
2019-07-04 11:56:52 +02:00
function build-devenv-image-if-not-exists {
2019-07-03 17:49:15 +02:00
if [[ ! $(docker images $IMGNAME:$REV -q) ]]; then
2019-07-04 11:56:52 +02:00
build-devenv-image
2016-11-20 20:08:24 +01:00
fi
2019-07-03 17:49:15 +02:00
}
function run-devenv {
kill-devenv-container;
2019-07-04 11:56:52 +02:00
build-devenv-image-if-not-exists;
2016-11-20 20:08:24 +01:00
mkdir -p $HOME/.m2
2019-02-14 13:04:05 +01:00
rm -rf ./frontend/node_modules
mkdir -p \
./frontend/resources/public/css \
./frontend/resources/public/view/css
CONTAINER=$IMGNAME:latest
2019-02-20 21:24:03 +01:00
echo "Running development image $CONTAINER..."
docker run --rm -ti \
-v `pwd`:/home/uxbox/uxbox \
2016-11-20 20:08:24 +01:00
-v $HOME/.m2:/home/uxbox/.m2 \
-v $HOME/.gitconfig:/home/uxbox/.gitconfig \
2019-02-20 05:58:25 +01:00
-p 3449:3449 -p 6060:6060 -p 9090:9090 \
2019-07-03 17:49:15 +02:00
--name "uxbox-devenv" \
2019-02-20 21:24:03 +01:00
$CONTAINER
2016-11-20 20:08:24 +01:00
}
2019-06-24 19:38:51 +02:00
function run-all-tests {
echo "Testing frontend..."
2019-06-24 19:38:51 +02:00
run-frontend-tests || exit 1;
echo "Testing backend..."
2019-06-24 19:38:51 +02:00
run-backend-tests || exit 1;
}
2019-06-24 19:38:51 +02:00
function run-frontend-tests {
2019-07-04 11:56:52 +02:00
build-devenv-image-if-not-exists;
2019-07-03 17:49:15 +02: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-24 19:38:51 +02:00
function run-backend-tests {
2019-07-04 11:56:52 +02:00
build-devenv-image-if-not-exists;
2019-06-24 19:38:51 +02: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
}
function build-frontend-local {
2019-07-04 11:56:52 +02:00
build-devenv-image-if-not-exists;
mkdir -p $HOME/.m2
rm -rf ./frontend/node_modules
CONTAINER=$IMGNAME:latest;
BUILD_TYPE=$1;
echo "Running development image $CONTAINER to build frontend $BUILD_TYPE ..."
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" \
$CONTAINER ./scripts/build-$BUILD_TYPE.sh
}
function build-frontend-image {
build-frontend-local "dist" || exit 1;
2019-07-04 11:56:52 +02:00
rm -rf docker/frontend/dist || exit 1;
cp -vr frontend/dist docker/frontend/ || exit 1;
2019-07-03 17:49:15 +02:00
docker build --rm=true \
-t uxbox-frontend:$REV \
-t uxbox-frontend:latest \
2019-07-04 11:56:52 +02:00
docker/frontend/;
2019-07-03 17:49:15 +02:00
2019-07-04 11:56:52 +02:00
rm -rf docker/frontend/dist || exit 1;
}
function build-frontend-dbg-image {
build-frontend-local "dbg-dist" || exit 1;
2019-07-04 11:56:52 +02:00
rm -rf docker/frontend/dist || exit 1;
cp -vr frontend/dist docker/frontend/ || exit 1;
docker build --rm=true \
-t uxbox-frontend-dbg:$REV \
-t uxbox-frontend-dbg:latest \
2019-07-04 11:56:52 +02:00
docker/frontend/;
2019-07-04 11:56:52 +02:00
rm -rf docker/frontend/dist || exit 1;
}
function build-backend-local {
2019-07-04 11:56:52 +02:00
echo "Prepare backend dist..."
2019-06-24 19:38:51 +02:00
2019-07-03 17:49:15 +02:00
rm -rf ./backend/dist
rsync -ar \
2019-06-24 19:38:51 +02:00
--exclude="/test" \
--exclude="/resources/public/media" \
--exclude="/target" \
--exclude="/scripts" \
--exclude="/.*" \
./backend/ ./backend/dist/
}
function build-backend-image {
build-backend-local || exit 1;
2019-07-04 11:56:52 +02:00
rm -rf docker/backend/dist || exit 1;
cp -vr backend/dist docker/backend/ || exit 1;
2019-07-03 17:49:15 +02:00
docker build --rm=true \
-t uxbox-backend:$REV \
-t uxbox-backend:latest \
2019-07-04 11:56:52 +02:00
docker/backend/;
2019-07-03 17:49:15 +02:00
2019-07-04 11:56:52 +02:00
rm -rf docker/backend/dist || exit 1;
}
function build-images {
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;
}
function run {
if [[ ! $(docker images uxbox-backend:latest) ]]; then
build-backend-image
fi
if [[ ! $(docker images uxbox-frontend:latest) ]]; then
build-frontend-image
2019-07-03 17:49:15 +02:00
fi
if [[ ! $(docker images uxbox-frontend-dbg:latest) ]]; then
build-frontend-dbg-image
fi
echo "Running images..."
2019-07-04 11:56:52 +02:00
docker-compose -p uxbox -f ./docker/docker-compose.yml up -d
2019-07-04 10:41:32 +02:00
}
function log {
docker-compose -p uxbox -f docker/docker-compose.yml logs -f --tail=50
}
2019-07-04 10:41:32 +02:00
function stop {
echo "Stoping containers..."
2019-07-04 11:56:52 +02:00
docker-compose -p uxbox -f ./docker/docker-compose.yml stop
}
2016-11-20 20:08:24 +01:00
function usage {
echo "UXBOX build & release manager v$REV"
echo "USAGE: $0 OPTION"
2019-05-16 00:48:09 +02:00
echo "Options:"
2019-07-04 11:56:52 +02:00
echo "- clean Stop and clean up docker containers"
echo "- build-devenv-image 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 "- 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 "- build-images Build a 'release ready' docker images for both backend and frontend"
echo "- build-frontend-image Build a 'release ready' docker image for frontend (debug version)"
echo "- build-frontend-dbg-image Build a 'release ready' docker images for frontend"
echo "- build-backend-image Build a 'release ready' docker images for backend"
echo "- log Attach to docker logs."
2019-07-04 11:56:52 +02:00
echo "- run Run 'production ready' docker compose"
echo "- stop Stop 'production ready' docker compose"
2016-11-20 20:08:24 +01:00
}
case $1 in
2019-02-20 21:24:03 +01:00
clean)
2019-07-03 17:49:15 +02:00
kill-devenv-container
remove-devenv-images
2019-02-20 21:24:03 +01:00
;;
2019-07-04 11:56:52 +02:00
build-devenv-image)
build-devenv-image
2016-11-20 20:08:24 +01:00
;;
run-devenv)
run-devenv
;;
2019-06-24 19:38:51 +02:00
run-all-tests)
run-all-tests
;;
2019-06-24 19:38:51 +02:00
run-frontend-tests)
run-frontend-tests
;;
2019-06-24 19:38:51 +02:00
run-backend-tests)
run-backend-tests
;;
build-images)
build-images
;;
build-frontend-dbg-image)
build-frontend-dbg-image;
;;
build-frontend-image)
build-frontend-image;
;;
build-backend-image)
build-backend-image;
;;
2019-07-04 10:41:32 +02:00
run)
run
;;
2019-08-08 21:24:43 +02:00
log)
log
;;
2019-08-08 21:24:43 +02:00
2019-07-04 10:41:32 +02:00
stop)
stop
;;
2016-11-20 20:08:24 +01:00
*)
usage
;;
esac