Skip to content

Commit

Permalink
Set up image deployment for seqcolapi
Browse files Browse the repository at this point in the history
  • Loading branch information
nsheff committed Feb 22, 2024
1 parent 14c6766 commit 6146b55
Show file tree
Hide file tree
Showing 14 changed files with 46 additions and 108 deletions.
31 changes: 20 additions & 11 deletions README_seqcolapi.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,44 @@ This repository contains:

### Run locally for development

To run a local server with a **local database**:
```
source servers/localhost/dev_local.env
uvicorn seqcolapi.main:app --reload --port 8100
```
First, configure env vars:
- To run a local server with a **local database**:`source servers/localhost/dev_local.env`
- To run a local server with **the production database**:`source servers/seqcolapi.databio.org/production.env`

Then, run service:

To run a local server with **the production database**:
```
source servers/seqcolapi.databio.org/production.env
uvicorn seqcolapi.main:app --reload --port 8100
```

### Running with docker

To build the docker file:
To build the docker file, from the root of this repository:

First you build the general-purpose image

```
docker build --no-cache -t scim .
docker build -f deployment/dockerhub/Dockerfile -t databio/seqcolapi seqcolapi
```

Next you build the wrapped image (this just wraps the config into the app):

```
docker build -f deployment/seqcolapi.databio.org/Dockerfile -t seqcolapi.databio.org deployment/seqcolapi.databio.org
```

To run in a container:

```
export POSTGRES_PASSWORD=`pass aws/rds_postgres`
source deployment/seqcolapi.databio.org/production.env
docker run --rm -p 8000:80 --name seqcolapi seqcolapi.databio.org
```


docker run --rm -p 8000:8000 --name sccon \
--env "POSTGRES_PASSWORD" \
--volume $CODE/seqcolapi.databio.org/config/seqcolapi.yaml:/config.yaml \
scim seqcolapi serve -c /config.yaml -p 8000
scim
```
To deploy container to dockerhub:
Expand Down
11 changes: 11 additions & 0 deletions deployment/dockerhub/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM tiangolo/uvicorn-gunicorn:python3.11-slim
LABEL authors="Nathan Sheffield"
RUN pip install https://github.com/databio/yacman/archive/dev.zip
RUN pip install https://github.com/refgenie/refget/archive/seqcolapi.zip

COPY requirements/requirements-seqcolapi.txt requirements/requirements-seqcolapi.txt
RUN pip install -r requirements/requirements-seqcolapi.txt --no-cache-dir

COPY . /app/seqcolapi

CMD ["uvicorn", "seqcolapi.main:app", "--host", "0.0.0.0", "--port", "80"]
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions deployment/seqcolapi.databio.org/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM databio/seqcolapi
COPY seqcolapi.yaml /seqcolapi_config.yaml
ENV SEQCOLAPI_CONFIG /seqcolapi_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ export POSTGRES_TABLE="seqcol"

export SEQCOLAPI_PORT="5432"
export SERVER_ENV="production"
export SEQCOLAPI_CONFIG="servers/seqcolapi.databio.org/seqcolapi.yaml"
export SEQCOLAPI_CONFIG="deployment/seqcolapi.databio.org/seqcolapi.yaml"
21 changes: 0 additions & 21 deletions refget/seqcol.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import henge
import logging
import yacman

from itertools import compress

Expand All @@ -12,26 +11,6 @@
henge.ITEM_TYPE = "_item_type"


class SeqColConf(yacman.YAMLConfigManager):
"""
Simple configuration manager object for SeqColHenge.
"""

def __init__(
self,
entries={},
filepath=None,
yamldata=None,
writable=False,
wait_max=60,
skip_read_lock=False,
):
filepath = yacman.select_config(
config_filepath=filepath, config_env_vars=["SEQCOLAPI_CONFIG"], config_name="seqcol"
)
super(SeqColConf, self).__init__(entries, filepath, yamldata, writable)


class SeqColHenge(henge.Henge):
"""
Extension of henge that accommodates collections of sequences.
Expand Down
3 changes: 0 additions & 3 deletions seqcolapi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
import logmuse

logmuse.init_logger("seqcolapi")
59 changes: 0 additions & 59 deletions seqcolapi/cli.py

This file was deleted.

17 changes: 10 additions & 7 deletions seqcolapi/main.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import henge
import json
import logging
import logmuse
import os
import sys
import uvicorn
Expand All @@ -17,12 +16,15 @@
from starlette.staticfiles import StaticFiles
from typing import Union

from .cli import build_parser
from .const import *
from .scconf import RDBDict
from .examples import *

from refget import SeqColConf, SeqColHenge, format_itemwise
from refget import SeqColHenge, format_itemwise
from yacman import select_config, FutureYAMLConfigManager as YAMLConfigManager

class SeqColConf(YAMLConfigManager):
pass

global _LOGGER

Expand Down Expand Up @@ -124,7 +126,7 @@ def create_globals(scconf: yacman.YAMLConfigManager):
def main(injected_args=None):
# Entry point for running from console_scripts, installed package
parser = build_parser()
parser = logmuse.add_logging_options(parser)
# parser = logmuse.add_logging_options(parser)
args = parser.parse_args()
if injected_args:
args.__dict__.update(injected_args)
Expand All @@ -133,10 +135,10 @@ def main(injected_args=None):
print("No subcommand given")
sys.exit(1)

_LOGGER = logmuse.logger_via_cli(args, make_root=True)
# _LOGGER = logmuse.logger_via_cli(args, make_root=True)
_LOGGER.info(f"args: {args}")
if "config" in args and args.config is not None:
scconf = SeqColConf(filepath=args.config)
scconf = SeqColConf.from_yaml_file(args.config)
create_globals(scconf)
app.state.schenge = schenge
port = args.port or scconf.exp["server"]["port"]
Expand All @@ -149,7 +151,8 @@ def main(injected_args=None):
if __name__ != "__main__":
# Entrypoint for running through uvicorn CLI (dev)
if os.environ.get("SEQCOLAPI_CONFIG") is not None:
scconf = SeqColConf()
_LOGGER.info(f"Loading config from SEQCOLAPI_CONFIG: {os.environ.get('SEQCOLAPI_CONFIG')}")
scconf = SeqColConf.from_yaml_file(os.environ.get('SEQCOLAPI_CONFIG'))
create_globals(scconf)
app.state.schenge = schenge
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ aiofiles
fastapi
henge>=0.2.1
jinja2
logmuse>=0.2
pipestat
psycopg2-binary
refget
uvicorn>=0.7.1
Expand Down
5 changes: 0 additions & 5 deletions servers/seqcolapi.databio.org/Dockerfile

This file was deleted.

0 comments on commit 6146b55

Please sign in to comment.