0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-06 14:50:20 -05:00
penpot/manage.sh

295 lines
8 KiB
Bash
Raw Normal View History

2016-11-20 14:08:24 -05:00
#!/usr/bin/env bash
set -e
2016-11-20 14:08:24 -05:00
export ORGANIZATION="penpotapp";
export DEVENV_IMGNAME="$ORGANIZATION/devenv";
export DEVENV_PNAME="penpotdev";
export CURRENT_USER_ID=$(id -u);
2020-12-04 10:01:33 -05:00
export CURRENT_VERSION=$(git describe --tags);
export CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD);
export CURRENT_HASH=$(git rev-parse --short HEAD);
export CURRENT_BUILD=$(date '+%Y%m%d%H%M');
2016-11-20 14:08:24 -05:00
function build-devenv {
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
}
function push-devenv {
docker push $DEVENV_IMGNAME:latest
}
function pull-devenv {
set -ex
docker pull $DEVENV_IMGNAME:latest
}
function pull-devenv-if-not-exists {
if [[ ! $(docker images $DEVENV_IMGNAME:latest -q) ]]; then
pull-devenv $@
2016-11-20 14:08:24 -05:00
fi
2019-07-03 10:49:15 -05:00
}
function start-devenv {
pull-devenv-if-not-exists $@;
docker-compose -p $DEVENV_PNAME -f docker/devenv/docker-compose.yaml up -d;
}
2016-11-20 14:08:24 -05:00
function stop-devenv {
docker-compose -p $DEVENV_PNAME -f docker/devenv/docker-compose.yaml stop -t 2;
}
function drop-devenv {
docker-compose -p $DEVENV_PNAME -f docker/devenv/docker-compose.yaml down -t 2 -v;
echo "Clean old development image $DEVENV_IMGNAME..."
docker images $DEVENV_IMGNAME -q | awk '{print $3}' | xargs --no-run-if-empty docker rmi
}
function log-devenv {
docker-compose -p $DEVENV_PNAME -f docker/devenv/docker-compose.yaml logs -f --tail=50
}
function run-devenv {
if [[ ! $(docker ps -f "name=penpot-devenv-main" -q) ]]; then
start-devenv
fi
2019-02-20 15:24:03 -05:00
docker exec -ti penpot-devenv-main sudo -EH -u penpot /home/start-tmux.sh
}
2020-09-09 08:49:06 -05:00
function build {
pull-devenv-if-not-exists;
docker volume create ${DEVENV_PNAME}_user_data;
docker run -t --rm \
--mount source=${DEVENV_PNAME}_user_data,type=volume,target=/home/penpot/ \
--mount source=`pwd`,type=bind,target=/home/penpot/penpot \
-e EXTERNAL_UID=$CURRENT_USER_ID \
2020-12-02 11:06:07 -05:00
-e SHADOWCLJS_EXTRA_PARAMS=$SHADOWCLJS_EXTRA_PARAMS \
-w /home/penpot/penpot/$1 \
2020-12-02 11:06:07 -05:00
$DEVENV_IMGNAME:latest sudo -EH -u penpot ./scripts/build.sh
}
2020-09-09 08:49:06 -05:00
function build-frontend {
build "frontend";
}
2020-09-09 08:49:06 -05:00
function build-exporter {
build "exporter";
}
function build-backend {
2020-09-09 08:49:06 -05:00
build "backend";
}
function build-bundle {
2021-01-28 05:56:05 -05:00
local build_enabled=${PENPOT_BUNDLE_BUILD:-"true"};
if [ $build_enabled == "true" ]; then
build "frontend";
build "exporter";
build "backend";
fi
2020-09-09 08:49:06 -05:00
rm -rf ./bundle
mkdir -p ./bundle
2021-01-28 05:56:05 -05:00
cp -r ./frontend/target/dist ./bundle/frontend
cp -r ./backend/target/dist ./bundle/backend
cp -r ./exporter/target ./bundle/exporter
2020-09-09 08:49:06 -05:00
local version="$CURRENT_VERSION";
local name="penpot-$CURRENT_BRANCH";
if [ $CURRENT_BRANCH != "main" ]; then
version="$CURRENT_BRANCH-$CURRENT_VERSION";
fi;
2020-09-09 08:49:06 -05:00
echo $version > ./bundle/version.txt
sed -i -re "s/\%version\%/$version/g" ./bundle/frontend/index.html;
sed -i -re "s/\%version\%/$version/g" ./bundle/backend/main/app/config.clj;
2021-01-28 05:56:05 -05:00
local generate_tar=${PENPOT_BUNDLE_GENERATE_TAR:-"true"};
if [ $generate_tar == "true" ]; then
pushd bundle/
tar -I lz4 -cvf ../$name.tar.lz4 *;
popd
echo "##############################################################";
echo "# Generated $name.tar.lz4";
2021-01-13 11:25:41 -05:00
echo "# Version $version";
echo "##############################################################";
fi
2019-12-09 10:29:26 -05:00
}
function build-image {
local image=$1;
local tag=$2;
local version=$3;
local docker_image="$ORGANIZATION/$image";
2020-09-09 08:49:06 -05:00
set -x
pushd ./docker/images;
docker buildx build --platform linux/amd64 -t $docker_image:$tag -f Dockerfile.$image .;
# docker tag $docker_image:$tag $docker_image:$version;
# docker buildx build --platform linux/arm64 -t $docker_image:$version-arm64 .;
popd;
}
function build-images {
local version="$CURRENT_VERSION";
local bundle_file="penpot-$CURRENT_BRANCH.tar.lz4";
if [ $CURRENT_BRANCH != "main" ]; then
version="$CURRENT_BRANCH-$CURRENT_VERSION";
bundle_file="penpot-$CURRENT_BRANCH.tar.lz4";
fi;
if [ ! -f $bundle_file ]; then
echo "File '$bundle_file' does not exists.";
exit 1;
2020-09-09 08:49:06 -05:00
fi
local bundle_file_path=`readlink -f $bundle_file`;
echo "Building docker image from: $bundle_file_path.";
2020-09-09 08:49:06 -05:00
rm -rf ./docker/images/bundle;
mkdir -p ./docker/images/bundle;
pushd ./docker/images/bundle;
tar -I lz4 -xvf $bundle_file_path;
2020-09-09 08:49:06 -05:00
popd
build-image "backend" $CURRENT_BRANCH $version;
build-image "frontend" $CURRENT_BRANCH $version;
build-image "exporter" $CURRENT_BRANCH $version;
}
function publish-latest-images {
if [ $CURRENT_BRANCH != "main" ]; then
echo "Latest image can only be build from main branch.";
exit 1;
fi;
set -x
docker tag $ORGANIZATION/frontend:$CURRENT_BRANCH $ORGANIZATION/frontend:latest;
docker tag $ORGANIZATION/backend:$CURRENT_BRANCH $ORGANIZATION/backend:latest;
docker tag $ORGANIZATION/exporter:$CURRENT_BRANCH $ORGANIZATION/exporter:latest;
2021-02-01 11:39:07 -05:00
# docker push $ORGANIZATION/frontend:$CURRENT_VERSION;
# docker push $ORGANIZATION/backend:$CURRENT_VERSION;
# docker push $ORGANIZATION/exporter:$CURRENT_VERSION;
docker push $ORGANIZATION/frontend:latest;
docker push $ORGANIZATION/backend:latest;
docker push $ORGANIZATION/exporter:latest;
2020-09-09 08:49:06 -05:00
}
function publish-snapshot-images {
set -x
docker push $ORGANIZATION/frontend:$CURRENT_BRANCH;
docker push $ORGANIZATION/backend:$CURRENT_BRANCH;
docker push $ORGANIZATION/exporter:$CURRENT_BRANCH;
2020-09-09 08:49:06 -05:00
}
2016-11-20 14:08:24 -05:00
function usage {
echo "PENPOT build & release manager"
echo "USAGE: $0 OPTION"
2019-05-15 17:48:09 -05:00
echo "Options:"
# echo "- clean Stop and clean up docker containers"
# echo ""
echo "- pull-devenv Pulls docker development oriented image"
echo "- build-devenv Build docker development oriented image"
echo "- start-devenv Start the development oriented docker-compose service."
echo "- stop-devenv Stops the development oriented docker-compose service."
echo "- drop-devenv Remove the development oriented docker-compose containers, volumes and clean images."
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 ""
# 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
## devenv related commands
pull-devenv)
pull-devenv ${@:2};
;;
build-devenv)
build-devenv ${@:2}
;;
push-devenv)
push-devenv ${@:2}
;;
start-devenv)
start-devenv ${@:2}
2016-11-20 14:08:24 -05:00
;;
run-devenv)
run-devenv ${@:2}
;;
stop-devenv)
stop-devenv ${@:2}
;;
drop-devenv)
drop-devenv ${@:2}
;;
2019-12-09 10:29:26 -05:00
log-devenv)
log-devenv ${@:2}
;;
## testin related commands
# 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
# production builds
build-frontend)
build-frontend
2019-07-04 03:41:32 -05:00
;;
build-backend)
build-backend
;;
build-exporter)
build-exporter
;;
2020-09-09 08:49:06 -05:00
build-bundle)
build-bundle
;;
# Docker Image Tasks
build-images)
build-images;
;;
publish-snapshot-images)
publish-snapshot-images;
;;
publish-latest-images)
publish-latest-images;
;;
2016-11-20 14:08:24 -05:00
*)
usage
;;
esac