Skip to content

Commit dce0aec

Browse files
authored
Merge pull request #421 from uc-cdis/feat/al2-updates
Feat/al2 updates
2 parents 985a3c7 + 91fd164 commit dce0aec

21 files changed

+225
-532
lines changed

.secrets.baseline

+2-2
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
"filename": "bin/settings.py",
137137
"hashed_secret": "347cd9c53ff77d41a7b22aa56c7b4efaf54658e3",
138138
"is_verified": false,
139-
"line_number": 43
139+
"line_number": 51
140140
}
141141
],
142142
"docs/local_dev_environment.md": [
@@ -354,5 +354,5 @@
354354
}
355355
]
356356
},
357-
"generated_at": "2024-04-22T20:07:28Z"
357+
"generated_at": "2025-01-07T20:16:15Z"
358358
}

Dockerfile

+44-53
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,56 @@
1-
# To run:
2-
# - Create and fill out `creds.json`:
3-
# {
4-
# "fence_host": "",
5-
# "fence_username": "",
6-
# "fence_password": "",
7-
# "fence_database": "",
8-
# "db_host": "",
9-
# "db_username": "",
10-
# "db_password": "",
11-
# "db_database": "",
12-
# "gdcapi_secret_key": "",
13-
# "indexd_password": "",
14-
# "hostname": ""
15-
# }
16-
# - Build the image: `docker build . -t sheepdog -f Dockerfile`
17-
# - Run: `docker run -v /full/path/to/creds.json:/var/www/sheepdog/creds.json -p 81:80 sheepdog`
18-
# To check running container: `docker exec -it sheepdog /bin/bash`
19-
20-
FROM quay.io/cdis/python:python3.9-buster-2.0.0
1+
ARG AZLINUX_BASE_VERSION=master
2+
3+
# Base stage with python-build-base
4+
FROM quay.io/cdis/python-nginx-al:${AZLINUX_BASE_VERSION} AS base
215

226
ENV appname=sheepdog
237

24-
RUN pip install --upgrade pip poetry
25-
RUN apt-get update && apt-get install -y --no-install-recommends \
26-
build-essential libffi-dev musl-dev gcc libxml2-dev libxslt-dev \
27-
curl bash git vim
8+
WORKDIR /${appname}
289

29-
RUN mkdir -p /var/www/$appname \
30-
&& mkdir -p /var/www/.cache/Python-Eggs/ \
31-
&& mkdir /run/nginx/ \
32-
&& ln -sf /dev/stdout /var/log/nginx/access.log \
33-
&& ln -sf /dev/stderr /var/log/nginx/error.log \
34-
&& chown nginx -R /var/www/.cache/Python-Eggs/ \
35-
&& chown nginx /var/www/$appname
10+
RUN chown -R gen3:gen3 /${appname}
3611

37-
EXPOSE 80
12+
# Builder stage
13+
FROM base AS builder
3814

39-
WORKDIR /$appname
15+
RUN yum install -y \
16+
gcc \
17+
python3-devel \
18+
postgresql-devel \
19+
libpq-devel && \
20+
yum clean all
4021

41-
# copy ONLY poetry artifact, install the dependencies but not indexd
42-
# this will make sure than the dependencies is cached
43-
COPY poetry.lock pyproject.toml /$appname/
44-
RUN poetry config virtualenvs.create false \
45-
&& poetry install -vv --no-root --without dev --no-interaction \
46-
&& poetry show -v
22+
USER gen3
23+
24+
COPY --chown=gen3:gen3 . /${appname}
25+
26+
RUN poetry install -vv --without dev --no-interaction
4727

