diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index bc116cd..223fd93 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -43,6 +43,9 @@ jobs: matrix: python-version: ["3.9", "3.10", "3.11"] + env: + SEQREPO_EB_PROD: true + steps: - uses: actions/checkout@v4 diff --git a/Procfile b/Procfile index 3ceba4b..103aa6f 100644 --- a/Procfile +++ b/Procfile @@ -1 +1 @@ -web: seqrepo-rest-service /usr/local/share/seqrepo/2024-02-20 \ No newline at end of file +web: cd src && gunicorn seqrepo_rest_service.cli:app --bind 0.0.0.0:5000 \ No newline at end of file diff --git a/cron.yaml b/cron.yaml deleted file mode 100644 index 206f9d1..0000000 --- a/cron.yaml +++ /dev/null @@ -1,5 +0,0 @@ -version: 1 -cron: - - name: "task1" - url: "/scheduled" - schedule: "* * * * *" \ No newline at end of file diff --git a/src/seqrepo_rest_service/cli.py b/src/seqrepo_rest_service/cli.py index 313d987..e985ad6 100644 --- a/src/seqrepo_rest_service/cli.py +++ b/src/seqrepo_rest_service/cli.py @@ -37,23 +37,30 @@ def _parse_opts(): return opts +cxapp = connexion.App(__name__, debug=True) + + def main(): coloredlogs.install(level="INFO") - if "SEQREPO_DIR" in os.environ: - _logger.warn("SEQREPO_DIR environment variable is now ignored") + if "SEQREPO_EB_PROD" in os.environ: + # AWS Elastic Beanstalk env + seqrepo_dir = os.environ.get("SEQREPO_ROOT_DIR", "/usr/local/share/seqrepo/2024-02-20") + else: + # Local env + if "SEQREPO_ROOT_DIR" in os.environ: + _logger.warn("SEQREPO_ROOT_DIR environment variable is now ignored") - opts = _parse_opts() + opts = _parse_opts() - seqrepo_dir = opts.SEQREPO_INSTANCE_DIR - if opts.wait_for_path: - while not seqrepo_dir.exists(): - _logger.info(f"{seqrepo_dir}: waiting for existence") - time.sleep(WAIT_POLL_PERIOD) - _logger.info(f"{seqrepo_dir}: path found") - _ = SeqRepo(seqrepo_dir.as_posix()) # test opening + seqrepo_dir = opts.SEQREPO_INSTANCE_DIR + if opts.wait_for_path: + while not seqrepo_dir.exists(): + _logger.info(f"{seqrepo_dir}: waiting for existence") + time.sleep(WAIT_POLL_PERIOD) + _logger.info(f"{seqrepo_dir}: path found") + _ = SeqRepo(seqrepo_dir.as_posix()) # test opening - cxapp = connexion.App(__name__, debug=True) cxapp.app.url_map.strict_slashes = False cxapp.app.config["seqrepo_dir"] = seqrepo_dir @@ -79,8 +86,11 @@ def refget_ui(): return redirect("/refget/1/ui/") _logger.info("Also watching " + str(spec_files)) - cxapp.run(host="0.0.0.0", extra_files=spec_files) + return cxapp.app, spec_files + + +app, spec_files = main() if __name__ == "__main__": - main() + app.run(host="0.0.0.0", extra_files=spec_files)