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

253 lines
6.4 KiB
Bash
Raw Normal View History

2016-11-20 14:08:24 -05:00
#!/usr/bin/env bash
2022-06-13 04:18:02 -05:00
set -ex
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);
2021-03-29 08:37:25 -05:00
export CURRENT_VERSION=$(cat ./version.txt);
export CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD);
export CURRENT_HASH=$(git rev-parse --short HEAD);
2021-03-29 08:37:25 -05:00
export CURRENT_COMMITS=$(git rev-list --count HEAD)
function print-current-version {
if [ $CURRENT_BRANCH != "main" ]; then
echo -n "$CURRENT_BRANCH-$CURRENT_VERSION-$CURRENT_COMMITS-g$CURRENT_HASH"
else
echo -n "$CURRENT_VERSION-$CURRENT_COMMITS-g$CURRENT_HASH"
fi
}
2016-11-20 14:08:24 -05:00
function build-devenv {
echo "Building development image $DEVENV_IMGNAME:latest..."
pushd docker/devenv;
docker run --privileged --rm tonistiigi/binfmt --install all
docker buildx inspect penpot > /dev/null 2>&1;
if [ $? -eq 1 ]; then
docker buildx create --name=penpot --use
docker buildx inspect --bootstrap > /dev/null 2>&1;
else
docker buildx use penpot;
docker buildx inspect --bootstrap > /dev/null 2>&1;
fi
# docker build -t $DEVENV_IMGNAME:latest .
docker buildx build --platform linux/amd64,linux/arm64 --push -t $DEVENV_IMGNAME:latest .;
docker pull $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 {
2021-03-31 01:32:57 -05:00
echo ">> build start: $1"
local version=$(print-current-version);
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 \
2021-03-31 01:32:57 -05:00
$DEVENV_IMGNAME:latest sudo -EH -u penpot ./scripts/build $version
echo ">> build end: $1"
}
function put-license-file {
local target=$1;
tee -a $target/LICENSE >> /dev/null <<EOF
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
Copyright (c) UXBOX Labs SL
EOF
}
function build-frontend-bundle {
echo ">> bundle frontend start";
2021-03-31 01:32:57 -05:00
2021-03-29 08:37:25 -05:00
local version=$(print-current-version);
local bundle_dir="./bundle-frontend";
2021-01-28 05:56:05 -05:00
build "frontend";
2020-09-09 08:49:06 -05:00
rm -rf $bundle_dir;
mv ./frontend/target/dist $bundle_dir;
echo $version > $bundle_dir/version.txt;
put-license-file $bundle_dir;
echo ">> bundle frontend end";
}
function build-backend-bundle {
echo ">> bundle backend start";
local version=$(print-current-version);
local bundle_dir="./bundle-backend";
build "backend";
rm -rf $bundle_dir;
mv ./backend/target/dist $bundle_dir;
echo $version > $bundle_dir/version.txt;
2021-03-31 01:32:57 -05:00
put-license-file $bundle_dir;
2022-08-19 00:21:51 -05:00
echo ">> bundle backend end";
2021-02-09 06:12:25 -05:00
}
2021-02-09 06:12:25 -05:00
function build-exporter-bundle {
2021-03-31 01:32:57 -05:00
echo ">> bundle exporter start";
2021-03-29 08:37:25 -05:00
local version=$(print-current-version);
2021-02-09 06:12:25 -05:00
local bundle_dir="./bundle-exporter";
build "exporter";
2021-02-09 06:12:25 -05:00
rm -rf $bundle_dir;
2021-03-31 01:32:57 -05:00
mv ./exporter/target $bundle_dir;
2021-02-09 06:12:25 -05:00
echo $version > $bundle_dir/version.txt
2021-03-31 01:32:57 -05:00
put-license-file $bundle_dir;
echo ">> bundle exporter end";
2019-12-09 10:29:26 -05:00
}
2021-11-15 09:54:36 -05:00
# DEPRECATED: temporary maintained for backward compatibility.
function build-app-bundle {
echo ">> bundle app start";
local version=$(print-current-version);
local bundle_dir="./bundle-app";
build "frontend";
build "backend";
rm -rf $bundle_dir
mkdir -p $bundle_dir;
mv ./frontend/target/dist $bundle_dir/frontend;
mv ./backend/target/dist $bundle_dir/backend;
echo $version > $bundle_dir/version.txt
put-license-file $bundle_dir;
echo ">> bundle app end";
}
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 "- 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 ""
2016-11-20 14:08:24 -05:00
}
case $1 in
version)
print-current-version
;;
## 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}
;;
# production builds
2021-02-09 06:12:25 -05:00
build-app-bundle)
build-app-bundle;
;;
build-frontend-bundle)
build-frontend-bundle;
;;
build-backend-bundle)
build-backend-bundle;
;;
2021-02-09 06:12:25 -05:00
build-exporter-bundle)
build-exporter-bundle;
2020-09-09 08:49:06 -05:00
;;
# Docker Image Tasks
2016-11-20 14:08:24 -05:00
*)
usage
;;
esac