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
|
|
|
|
2020-12-02 03:39:39 -05:00
|
|
|
export ORGANIZATION="penpotapp";
|
|
|
|
export DEVENV_IMGNAME="$ORGANIZATION/devenv";
|
|
|
|
export DEVENV_PNAME="penpotdev";
|
|
|
|
|
|
|
|
export CURRENT_USER_ID=$(id -u);
|
|
|
|
export CURRENT_GIT_TAG=$(git describe --tags);
|
|
|
|
export CURRENT_GIT_BRANCH=$(git rev-parse --abbrev-ref HEAD);
|
2016-11-20 14:08:24 -05:00
|
|
|
|
2019-09-20 10:31:03 -05:00
|
|
|
function build-devenv {
|
2020-12-02 03:39:39 -05:00
|
|
|
echo "Building development image $DEVENV_IMGNAME:latest..."
|
|
|
|
|
|
|
|
pushd docker/devenv;
|
|
|
|
docker build -t $DEVENV_IMGNAME:latest .
|
|
|
|
popd;
|
2016-11-20 14:08:24 -05:00
|
|
|
}
|
|
|
|
|
2020-12-02 03:39:39 -05:00
|
|
|
function publish-devenv {
|
|
|
|
docker push $DEVENV_IMGNAME:latest
|
|
|
|
}
|
|
|
|
|
|
|
|
function pull-devenv {
|
|
|
|
set -ex
|
|
|
|
docker pull $DEVENV_IMGNAME:latest
|
|
|
|
}
|
|
|
|
|
|
|
|
function pull-devenv-if-not-exists {
|
2020-01-20 07:03:01 -05:00
|
|
|
if [[ ! $(docker images $DEVENV_IMGNAME:latest -q) ]]; then
|
2020-12-02 03:39:39 -05:00
|
|
|
pull-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 {
|
2020-12-02 03:39:39 -05:00
|
|
|
pull-devenv-if-not-exists $@;
|
|
|
|
docker-compose -p $DEVENV_PNAME -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 {
|
2020-12-02 03:39:39 -05:00
|
|
|
docker-compose -p $DEVENV_PNAME -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-12-26 23:30:35 -05:00
|
|
|
function drop-devenv {
|
2020-12-02 03:39:39 -05:00
|
|
|
docker-compose -p $DEVENV_PNAME -f docker/devenv/docker-compose.yaml down -t 2 -v;
|
2020-01-20 07:03:01 -05:00
|
|
|
|
|
|
|
echo "Clean old development image $DEVENV_IMGNAME..."
|
|
|
|
docker images $DEVENV_IMGNAME -q | awk '{print $3}' | xargs --no-run-if-empty docker rmi
|
2019-12-26 23:30:35 -05:00
|
|
|
}
|
|
|
|
|
2020-12-02 03:39:39 -05:00
|
|
|
function log-devenv {
|
|
|
|
docker-compose -p $DEVENV_PNAME -f docker/devenv/docker-compose.yaml logs -f --tail=50
|
|
|
|
}
|
|
|
|
|
2019-09-20 10:31:03 -05:00
|
|
|
function run-devenv {
|
2020-11-10 06:41:20 -05:00
|
|
|
if [[ ! $(docker ps -f "name=penpot-devenv-main" -q) ]]; then
|
2019-09-20 10:31:03 -05:00
|
|
|
start-devenv
|
|
|
|
fi
|
2019-02-20 15:24:03 -05:00
|
|
|
|
2020-12-02 03:39:39 -05:00
|
|
|
docker exec -ti penpot-devenv-main sudo -EH -u penpot /home/start-tmux.sh
|
2019-06-19 11:31:48 -05:00
|
|
|
}
|
|
|
|
|
2020-09-09 08:49:06 -05:00
|
|
|
function build {
|
2020-12-02 03:39:39 -05:00
|
|
|
pull-devenv-if-not-exists;
|
|
|
|
docker volume create $DEVENV_PNAME_user_data;
|
2020-01-20 07:03:01 -05:00
|
|
|
docker run -t --rm \
|
2020-12-02 10:44:21 -05:00
|
|
|
--mount source=${DEVENV_PNAME}_user_data,type=volume,target=/home/penpot/ \
|
2020-11-10 06:41:20 -05:00
|
|
|
--mount source=`pwd`,type=bind,target=/home/penpot/penpot \
|
2020-12-02 03:39:39 -05:00
|
|
|
-e EXTERNAL_UID=$CURRENT_USER_ID \
|
2020-11-10 06:41:20 -05:00
|
|
|
-w /home/penpot/penpot/$1 \
|
2020-12-02 03:39:39 -05:00
|
|
|
$DEVENV_IMGNAME:latest sudo -u penpot ./scripts/build.sh
|
2019-07-04 02:24:20 -05:00
|
|
|
}
|
|
|
|
|
2020-09-09 08:49:06 -05:00
|
|
|
function build-frontend {
|
|
|
|
build "frontend";
|
|
|
|
}
|
2020-07-02 03:42:01 -05:00
|
|
|
|
2020-09-09 08:49:06 -05:00
|
|
|
function build-exporter {
|
|
|
|
build "exporter";
|
2020-07-02 03:42:01 -05:00
|
|
|
}
|
|
|
|
|
2020-01-20 07:03:01 -05:00
|
|
|
function build-backend {
|
2020-09-09 08:49:06 -05:00
|
|
|
build "backend";
|
|
|
|
}
|
|
|
|
|
|
|
|
function build-bundle {
|
|
|
|
build "frontend";
|
|
|
|
build "exporter";
|
|
|
|
build "backend";
|
|
|
|
|
|
|
|
rm -rf ./bundle
|
|
|
|
mkdir -p ./bundle
|
|
|
|
mv ./frontend/target/dist ./bundle/frontend
|
|
|
|
mv ./backend/target/dist ./bundle/backend
|
|
|
|
mv ./exporter/target ./bundle/exporter
|
|
|
|
|
2020-12-02 03:39:39 -05:00
|
|
|
local name="penpot-$CURRENT_GIT_TAG";
|
|
|
|
|
|
|
|
echo $CURRENT_GIT_TAG > ./bundle/frontend/version.txt
|
|
|
|
echo $CURRENT_GIT_TAG > ./bundle/backend/main/version.txt
|
|
|
|
echo $CURRENT_GIT_TAG > ./bundle/exporter/version.txt
|
|
|
|
echo $CURRENT_GIT_TAG > ./bundle/version.txt
|
2020-09-09 08:49:06 -05:00
|
|
|
|
2020-12-02 10:44:21 -05:00
|
|
|
local generate_tar=${PENPOT_BUILD_GENERATE_TAR:-"true"};
|
|
|
|
|
|
|
|
if [ $generate_tar == "true" ]; then
|
|
|
|
pushd bundle/
|
|
|
|
tar -cvf ../$name.tar *;
|
|
|
|
popd
|
2020-09-09 08:49:06 -05:00
|
|
|
|
2020-12-02 10:44:21 -05:00
|
|
|
xz -vez1f -T4 $name.tar
|
2019-08-08 10:05:05 -05:00
|
|
|
|
2020-12-02 10:44:21 -05:00
|
|
|
echo "##############################################################";
|
|
|
|
echo "# Generated $name.tar.xz";
|
|
|
|
echo "##############################################################";
|
|
|
|
fi
|
2019-12-09 10:29:26 -05:00
|
|
|
}
|
|
|
|
|
2020-12-02 03:39:39 -05:00
|
|
|
function build-image {
|
|
|
|
set -ex;
|
2020-09-09 08:49:06 -05:00
|
|
|
|
2020-12-02 03:39:39 -05:00
|
|
|
local image=$1;
|
2020-09-09 08:49:06 -05:00
|
|
|
|
2020-12-02 03:39:39 -05:00
|
|
|
pushd ./docker/images;
|
|
|
|
local docker_image="$ORGANIZATION/$image";
|
|
|
|
docker build -t $docker_image:$CURRENT_GIT_TAG -f Dockerfile.$image .;
|
|
|
|
popd;
|
|
|
|
}
|
|
|
|
|
|
|
|
function build-images {
|
|
|
|
local bundle_file="penpot-$CURRENT_GIT_TAG.tar.xz";
|
|
|
|
|
|
|
|
if [ ! -f $bundle_file ]; then
|
|
|
|
echo "File '$bundle_file' does not exists.";
|
|
|
|
exit 1;
|
2020-09-09 08:49:06 -05:00
|
|
|
fi
|
|
|
|
|
2020-12-02 03:39:39 -05:00
|
|
|
rm -rf ./docker/images/bundle;
|
|
|
|
mkdir -p ./docker/images/bundle;
|
2020-09-09 08:49:06 -05:00
|
|
|
|
2020-12-02 03:39:39 -05:00
|
|
|
local bundle_file_path=`readlink -f $bundle_file`;
|
|
|
|
echo "Building docker image from: $bundle_file_path.";
|
2020-09-09 08:49:06 -05:00
|
|
|
|
2020-12-02 03:39:39 -05:00
|
|
|
pushd ./docker/images/bundle;
|
|
|
|
tar xvf $bundle_file_path;
|
2020-09-09 08:49:06 -05:00
|
|
|
popd
|
2020-12-02 03:39:39 -05:00
|
|
|
|
|
|
|
build-image "backend";
|
|
|
|
build-image "frontend";
|
|
|
|
build-image "exporter";
|
2020-09-09 08:49:06 -05:00
|
|
|
}
|
|
|
|
|
2020-12-02 03:39:39 -05:00
|
|
|
function publish-snapshot {
|
|
|
|
set -x
|
|
|
|
docker tag $ORGANIZATION/frontend:$CURRENT_GIT_TAG $ORGANIZATION/frontend:$CURRENT_GIT_BRANCH
|
|
|
|
docker tag $ORGANIZATION/backend:$CURRENT_GIT_TAG $ORGANIZATION/backend:$CURRENT_GIT_BRANCH
|
|
|
|
docker tag $ORGANIZATION/exporter:$CURRENT_GIT_TAG $ORGANIZATION/exporter:$CURRENT_GIT_BRANCH
|
|
|
|
|
|
|
|
docker push $ORGANIZATION/frontend:$CURRENT_GIT_BRANCH;
|
|
|
|
docker push $ORGANIZATION/backend:$CURRENT_GIT_BRANCH;
|
|
|
|
docker push $ORGANIZATION/exporter:$CURRENT_GIT_BRANCH;
|
2020-09-09 08:49:06 -05:00
|
|
|
}
|
|
|
|
|
2016-11-20 14:08:24 -05:00
|
|
|
function usage {
|
2020-12-02 03:39:39 -05:00
|
|
|
echo "PENPOT build & release manager"
|
2019-06-10 16:49:51 -05:00
|
|
|
echo "USAGE: $0 OPTION"
|
2019-05-15 17:48:09 -05:00
|
|
|
echo "Options:"
|
2020-01-20 07:03:01 -05:00
|
|
|
# echo "- clean Stop and clean up docker containers"
|
|
|
|
# echo ""
|
2020-12-02 03:39:39 -05:00
|
|
|
echo "- pull-devenv Pulls docker development oriented image"
|
|
|
|
echo "- build-devenv Build docker development oriented image"
|
2019-09-20 10:31:03 -05:00
|
|
|
echo "- start-devenv Start the development oriented docker-compose service."
|
|
|
|
echo "- stop-devenv Stops the development oriented docker-compose service."
|
2019-12-26 23:30:35 -05:00
|
|
|
echo "- drop-devenv Remove the development oriented docker-compose containers, volumes and clean images."
|
2019-09-20 10:31:03 -05:00
|
|
|
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 ""
|
2020-12-02 03:39:39 -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."
|
2016-11-20 14:08:24 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
case $1 in
|
2019-09-20 10:31:03 -05:00
|
|
|
## devenv related commands
|
2020-12-02 03:39:39 -05:00
|
|
|
pull-devenv)
|
|
|
|
pull-devenv ${@:2};
|
|
|
|
;;
|
|
|
|
|
2019-09-20 10:31:03 -05:00
|
|
|
build-devenv)
|
|
|
|
build-devenv ${@:2}
|
|
|
|
;;
|
2020-12-02 03:39:39 -05:00
|
|
|
|
|
|
|
|
|
|
|
publish-devenv)
|
|
|
|
publish-devenv ${@:2}
|
|
|
|
;;
|
|
|
|
|
2019-09-20 10:31:03 -05:00
|
|
|
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}
|
|
|
|
;;
|
2019-12-26 23:30:35 -05:00
|
|
|
drop-devenv)
|
|
|
|
drop-devenv ${@:2}
|
|
|
|
;;
|
2019-12-09 10:29:26 -05:00
|
|
|
log-devenv)
|
|
|
|
log-devenv ${@:2}
|
|
|
|
;;
|
2019-09-20 10:31:03 -05:00
|
|
|
|
|
|
|
## testin related commands
|
|
|
|
|
2020-01-20 07:03:01 -05:00
|
|
|
# run-all-tests)
|
|
|
|
# run-all-tests ${@:2}
|
|
|
|
# ;;
|
|
|
|
# run-frontend-tests)
|
|
|
|
# run-frontend-tests ${@:2}
|
|
|
|
# ;;
|
|
|
|
# run-backend-tests)
|
|
|
|
# run-backend-tests ${@:2}
|
|
|
|
# ;;
|
2019-08-08 14:24:43 -05:00
|
|
|
|
2020-01-20 07:03:01 -05:00
|
|
|
# production builds
|
|
|
|
build-frontend)
|
|
|
|
build-frontend
|
2019-07-04 03:41:32 -05:00
|
|
|
;;
|
2019-07-04 02:24:20 -05:00
|
|
|
|
2020-01-20 07:03:01 -05:00
|
|
|
build-backend)
|
|
|
|
build-backend
|
2019-12-26 23:30:35 -05:00
|
|
|
;;
|
|
|
|
|
2020-07-02 03:42:01 -05:00
|
|
|
build-exporter)
|
|
|
|
build-exporter
|
|
|
|
;;
|
|
|
|
|
2020-09-09 08:49:06 -05:00
|
|
|
build-bundle)
|
|
|
|
build-bundle
|
|
|
|
;;
|
|
|
|
|
2020-12-02 03:39:39 -05:00
|
|
|
# Docker Image Tasks
|
|
|
|
build-images)
|
|
|
|
build-images;
|
|
|
|
;;
|
|
|
|
|
|
|
|
publish-snapshot)
|
|
|
|
publish-snapshot ${@:2}
|
|
|
|
;;
|
|
|
|
|
2016-11-20 14:08:24 -05:00
|
|
|
*)
|
|
|
|
usage
|
|
|
|
;;
|
|
|
|
esac
|