Commit 5250af43 authored by Raphael Beer's avatar Raphael Beer

Refactor: DRY starter scripts

parent a3693c84
...@@ -3,8 +3,12 @@ COOKIE_DIR=./.htcookies ...@@ -3,8 +3,12 @@ COOKIE_DIR=./.htcookies
LOG_FILE=./logs/results.log LOG_FILE=./logs/results.log
DEBUG_FILE=./logs/debug.log DEBUG_FILE=./logs/debug.log
PORT=4040 PORT=4040
HOST=127.0.0.1 HOST=localhost
MONGO_HOST=127.0.0.1 MONGO_HOST=localhost
MONGO_PORT=27017 MONGO_PORT=27017
MONGO_DB=tester MONGO_DB=shadowban-testing
TWITTER_AUTH_KEY=GRAPHQL_KEY MONGO_USERNAME=root
MONGO_PASSWORD=5X-rl[(EMdJKll1|qMDU}5xY<t?F.UEo
TWITTER_AUTH_KEY=AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA
CORS_HOST=http://localhost:3000
GUEST_SESSIONS=3
...@@ -54,7 +54,6 @@ node_modules ...@@ -54,7 +54,6 @@ node_modules
.env .env
.env.* .env.*
!.env.example !.env.example
!.env.docker
.ht* .ht*
# starter scripts with possibly sensitive data # starter scripts with possibly sensitive data
...@@ -62,5 +61,6 @@ dev.sh ...@@ -62,5 +61,6 @@ dev.sh
start.sh start.sh
restart.sh restart.sh
# venv # python misc
.venv .venv
mprofile_*.dat
Pull ### Install/Run
```
git clone https://github.com/shadowban-eu/shadowban-eu-backend && cd shadowban-eu-backend
```
Add config ```bash
``` $ git clone https://github.com/shadowban-eu/shadowban-testing ./shadowban-testing; cd $_
cp ~/configs/.env.development|production ./ $ ./docker-entry.sh .env.example # takes any .env file
cp ~/configs/.htaccounts
``` ```
Run ### Memory Profiling
`./run.sh development|production` Using [memory-profiler](https://pypi.org/project/memory-profiler/) to debug memory usage:
See [.env.example](https://github.com/shadowban-eu/shadowban-eu-backend/blob/dev/.env.example) for .env variables ```bash
# When env vars are already set
$ ./docker-entry.sh mprof
# Otherwise, read from file
$ ./docker-entry.sh .env.example mprof
# Passes remaining arguments to mprof (set interval to 5s)
$ ./docker-entry.sh .env.example mprof -T 5
```
#!/usr/bin/env bash #!/usr/bin/env bash
if [ -f $1 ]; then
echo "Using provided .env file: $1"
export $(cat $1 | xargs)
shift
fi
echo "Starting server..." echo "Starting server..."
echo "--account-file $ACCOUNT_FILE" echo "--account-file $ACCOUNT_FILE"
echo "--cookie-dir $COOKIE_DIR" echo "--cookie-dir $COOKIE_DIR"
...@@ -16,7 +22,15 @@ echo "--twitter-auth-key --REDACTED--" ...@@ -16,7 +22,15 @@ echo "--twitter-auth-key --REDACTED--"
echo "--cors-allow $CORS_HOST" echo "--cors-allow $CORS_HOST"
echo "--guest-sessions $GUEST_SESSIONS" echo "--guest-sessions $GUEST_SESSIONS"
python3 -u ./backend.py \ CMD="python3 -u ./backend.py"
if [ "$1" == "mprof" ]; then
shift
CMD="mprof run $@ ./backend.py"
echo -e "\nRecording memory profile\n"
fi
$CMD \
--account-file $ACCOUNT_FILE \ --account-file $ACCOUNT_FILE \
--cookie-dir $COOKIE_DIR \ --cookie-dir $COOKIE_DIR \
--log $LOG_FILE \ --log $LOG_FILE \
......
mprof run ./backend.py \
--account-file ./.htaccounts \
--cookie-dir ./.htcookies \
--port 8080 \
--host 0.0.0.0 \
--mongo-host 127.0.0.1 \
--mongo-port 27017 \
--mongo-db tester \
--mongo-username $MONGO_USERNAME \
--mongo-password $MONGO_PASSWORD \
--twitter-auth-key AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA \
--guest-sessions $GUEST_SESSIONS
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment