Commit 964a6428 authored by Raphael Beer's avatar Raphael Beer

Merge branch 'rls/1.0.1'

parents 0b038131 fe40eed9
ACCOUNT_FILE=./.htaccounts
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
MONGO_PORT=27017
MONGO_DB=tester
TWITTER_AUTH_KEY=GRAPHQL_KEY
......@@ -52,4 +52,5 @@ node_modules
# .env
.env
.env.*
!.env.example
.ht*
FROM python:3.5.7-slim-buster
RUN mkdir /app
WORKDIR /app
ADD requirements.txt /app/
ADD . /app
RUN pip3 install --no-cache-dir -r ./requirements.txt
Pull
```
git clone https://github.com/shadowban-eu/shadowban-eu-backend && cd shadowban-eu-backend
```
Add config
```
cp ~/configs/.env.development|production ./
cp ~/configs/.htaccounts
```
Run
`./run.sh development|production`
See [.env.example](https://github.com/shadowban-eu/shadowban-eu-backend/blob/dev/.env.example) for .env variables
This diff is collapsed.
......@@ -4,18 +4,23 @@ import sys
from pymongo import MongoClient, errors as MongoErrors
class Database:
def __init__(self, host=None, port=27017, db='tester', collection_name='results'):
def __init__(self, host=None, port=27017, db='tester'):
# collection name definitions
RESULTS_COLLECTION = 'results'
RATELIMIT_COLLECTION = 'rate-limits'
try:
print('[mongoDB] Connecting to ' + host + ':' + str(port))
print('[mongoDB] Using Collection `' + collection_name + '` in Database `' + db + '`')
print('[mongoDB] Using Database `' + db + '`')
# client and DB
self.client = MongoClient(host, port, serverSelectionTimeoutMS=3)
self.db = self.client[db]
# collection for test results
self.results = self.db[collection_name]
# collection for rate limit monitoring
self.rate_limits = self.db['rate-limits']
# test connection immediately, instead of
# collections
self.results = self.db[RESULTS_COLLECTION]
self.rate_limits = self.db[RATELIMIT_COLLECTION]
# Test connection immediately, instead of
# when trying to write in a request, later.
self.client.admin.command('ismaster')
except MongoErrors.ServerSelectionTimeoutError:
......@@ -33,8 +38,8 @@ class Database:
def write_rate_limit(self, data):
self.rate_limits.insert_one(data)
def connect(host=None, port=27017, db='tester', collection_name='results'):
def connect(host=None, port=27017, db='tester'):
if host is None:
raise ValueError('[mongoDB] Database constructor needs a `host`name or ip!')
return Database(host=host, port=port, db=db, collection_name=collection_name)
return Database(host=host, port=port, db=db)
version: "3.5"
services:
tester:
command: ["bash", "./run.sh", "development"]
version: "3.5"
services:
tester:
build: .
command: ["bash", "./docker-entry.sh"]
env_file: ${EXPECTED_ENV_FILE}
ports:
- "127.0.0.1:${PORT}:${PORT}"
volumes:
- .:/app
networks:
- mongodb
networks:
mongodb:
external:
name: shadowban-eu_mongodb
#/usr/bin/env bash
echo "Starting server..."
echo "--account-file $ACCOUNT_FILE"
echo "--cookie-dir $COOKIE_DIR"
echo "--log $LOG_FILE"
echo "--debug $DEBUG_FILE"
echo "--port "$PORT""
echo "--host "$HOST""
echo "--mongo-host $MONGO_HOST"
echo "--mongo-port $MONGO_PORT"
echo "--mongo-db $MONGO_DB"
echo "--twitter-auth-key $TWITTER_AUTH_KEY"
python3 -u ./backend.py \
--account-file $ACCOUNT_FILE \
--cookie-dir $COOKIE_DIR \
--log $LOG_FILE \
--debug $DEBUG_FILE \
--port "$PORT" \
--host "$HOST" \
--mongo-host $MONGO_HOST \
--mongo-port $MONGO_PORT \
--mongo-db $MONGO_DB \
--twitter-auth-key $TWITTER_AUTH_KEY
#!/usr/bin/env bash
echo -n "Looking for Python3: "
if ! hash python3; then
echo -n "\nPlease install Python3 to use this program!"
fi
echo "OK"
echo "Installing dependencies..."
pip3 install -r requirements.txt --no-cache-dir
echo -e "\n----------------------------"
echo "All done! \o/"
echo "Run 'PYTON_ENV=[development|prodcution] ./run.sh' to start the server!"
#/usr/bin/env bash
if [ "$1" != 'production' ] && [ "$1" != 'development' ]; then
echo "Please provide 'production' or 'development' as first argument"
echo "e.g. $ $0 development"
exit
fi
EXPECTED_ENV_FILE="./.env.$1"
if [ ! -f $EXPECTED_ENV_FILE ]; then
echo "Please provide a configuration file {$EXPECTED_ENV_FILE}!"
fi
echo "Using configuration from: $EXPECTED_ENV_FILE"
source $EXPECTED_ENV_FILE
echo "Listening on: $PORT"
PORT=$PORT EXPECTED_ENV_FILE=$EXPECTED_ENV_FILE docker-compose -f docker-compose.yml up
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