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

Refactor: DRY starter scripts

parent a3693c84
......@@ -3,8 +3,12 @@ COOKIE_DIR=./.htcookies
LOG_FILE=./logs/results.log
DEBUG_FILE=./logs/debug.log
PORT=4040
HOST=127.0.0.1
MONGO_HOST=127.0.0.1
HOST=localhost
MONGO_HOST=localhost
MONGO_PORT=27017
MONGO_DB=tester
TWITTER_AUTH_KEY=GRAPHQL_KEY
MONGO_DB=shadowban-testing
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
.env
.env.*
!.env.example
!.env.docker
.ht*
# starter scripts with possibly sensitive data
......@@ -62,5 +61,6 @@ dev.sh
start.sh
restart.sh
# venv
# python misc
.venv
mprofile_*.dat
Pull
```
git clone https://github.com/shadowban-eu/shadowban-eu-backend && cd shadowban-eu-backend
```
### Install/Run
Add config
```
cp ~/configs/.env.development|production ./
cp ~/configs/.htaccounts
```bash
$ git clone https://github.com/shadowban-eu/shadowban-testing ./shadowban-testing; cd $_
$ ./docker-entry.sh .env.example # takes any .env file
```
Run
`./run.sh development|production`
### Memory Profiling
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
if [ -f $1 ]; then
echo "Using provided .env file: $1"
export $(cat $1 | xargs)
shift
fi
echo "Starting server..."
echo "--account-file $ACCOUNT_FILE"
echo "--cookie-dir $COOKIE_DIR"
......@@ -16,7 +22,15 @@ echo "--twitter-auth-key --REDACTED--"
echo "--cors-allow $CORS_HOST"
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 \
--cookie-dir $COOKIE_DIR \
--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