Skip to content

Manual setup

marsofjkic edited this page Jun 27, 2023 · 2 revisions

Dependencies

  • PostgreSQL >= v11
  • Redis >= v5
  • Nginx >= 1.17
  • Python >= v3.7 (w/ pipenv)
  • Node >= v10 (w/ yarn)
  • Fish Shell (optional, used for dev shortcut commands)

Install Dependencies

Follow the instructions for your OS to install all the dependencies:

For example, here are the steps for Ubuntu 18.04:

wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo add-apt-repository -y "deb http://apt.postgresql.org/pub/repos/apt/ bionic-pgdg main"
sudo add-apt-repository -y ppa:maxmind/ppa
sudo add-apt-repository -y ppa:trevorjay/pyflame
sudo add-apt-repository -y ppa:fish-shell/release-3
sudo apt update
sudo apt install -y fish git gzip zip unzip  supervisor expect jq \
    nodejs npm build-essential autoconf \
    libmaxminddb0 libmaxminddb-dev mmdb-bin \
    python3.7 python3-pip python3.7-dev python-dev virtualenv pyflame \
    nginx redis-server postgresql-12 postgresql-server-dev-all \ 
    postgresql-contrib 

# Prevent the services from starting automatically on boot
# (we'll be starting them with supervisord instead)
sudo systemctl stop postgresql
sudo systemctl stop redis-server
sudo systemctl stop nginx
sudo systemctl disable postgresql
sudo systemctl disable redis-server
sudo systemctl disable nginx

# Make sure pipenv and yarn are up-to-date
pip3 install -q --upgrade pip setuptools virtualenv pipenv
npm install --global npm yarn

Setup Python and Node environemnts

# Install Python dependencies
export PIPENV_VENV_IN_PROJECT="enabled"
cd /opt/poker-game/core
pipenv install --dev
ln -s .venv venv
# Install JS dependencies
cd /opt/poker-game/core/js
yarn install

Initializing the database

cd /opt/poker-game
cp env/secrets.env.default env/secrets.env

# Then edit this values in env/secrets.env:
POSTGRES_USER=oddslingers
POSTGRES_DB=oddslingers
POSTGRES_PASSWORD=<some secure password here>
# you can generate a secure password with `openssl rand -base64 14`
mkdir -p "/opt/poker-game/data/postgres"

# On Ubuntu, we must run everything as the postgres user
# (skip these two commands on macOS)
sudo chown -R postgres:postgres "/opt/poker-game/data/postgres"
sudo -u postgres bash

# Then create the database and its user
source "/opt/poker-game/env/secrets.env"
initdb -D "/opt/poker-game/data/postgres"
pg_ctl -D "/opt/poker-game/data/postgres" start
psql postgres -c "CREATE USER $POSTGRES_USER WITH PASSWORD '$POSTGRES_PASSWORD';"
psql postgres -c "CREATE DATABASE $POSTGRES_DB OWNER $POSTGRES_USER;"
psql postgres -c "GRANT ALL PRIVILEGES ON DATABASE $POSTGRES_DB TO $POSTGRES_USER;"
psql postgres -c "ALTER USER $POSTGRES_DB CREATEDB;"

pg_ctl -D "/opt/poker-game/data/postgres" stop

Run initial migrations and create Django admin user

mkdir -p "/opt/poker-game/data/logs"
# Run Supervisord and start Postgres and Redis (w/ mac-dev.conf on macOS hosts)
supervisord -c "/opt/poker-game/etc/supervisor/ubuntu-dev.conf"
supervisorctl start poker-game:postgres
supervisorctl start poker-game:redis

cd /opt/poker-game/core
pipenv shell
./manage.py migrate
./manage.py createsuperuser

Check services are up

supervisorctl start all
supervisorctl status

# Point the oddslingers.l host to locahost for convenience
sudo bash -c "echo '127.0.0.1     oddslingers.l' >> /etc/hosts"

Create certificates

cd "/opt/oddslingers/bin"

# For example, this is for the local domain oddslingers.l
ssl oddslingers.l openssl

Start oddslingers

# For Bash: add this line to ~/.bashrc or ~/.bash_profile
PATH=/opt/poker-game/bin:./node_modules/.bin:$PATH

oddslingers start

# Then visit the host to see your running development server!
open https://oddslingers.l