dockersetup: add option to skip database migrations

If we've messed around with the migrations during development then they
may need to be run carefully (with some fake steps), so provide an
option to update the container and then do the migrations manually
afterwards.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
Paul Eggleton 2019-02-14 10:55:43 +13:00
parent 0d19d76d8a
commit 8d52470654

View File

@ -42,6 +42,7 @@ def get_args():
parser.add_argument('--cert', type=str, help='Existing SSL certificate to use for HTTPS web serving', required=False) parser.add_argument('--cert', type=str, help='Existing SSL certificate to use for HTTPS web serving', required=False)
parser.add_argument('--cert-key', type=str, help='Existing SSL certificate key to use for HTTPS web serving', required=False) parser.add_argument('--cert-key', type=str, help='Existing SSL certificate key to use for HTTPS web serving', required=False)
parser.add_argument('--letsencrypt', action="store_true", default=False, help='Use Let\'s Encrypt for HTTPS') parser.add_argument('--letsencrypt', action="store_true", default=False, help='Use Let\'s Encrypt for HTTPS')
parser.add_argument('--no-migrate', action="store_true", default=False, help='Skip running database migrations')
args = parser.parse_args() args = parser.parse_args()
@ -93,7 +94,7 @@ def get_args():
if len(email_host_split) > 1: if len(email_host_split) > 1:
email_port = email_host_split[1] email_port = email_host_split[1]
return args.update, args.reinstall, args.hostname, args.http_proxy, args.https_proxy, args.databasefile, port, proxymod, args.portmapping, args.no_https, args.cert, cert_key, args.letsencrypt, email_host, email_port return args.update, args.reinstall, args.hostname, args.http_proxy, args.https_proxy, args.databasefile, port, proxymod, args.portmapping, args.no_https, args.cert, cert_key, args.letsencrypt, email_host, email_port, args.no_migrate
# Edit http_proxy and https_proxy in Dockerfile # Edit http_proxy and https_proxy in Dockerfile
def edit_dockerfile(http_proxy, https_proxy): def edit_dockerfile(http_proxy, https_proxy):
@ -402,7 +403,7 @@ def writefile(filename, data):
## Get user arguments and modify config files ## Get user arguments and modify config files
updatemode, reinstmode, hostname, http_proxy, https_proxy, dbfile, port, proxymod, portmapping, no_https, cert, cert_key, letsencrypt, email_host, email_port = get_args() updatemode, reinstmode, hostname, http_proxy, https_proxy, dbfile, port, proxymod, portmapping, no_https, cert, cert_key, letsencrypt, email_host, email_port, no_migrate = get_args()
if updatemode: if updatemode:
with open('docker-compose.yml', 'r') as f: with open('docker-compose.yml', 'r') as f:
@ -533,14 +534,15 @@ if not updatemode:
print("Database import failed") print("Database import failed")
sys.exit(1) sys.exit(1)
# Apply any pending layerindex migrations / initialize the database. if not no_migrate:
env = os.environ.copy() # Apply any pending layerindex migrations / initialize the database.
env['DATABASE_USER'] = 'root' env = os.environ.copy()
env['DATABASE_PASSWORD'] = dbapassword env['DATABASE_USER'] = 'root'
return_code = subprocess.call("docker-compose run --rm -e DATABASE_USER -e DATABASE_PASSWORD layersapp /opt/migrate.sh", shell=True, env=env) env['DATABASE_PASSWORD'] = dbapassword
if return_code != 0: return_code = subprocess.call("docker-compose run --rm -e DATABASE_USER -e DATABASE_PASSWORD layersapp /opt/migrate.sh", shell=True, env=env)
print("Applying migrations failed") if return_code != 0:
sys.exit(1) print("Applying migrations failed")
sys.exit(1)
if not updatemode: if not updatemode:
# Create normal database user for app to use # Create normal database user for app to use