From 23159ddde894ab05992547fe7bc0ae2c7afa1050 Mon Sep 17 00:00:00 2001 From: Rui Carmo Date: Tue, 26 Dec 2023 17:28:19 +0000 Subject: [PATCH] Added "preflight" worker --- docs/DESIGN.md | 1 + piku.py | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/docs/DESIGN.md b/docs/DESIGN.md index 93fb6e4..8eedbd8 100644 --- a/docs/DESIGN.md +++ b/docs/DESIGN.md @@ -21,6 +21,7 @@ An app is simply a `git` repository with some additional files on the top level, * `wsgi` workers, in the format `dotted.module:entry_point` (Python-only) * `web` workers, which can be anything that honors the `PORT` environment variable * `static` workers, which simply mount the first argument as the root static path +* `preflight` which is a special "worker" that is run once _before_ the app is deployed _and_ installing deps (can be useful for cleanups). * `release` which is a special worker that is run once when the app is deployed, after installing deps (can be useful for build steps). * `cron` workers, which require a simplified `cron` expression preceding the command to be run (e.g. `cron: */5 * * * * python batch.py` to run a batch every 5 minutes) * `worker` processes, which are standalone workers and can have arbitrary names diff --git a/piku.py b/piku.py index f25d09c..84c52c4 100755 --- a/piku.py +++ b/piku.py @@ -385,6 +385,13 @@ def do_deploy(app, deltas={}, newrev=None): workers = parse_procfile(procfile) if workers and len(workers) > 0: settings = {} + if "preflight" in workers: + echo("-----> Running preflight.", fg='green') + retval = call(workers["preflight"], cwd=app_path, env=settings, shell=True) + if retval: + echo("-----> Exiting due to preflight command error value: {}".format(retval)) + exit(retval) + workers.pop("preflight", None) if exists(join(app_path, 'requirements.txt')) and found_app("Python"): settings.update(deploy_python(app, deltas)) elif exists(join(app_path, 'Gemfile')) and found_app("Ruby Application") and check_requirements(['ruby', 'gem', 'bundle']): @@ -687,6 +694,7 @@ def spawn_app(app, deltas={}): app_path = join(APP_ROOT, app) procfile = join(app_path, 'Procfile') workers = parse_procfile(procfile) + workers.pop("preflight", None) workers.pop("release", None) ordinals = defaultdict(lambda: 1) worker_count = {k: 1 for k in workers.keys()}