48-
# copy source code ONLY after installing dependencies
49-
COPY . /$appname
50-
COPY ./deployment/uwsgi/uwsgi.ini /etc/uwsgi/uwsgi.ini
51-
COPY ./bin/settings.py /var/www/$appname/settings.py
52-
COPY ./bin/confighelper.py /var/www/$appname/confighelper.py
28+
RUN git config --global --add safe.directory /${appname} && COMMIT=`git rev-parse HEAD` && echo "COMMIT=\"${COMMIT}\"" > /${appname}/version_data.py \
29+
&& VERSION=`git describe --always --tags` && echo "VERSION=\"${VERSION}\"" >> /${appname}/version_data.py
30+
31+
# Final stage
32+
FROM base
33+
34+
# Install runtime dependencies
35+
RUN yum install -y \
36+
gcc \
37+
python3-devel \
38+
postgresql-devel \
39+
libpq-devel && \
40+
yum clean all
41+
42+
# Copy poetry artifacts and install the dependencies
43+
COPY poetry.lock pyproject.toml /$appname/
44+
RUN poetry config virtualenvs.create false && \
45+
poetry install -vv --no-root --without dev --no-interaction && \
46+
poetry show -v
5347

54-
# install sheepdog
55-
RUN poetry config virtualenvs.create false \
56-
&& poetry install -vv --without dev --no-interaction \
57-
&& poetry show -v
48+
# Copy application files from the builder stage
49+
COPY --from=builder /${appname} /${appname}
5850

59-
RUN COMMIT=`git rev-parse HEAD` && echo "COMMIT=\"${COMMIT}\"" >$appname/version_data.py \
60-
&& VERSION=`git describe --always --tags` && echo "VERSION=\"${VERSION}\"" >>$appname/version_data.py
51+
# Switch to non-root user 'gen3' for the serving process
52+
USER gen3
6153

62-
WORKDIR /var/www/$appname
54+
WORKDIR /${appname}
6355

64-
RUN ls
65-
CMD /dockerrun.sh
56+
CMD ["/sheepdog/dockerrun.bash"]

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import sheepdog
2222
import datamodelutils
2323
from dictionaryutils import dictionary
2424
from gdcdictionary import gdcdictionary
25-
from gdcdatamodel import models, validators
25+
from gen3datamodel import models, validators
2626

2727
dictionary.init(gdcdictionary)
2828
datamodelutils.validators.init(validators)

