diff --git a/dev/commands.py b/dev/commands.py index 52c8763..6733684 100755 --- a/dev/commands.py +++ b/dev/commands.py @@ -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)() diff --git a/prod/create_initial_user.py b/prod/create_initial_user.py new file mode 100755 index 0000000..d0035c7 --- /dev/null +++ b/prod/create_initial_user.py @@ -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() diff --git a/prod/docker-compose.yml b/prod/docker-compose.yml index fb848f8..277c979 100644 --- a/prod/docker-compose.yml +++ b/prod/docker-compose.yml @@ -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 diff --git a/prod/install.sh b/prod/install.sh index d943a21..430266f 100755 --- a/prod/install.sh +++ b/prod/install.sh @@ -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? @@ -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" @@ -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"