Skip to content

Commit

Permalink
switch dependency management and package installation to poetry (#1304)
Browse files Browse the repository at this point in the history
* Replace setup.py and requirements files with pyproject.toml and poetry

* Switch Dockerfiles, tox, and CI over to using Poetry instead of pip for dependency and package installation

* Fix formatting issues after upgrading black
  • Loading branch information
bhearsum authored Apr 11, 2023
1 parent a83af31 commit 5895649
Show file tree
Hide file tree
Showing 34 changed files with 3,276 additions and 1,666 deletions.
10 changes: 5 additions & 5 deletions api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ RUN groupadd --gid 10001 app && \

WORKDIR /app

COPY requirements/ /app/requirements/
RUN pip install -r requirements/base.txt
COPY requirements/poetry.txt /tmp/poetry.txt
RUN pip install -r /tmp/poetry.txt

COPY . /app
RUN APP_TYPE="admin" pip install -e .

ENV FLASK_APP shipit_api.admin.flask:app
ENV WEB_CONCURRENCY=3
USER app

CMD ["/app/docker.d/init.sh"]
RUN poetry install --only main

CMD ["/app/docker.d/init.sh", "admin"]
11 changes: 5 additions & 6 deletions api/Dockerfile.public
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@ RUN groupadd --gid 10001 app && \

WORKDIR /app

COPY requirements/ /app/requirements/
RUN pip install -r requirements/public.txt
COPY requirements/poetry.txt /tmp/poetry.txt
RUN pip install -r /tmp/poetry.txt

COPY docker.d/init.sh /app/docker.d/
COPY . /app
RUN pip install -e .

ENV FLASK_APP shipit_api.public.flask:app
ENV WEB_CONCURRENCY=3
USER app

CMD ["/app/docker.d/init.sh"]
RUN poetry install --only main

CMD ["/app/docker.d/init.sh", "public"]
12 changes: 8 additions & 4 deletions api/Dockerfile.test
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@ ARG PYTHON_VERSION

FROM python:${PYTHON_VERSION}

COPY requirements/poetry.txt /tmp/poetry.txt
RUN pip install -r /tmp/poetry.txt

WORKDIR /app

COPY MANIFEST.in setup.py tox.ini /app/
COPY requirements/ /app/requirements/
COPY pyproject.toml /app/

RUN poetry install --only tox --no-root

RUN pip install -r requirements/local.txt
COPY tox.ini /app/

COPY src/ /app/src/

ENTRYPOINT ["/usr/local/bin/tox", "-e"]
ENTRYPOINT ["/usr/local/bin/poetry", "run", "tox", "-e"]
22 changes: 0 additions & 22 deletions api/MANIFEST.in

This file was deleted.

15 changes: 13 additions & 2 deletions api/docker.d/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ pushd `dirname $0` &>/dev/null
MY_DIR=$(pwd)
popd &>/dev/null

if [ $1 == "public" ]; then
export FLASK_APP="shipit_api.public.flask:app"
elif [ $1 == "admin" ]; then
export FLASK_APP="shipit_api.admin.flask:app"
else
echo "first arg must be 'public' or 'admin'"
exit 1
fi

EXTRA_ARGS=""
if [ "$APP_CHANNEL" == "development" ]
then
Expand All @@ -14,7 +23,9 @@ then
key="${MY_DIR}/key.pem"

# Local development only - we don't want these in deployed environments
EXTRA_ARGS="--bind $HOST:$PORT --workers 3 --timeout 3600 --reload --reload-engine=poll --certfile=$cert --keyfile=$key"
# More than 1 worker causes race conditions when migrating the database.
# They resolve themselves after a restart...but it's preferable not to have them at all.
EXTRA_ARGS="--bind $HOST:$PORT --workers 1 --timeout 3600 --reload --reload-engine=poll --certfile=$cert --keyfile=$key"
fi

exec /usr/local/bin/gunicorn $FLASK_APP --log-file - $EXTRA_ARGS
exec poetry run gunicorn $FLASK_APP --log-file - $EXTRA_ARGS
1 change: 0 additions & 1 deletion api/maintenance/README.md

This file was deleted.

14 changes: 0 additions & 14 deletions api/maintenance/pin-helper.sh

This file was deleted.

9 changes: 0 additions & 9 deletions api/maintenance/pin.sh

This file was deleted.

2,512 changes: 2,512 additions & 0 deletions api/poetry.lock

Large diffs are not rendered by default.

82 changes: 82 additions & 0 deletions api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,85 @@ use_parentheses=true

[tool.coverage.run]
omit = ["api/tests/*"]

[tool.poetry]
name = "shipit-api"
version = "1.0.0"
description = ""
authors = ["Release Engineering <releng@mozilla.com>"]
license = "MPL2"
packages = [
{include = "backend_common", from = "src"},
{include = "cli_common", from = "src"},
{include = "shipit_api", from = "src"},
]

[tool.poetry.scripts]
shipit_upload_product_details = "shipit_api.admin.cli:download_product_details"
shipit_rebuild_product_details = "shipit_api.admin.cli:rebuild_product_details"
shipit_import = "shipit_api.admin.cli:shipit_import"
shipit_trigger_product_details = "shipit_api.admin.cli:trigger_product_details"

[tool.poetry.dependencies]
# Required by both public and admin apps
python = "^3.9"
connexion = {version = "*", extras = ["swagger-ui"]}
dockerflow = "*"
flask = "*"
flask_cors = "*"
flask_migrate = "*"
flask_talisman = "*"
# flask_oidc imports JSONWebSignatureSerializer which was removed in 2.1+
# https://github.com/pallets/itsdangerous/pull/273
itsdangerous = "<2.1"
mozilla-version = "*"
python-decouple = "*"
sentry-sdk = {version = "*", extras = ["flask"]}
slugid = "*"
sqlalchemy = "<=1.4.44"
# deployment
gunicorn = "*"
psycopg2 = "*"

# Required only by the admin app
aioamqp = "*"
aiohttp = {version = "*", extras = ["speedup"]}
arrow = "*"
backoff = "*"
# to support signals in Flask
blinker = "*"
flask_login = "*"
flask_oidc = "*"
json-e = "*"
kombu = "*"
mohawk = "*"
mypy = "*"
mypy_extensions = "*"
pyyaml = "*"
taskcluster = "*"

[tool.poetry.group.test.dependencies]
python = "^3.9"
aioresponses = "*"
responses = "*"
pytest = "*"
pytest-asyncio = "*"
pytest-cov = "*"
black = "*"
check-manifest = "*"
isort = "*"
coverage = "*"
dpath = "*"
flake8 = "*"
openapi-spec-validator = "*"
oyaml = "*"

[tool.poetry.group.ccov-upload.dependencies]
requests = "*"

[tool.poetry.group.tox.dependencies]
tox = "*"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
3 changes: 3 additions & 0 deletions api/requirements/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Requirements files are only used to get Poetry installed. From there, Poetry handles all of the application-specific packages, dependencies, et. al.

To pick up a new version of Poetry, run `pip-compile -r poetry.in --generate-hashes`.
21 changes: 0 additions & 21 deletions api/requirements/base.in

This file was deleted.

Loading

0 comments on commit 5895649

Please sign in to comment.