Skip to content

Commit

Permalink
Add script to create initial user
Browse files Browse the repository at this point in the history
  • Loading branch information
vr2262 committed Dec 9, 2016
1 parent 851d22e commit f28d8e2
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 6 deletions.
1 change: 1 addition & 0 deletions dev/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def createdb(ensure=True):
engine = models.create_engine()
if ensure:
models.Base.metadata.create_all(engine)
print('Created schema {}'.format(models.Base.metadata.schema))
return sessionmaker(bind=engine, autocommit=True)()


Expand Down
36 changes: 36 additions & 0 deletions prod/create_initial_user.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env python
"""Create the initial administrator for the application."""
import argparse
import os
import sys

from sqlalchemy import func
from sqlalchemy.orm import sessionmaker

sys.path.insert(1, os.path.join(sys.path[0], '..'))


def main():
"""Supply the administrator's e-mail"""
parser = argparse.ArgumentParser()
parser.add_argument('email')
args, others = parser.parse_known_args()
from minigrid.options import parse_command_line
parse_command_line([None] + others)
from minigrid.options import options
if not any(other.startswith('--db_schema=') for other in others):
options.db_schema = 'minigrid_dev'
from minigrid import models
engine = models.create_engine()
session = sessionmaker(bind=engine, autocommit=True)()
users = session.query(func.count(models.User.user_id)).scalar()
if users:
print('At least one user already exists. Log in as that user.')
sys.exit(1)
with session.begin():
session.add(models.User(email=args.email))
print('Created initial user with e-mail', args.email)


if __name__ == '__main__':
main()
2 changes: 1 addition & 1 deletion prod/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '2'
services:
minigrid:
image: selcolumbia/minigrid-server:0.0.7
image: selcolumbia/minigrid-server:0.1.0
command: ./prod/run.sh --db_host=db --redis_url=redis://redis:6379/0 --minigrid-website-url=https://www.example.com
depends_on:
- redis
Expand Down
19 changes: 14 additions & 5 deletions prod/install.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env sh
# Minigrid Server installer for version 0.0.7
# Minigrid Server installer for version 0.1.0
set -e

# Do you have docker installed?
Expand Down Expand Up @@ -106,14 +106,21 @@ $SUDO openssl dhparam -out /etc/letsencrypt/live/$LETSENCRYPT_DIR/dhparam.pem 20

# Download the configuration files
printf "========================================\n"
printf " Downloading configuration files \n"
printf " Generating configuration \n"
printf "========================================\n"
$CURL -L https://raw.githubusercontent.com/SEL-Columbia/minigrid-server/0.0.7/prod/docker-compose.yml > docker-compose.yml
$CURL -L https://raw.githubusercontent.com/SEL-Columbia/minigrid-server/0.0.7/prod/nginx.conf > nginx.conf
$CURL -L https://raw.githubusercontent.com/SEL-Columbia/minigrid-server/0.1.0/prod/docker-compose.yml > docker-compose.yml
$CURL -L https://raw.githubusercontent.com/SEL-Columbia/minigrid-server/0.1.0/prod/nginx.conf > nginx.conf

sed -i s/www.example.com/$LETSENCRYPT_DIR/g docker-compose.yml
sed -i s/www.example.com/$LETSENCRYPT_DIR/g nginx.conf

printf "\n"
printf "Please enter an e-mail address for the \n"
printf "administrator. This will be the only \n"
printf "account that can log in at first. \n"
printf "Administrator e-mail address:\n>>> "
read ADMIN_EMAIL

# Bring up the server
printf "========================================\n"
printf " Starting minigrid server. \n"
Expand All @@ -126,7 +133,9 @@ if [ -f /etc/redhat-release ] ; then
chcon -Rt svirt_sandbox_file_t .
fi
$DOCKER_COMPOSE up -d
NGINX_CONTAINER_NAME=$($DOCKER_COMPOSE ps | grep nginx | cut -d' ' -f1)
MINIGRID_CONTAINER_NAME=$($DOCKER_COMPOSE ps | grep _minigrid_ | cut -d' ' -f1)
docker exec $MINIGRID_CONTAINER_NAME "prod/create_initial_user.py $ADMIN_EMAIL"
NGINX_CONTAINER_NAME=$($DOCKER_COMPOSE ps | grep _nginx_ | cut -d' ' -f1)

# Let's Encrypt auto-renew (for now this is a cron job).
printf "========================================\n"
Expand Down

0 comments on commit f28d8e2

Please sign in to comment.