bin/confighelper.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@ def load_json(file_name, app_name, search_folders=None):
4949
"""
5050
actual_files = find_paths(file_name, app_name, search_folders)
5151
if not actual_files:
52-
return None
52+
return {}
5353
with open(actual_files[0], "r") as reader:
5454
return json.load(reader)

bin/settings.py

+36-26
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from sheepdog.api import app, app_init
22
from os import environ
3-
import confighelper
3+
import os
4+
import bin.confighelper as confighelper
45

56
APP_NAME = "sheepdog"
67

@@ -12,49 +13,58 @@ def load_json(file_name):
1213
conf_data = load_json("creds.json")
1314
config = app.config
1415

15-
config["AUTH"] = "https://auth.service.consul:5000/v3/"
16-
config["AUTH_ADMIN_CREDS"] = None
17-
config["INTERNAL_AUTH"] = None
18-
1916
# ARBORIST deprecated, replaced by ARBORIST_URL
2017
# ARBORIST_URL is initialized in app_init() directly
2118
config["ARBORIST"] = "http://arborist-service/"
2219

23-
# Signpost: deprecated, replaced by index client.
24-
config["SIGNPOST"] = {
25-
"host": environ.get("SIGNPOST_HOST") or "http://indexd-service",
26-
"version": "v0",
27-
"auth": ("gdcapi", conf_data.get("indexd_password", "{{indexd_password}}")),
28-
}
2920
config["INDEX_CLIENT"] = {
30-
"host": environ.get("INDEX_CLIENT_HOST") or "http://indexd-service",
21+
"host": os.environ.get("INDEX_CLIENT_HOST") or "http://indexd-service",
3122
"version": "v0",
32-
"auth": ("gdcapi", conf_data.get("indexd_password", "{{indexd_password}}")),
23+
# The user should be "sheepdog", but for legacy reasons, we use "gdcapi" instead
24+
"auth": (
25+
(
26+
environ.get("INDEXD_USER", "gdcapi"),
27+
environ.get("INDEXD_PASS")
28+
or conf_data.get("indexd_password", "{{indexd_password}}"),
29+
)
30+
),
3331
}
34-
config["FAKE_AUTH"] = False
32+
3533
config["PSQLGRAPH"] = {
36-
"host": conf_data["db_host"],
37-
"user": conf_data["db_username"],
38-
"password": conf_data["db_password"],
39-
"database": conf_data["db_database"],
34+
"host": conf_data.get("db_host", os.environ.get("PGHOST", "localhost")),
35+
"user": conf_data.get("db_username", os.environ.get("PGUSER", "sheepdog")),
36+
"password": conf_data.get("db_password", os.environ.get("PGPASSWORD", "sheepdog")),
37+
"database": conf_data.get("db_database", os.environ.get("PGDB", "sheepdog")),
4038
}
4139

4240
config["FLASK_SECRET_KEY"] = conf_data.get("gdcapi_secret_key", "{{gdcapi_secret_key}}")
43-
config["PSQL_USER_DB_CONNECTION"] = "postgresql://%s:%s@%s:5432/%s" % tuple(
44-
[
45-
conf_data.get(key, key)
46-
for key in ["fence_username", "fence_password", "fence_host", "fence_database"]
47-
]
41+
fence_username = conf_data.get(
42+
"fence_username", os.environ.get("FENCE_DB_USER", "fence")
43+
)
44+
fence_password = conf_data.get(
45+
"fence_password", os.environ.get("FENCE_DB_PASS", "fence")
46+
)
47+
fence_host = conf_data.get("fence_host", os.environ.get("FENCE_DB_HOST", "localhost"))
48+
fence_database = conf_data.get(
49+
"fence_database", os.environ.get("FENCE_DB_DATABASE", "fence")
50+
)
51+
config["PSQL_USER_DB_CONNECTION"] = "postgresql://%s:%s@%s:5432/%s" % (
52+
fence_username,
53+
fence_password,
54+
fence_host,
55+
fence_database,
4856
)
4957

50-
config["USER_API"] = "https://%s/user" % conf_data["hostname"] # for use by authutils
58+
config["USER_API"] = "https://%s/user" % conf_data.get(
59+
"hostname", os.environ.get("CONF_HOSTNAME", "localhost")
60+
) # for use by authutils
5161
# use the USER_API URL instead of the public issuer URL to accquire JWT keys
5262
config["FORCE_ISSUER"] = True
53-
config["DICTIONARY_URL"] = environ.get(
63+
config["DICTIONARY_URL"] = os.environ.get(
5464
"DICTIONARY_URL",
5565
"https://s3.amazonaws.com/dictionary-artifacts/datadictionary/develop/schema.json",
5666
)
5767

5868
app_init(app)
5969
application = app
60-
application.debug = environ.get("GEN3_DEBUG") == "True"
70+
application.debug = os.environ.get("GEN3_DEBUG") == "True"

bin/setup_psqlgraph.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import logging
44
from sqlalchemy import create_engine
55

6-
from gdcdatamodel.models import *
6+
from gen3datamodel.models import *
77
from psqlgraph import create_all, Node, Edge
88

99

bin/setup_transactionlogs.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import argparse
77
from sqlalchemy import create_engine
8-
from gdcdatamodel.models.submission import Base
8+
from gen3datamodel.models.submission import Base
99

1010

1111
def setup(host, port, user, password, database, use_ssl=False):

deployment/uwsgi/uwsgi.ini

-32
This file was deleted.

deployment/wsgi/gunicorn.conf.py

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
wsgi_app = "bin.settings:application"
2+
bind = "0.0.0.0:8000"
3+
workers = 1
4+
preload_app = True
5+
user = "gen3"
6+
group = "gen3"
7+
timeout = 300
8+
keepalive = 2
9+
keepalive_timeout = 5

dockerrun.bash

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
nginx
4+
poetry run gunicorn -c "/sheepdog/deployment/wsgi/gunicorn.conf.py"

docs/local_dev_environment.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ For convenience, the minimal usage looks like the following:
195195
import datamodelutils
196196
from dictionaryutils import dictionary
197197
from gdcdictionary import gdcdictionary
198-
from gdcdatamodel import models, validators
198+
from gen3datamodel import models, validators
199199
from flask import Flask
200200
import sheepdog
201201

0 commit comments

Comments
 (0)