0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-24 18:07:17 +01:00
posthog/bin/plugin-server
Yakko Majuri 963c62aaf1
Use monorepo plugin server (#6784)
* use plugin-server in same repo

* remove plugins dir

* update docker files

* clean up docker files:

* visual separation

* run plugin server test stack

* build and push test image

* revert push image

* fix default yarn start

* another fix

* fix some more

* add plugin-server-prod script

* make executable

* update scripts:

* revert prod script

* fixes

* fix tests

* clean

* move build to docker

* build plugin-server in prod dockerfile

* use different entrypoint for e2e test

* fix bugs with ts-node-dev

* restore yarn.lock

* lost a few changes in the rebase

* fix dockerfile

Co-authored-by: James Greenhill <fuziontech@gmail.com>
2021-11-13 11:52:00 -08:00

69 lines
2.1 KiB
Bash
Executable File

#!/bin/bash
while test $# -gt 0; do
case "$1" in
-h|--help)
echo "USAGE:"
echo " bin/plugin-server [FLAGS]"
echo " "
echo "FLAGS:"
echo " -h, --help Print this help information."
echo " --no-restart-loop Run without restart loop. Recommended when deferring resiliency to e.g. docker-compose."
exit 0
;;
--no-restart-loop)
NO_RESTART_LOOP='true'
shift
;;
*)
break
;;
esac
done
export BASE_DIR=$(dirname $(dirname "$PWD/${0#./}"))
# Crudely extract netlocs by removing "kafka://" in a compatibility approach
export KAFKA_HOSTS=${KAFKA_HOSTS:-$(echo $KAFKA_URL | sed -e "s/kafka\(\+ssl\)\{0,1\}:\/\///g")}
# Check PRIMARY_DB in a compatibility approach
export KAFKA_ENABLED=${KAFKA_ENABLED:-$([[ $PRIMARY_DB = "clickhouse" ]] && echo "true" || echo "false")}
# On _Heroku_, the $WEB_CONCURRENCY env contains suggested number of workers per dyno.
# Unfortunately we are running a NodeJS app, yet get the value for the "python" buildpack.
# Thus instead of using this env directly, calculate the real concurrency from $DYNO_RAM.
# Python: https://github.com/heroku/heroku-buildpack-python/blob/main/vendor/WEB_CONCURRENCY.sh
# NodeJS: https://devcenter.heroku.com/articles/node-concurrency#common-runtime
if [[ -n $DYNO_RAM ]]; then
# One worker for 512MB of RAM, rounding up
export WORKER_CONCURRENCY=$(( ($DYNO_RAM - 1) / 512 + 1 ))
fi
# don't do a full build on e2e tests
if [[ -n $E2E_TESTING ]]; then
export DEBUG=1
fi
cd plugin-server
if [[ -n $DEBUG ]]; then
echo "🧐 Verifying installed packages..."
yarn --frozen-lockfile
fi
if [ $? -ne 0 ]; then
echo "💥 Verification failed!"
exit 1
fi
if [[ -n $NO_RESTART_LOOP ]]; then
echo "▶️ Starting plugin server..."
[[ -n $DEBUG ]] && yarn start:dev || yarn start:dist
else
echo "🔁 Starting plugin server in a resiliency loop..."
while true; do
[[ -n $DEBUG ]] && yarn start:dev || yarn start:dist
echo "💥 Plugin server crashed!"
echo "⌛️ Waiting 2 seconds before restarting..."
sleep 2
done
fi