def create_sample_db(ctx): """ Load schema and data into the empty database pointed to by $SQLA_SAMPLE_DB_CONN """ print("Loading schema...") db_conn = os.getenv('SQLA_SAMPLE_DB_CONN') if not db_conn: print("Error: SQLA_SAMPLE_DB_CONN env var must be set") return jdbc_url = to_jdbc_url(db_conn) result = run_migrations(ctx, jdbc_url) if result.failed: print("Migration failed!") print(result) return print("Schema loaded") print("Loading sample data...") subprocess.check_call( ['psql', '-v', 'ON_ERROR_STOP=1', '-f', 'data/sample_db.sql', db_conn] ) print("Sample data loaded") print("Refreshing materialized views...") os.environ["SQLA_CONN"] = db_conn # SQLA_CONN is used by manage.py tasks subprocess.check_call(['python', 'manage.py', 'refresh_materialized']) print("Materialized views refreshed")
def get_test_jdbc_url(): """ Return the JDBC URL for TEST_CONN. If TEST_CONN cannot be successfully converted, it is probably the default Postgres instance with trust authentication """ jdbc_url = to_jdbc_url(TEST_CONN) if jdbc_url is None: jdbc_url = "jdbc:" + TEST_CONN return jdbc_url
def create_sample_db(ctx): """ Load schema and data into the empty database pointed to by $SQLA_SAMPLE_DB_CONN """ print("Loading schema...") db_conn = os.getenv('SQLA_SAMPLE_DB_CONN') jdbc_url = to_jdbc_url(db_conn) run_migrations(ctx, jdbc_url) print("Schema loaded") print("Loading sample data...") subprocess.check_call( ['psql', '-v', 'ON_ERROR_STOP=1', '-f', 'data/sample_db.sql', db_conn ], ) print("Sample data loaded")
def create_sample_db(ctx): """ Load schema and data into the empty database pointed to by $SQLA_SAMPLE_DB_CONN """ print("Loading schema...") db_conn = os.getenv('SQLA_SAMPLE_DB_CONN') jdbc_url = to_jdbc_url(db_conn) run_migrations(ctx, jdbc_url) print("Schema loaded") print("Loading sample data...") subprocess.check_call( ['psql', '-v', 'ON_ERROR_STOP=1', '-f', 'data/sample_db.sql', db_conn], ) print("Sample data loaded")
def deploy(ctx, space=None, branch=None, login=None, yes=False): """Deploy app to Cloud Foundry. Log in using credentials stored per environment like `FEC_CF_USERNAME_DEV` and `FEC_CF_PASSWORD_DEV`; push to either `space` or t he space detected from the name and tags of the current branch. Note: Must pass `space` or `branch` if repo is in detached HEAD mode, e.g. when running on Travis. """ # Detect space repo = git.Repo('.') branch = branch or _detect_branch(repo) space = space or _detect_space(repo, branch, yes) if space is None: return # Set api api = 'https://api.fr.cloud.gov' ctx.run('cf api {0}'.format(api), echo=True) # Log in if necessary if login == 'True': login_command = 'cf auth "$FEC_CF_USERNAME_{0}" "$FEC_CF_PASSWORD_{0}"'.format( space.upper()) ctx.run(login_command, echo=True) # Target space ctx.run('cf target -o fec-beta-fec -s {0}'.format(space), echo=True) print("\nMigrating database...") jdbc_url = to_jdbc_url( os.getenv('FEC_MIGRATOR_SQLA_CONN_{0}'.format(space.upper()))) run_migrations(ctx, jdbc_url) print("Database migrated\n") # Set deploy variables with open('.cfmeta', 'w') as fp: json.dump({'user': os.getenv('USER'), 'branch': branch}, fp) # Deploy API and worker applications for app in ('api', 'celery-worker', 'celery-beat'): deployed = ctx.run('cf app {0}'.format(app), echo=True, warn=True) cmd = 'zero-downtime-push' if deployed.ok else 'push' ctx.run( 'cf {cmd} {app} -f manifests/manifest_{file}_{space}.yml'.format( cmd=cmd, app=app, file=app.replace('-', '_'), space=space), echo=True)
def deploy(ctx, space=None, branch=None, login=None, yes=False): """Deploy app to Cloud Foundry. Log in using credentials stored per environment like `FEC_CF_USERNAME_DEV` and `FEC_CF_PASSWORD_DEV`; push to either `space` or t he space detected from the name and tags of the current branch. Note: Must pass `space` or `branch` if repo is in detached HEAD mode, e.g. when running on Travis. """ # Detect space repo = git.Repo('.') branch = branch or _detect_branch(repo) space = space or _detect_space(repo, branch, yes) if space is None: return # Set api api = 'https://api.fr.cloud.gov' ctx.run('cf api {0}'.format(api), echo=True) # Log in if necessary if login == 'True': login_command = 'cf auth "$FEC_CF_USERNAME_{0}" "$FEC_CF_PASSWORD_{0}"'.format(space.upper()) ctx.run(login_command, echo=True) # Target space ctx.run('cf target -o fec-beta-fec -s {0}'.format(space), echo=True) print("\nMigrating database...") jdbc_url = to_jdbc_url(os.getenv('FEC_MIGRATOR_SQLA_CONN_{0}'.format(space.upper()))) run_migrations(ctx, jdbc_url) print("Database migrated\n") # Set deploy variables with open('.cfmeta', 'w') as fp: json.dump({'user': os.getenv('USER'), 'branch': branch}, fp) # Deploy API and worker applications for app in ('api', 'celery-worker', 'celery-beat'): deployed = ctx.run('cf app {0}'.format(app), echo=True, warn=True) cmd = 'zero-downtime-push' if deployed.ok else 'push' ctx.run('cf {cmd} {app} -f manifests/manifest_{file}_{space}.yml'.format( cmd=cmd, app=app, file=app.replace('-','_'), space=space ), echo=True)