Skip to content

Commit 2e79473

Browse files
authored
Add poetry (#15)
1 parent 6ec6bc8 commit 2e79473

17 files changed

+1728
-53
lines changed

setup.cfg renamed to .flake8

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
[tool:pytest]
2-
addopts = --verbose --strict-markers -p no:doctest
3-
norecursedirs=.git,.venv
4-
51
[flake8]
62
count = True
73
max-line-length=127

.github/workflows/poetry.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Python tests
2+
on:
3+
pull_request:
4+
push:
5+
branches: [main]
6+
jobs:
7+
ci:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- uses: actions/checkout@v3
11+
- uses: actions/setup-python@v4
12+
with:
13+
python-version: '3.10'
14+
- name: Run image
15+
uses: abatilo/actions-poetry@v2
16+
with:
17+
poetry-version: '1.3.2'
18+
- name: Install dependencies
19+
run: poetry install
20+
- name: Run tests
21+
run: poetry run pytest

Dockerfile

Lines changed: 92 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,95 @@
1-
FROM python:3.9.12-bullseye
1+
# Reference: https://bmaingret.github.io/blog/2021-11-15-Docker-and-Poetry#multi-stage-build
22

3-
COPY . /publisher
4-
WORKDIR /publisher
3+
ARG APP_NAME=example-publisher
4+
ARG APP_PACKAGE=example_publisher
5+
ARG APP_PATH=/opt/$APP_NAME
6+
ARG PYTHON_VERSION=3.10.4
7+
ARG POETRY_VERSION=1.2.2
58

6-
RUN pip install --upgrade setuptools pip && pip install -e .
9+
#
10+
# Stage: base
11+
#
712

8-
CMD ["python", "-m", "publisher", "--config", "config/config.toml"]
13+
FROM python:$PYTHON_VERSION as base
14+
15+
ARG APP_NAME
16+
ARG APP_PATH
17+
ARG POETRY_VERSION
18+
19+
ENV \
20+
PYTHONDONTWRITEBYTECODE=1 \
21+
PYTHONUNBUFFERED=1 \
22+
PYTHONFAULTHANDLER=1
23+
ENV \
24+
POETRY_VERSION=$POETRY_VERSION \
25+
POETRY_HOME="/opt/poetry" \
26+
POETRY_VIRTUALENVS_IN_PROJECT=true \
27+
POETRY_NO_INTERACTION=1
28+
29+
# Install Poetry - respects $POETRY_VERSION & $POETRY_HOME
30+
RUN curl -sSL https://github.com/python-poetry/poetry/master/install-poetry.py | python
31+
ENV PATH="$POETRY_HOME/bin:$PATH"
32+
33+
WORKDIR $APP_PATH
34+
COPY . .
35+
36+
#
37+
# Stage: development
38+
#
39+
40+
FROM base as development
41+
42+
ARG APP_NAME
43+
ARG APP_PATH
44+
45+
WORKDIR $APP_PATH
46+
RUN poetry install
47+
48+
ENV APP_NAME=$APP_NAME
49+
50+
ENTRYPOINT ["poetry", "run"]
51+
CMD ["$APP_NAME"]
52+
53+
#
54+
# Stage: build
55+
#
56+
57+
FROM base as build
58+
59+
ARG APP_NAME
60+
ARG APP_PATH
61+
62+
WORKDIR $APP_PATH
63+
RUN poetry build --format wheel
64+
RUN poetry export --format requirements.txt --output constraints.txt --without-hashes
65+
66+
#
67+
# Stage: production
68+
#
69+
70+
FROM python:$PYTHON_VERSION as production
71+
72+
ARG APP_NAME
73+
ARG APP_PATH
74+
75+
ENV \
76+
PYTHONDONTWRITEBYTECODE=1 \
77+
PYTHONUNBUFFERED=1 \
78+
PYTHONFAULTHANDLER=1
79+
80+
ENV \
81+
PIP_NO_CACHE_DIR=off \
82+
PIP_DISABLE_PIP_VERSION_CHECK=on \
83+
PIP_DEFAULT_TIMEOUT=100
84+
85+
# Get build artifact wheel and install it respecting dependency versions
86+
WORKDIR $APP_PATH
87+
COPY --from=build $APP_PATH/dist/*.whl ./
88+
COPY --from=build $APP_PATH/constraints.txt ./
89+
RUN pip install ./*.whl --requirement constraints.txt
90+
91+
COPY ./entrypoint.sh /entrypoint.sh
92+
RUN chmod +x /entrypoint.sh
93+
94+
ENTRYPOINT ["/entrypoint.sh"]
95+
CMD ["$APP_NAME"]

entrypoint.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/sh
2+
3+
set -e
4+
5+
eval "exec $@"
File renamed without changes.

publisher/__main__.py renamed to example_publisher/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import asyncio
22
import os
33
import sys
4-
from publisher.config import Config
5-
from publisher.publisher import Publisher
4+
from example_publisher.config import Config
5+
from example_publisher.publisher import Publisher
66
import typed_settings as ts
77
import click
88
import logging
File renamed without changes.
File renamed without changes.

publisher/providers/coin_gecko.py renamed to example_publisher/providers/coin_gecko.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from pycoingecko import CoinGeckoAPI
44
from structlog import get_logger
55

6-
from publisher.provider import Price, Provider, Symbol
6+
from example_publisher.provider import Price, Provider, Symbol
77
from ..config import CoinGeckoConfig
88

99
log = get_logger()

publisher/providers/pyth_replicator.py renamed to example_publisher/providers/pyth_replicator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from structlog import get_logger
99

10-
from publisher.provider import Price, Provider, Symbol
10+
from example_publisher.provider import Price, Provider, Symbol
1111

1212
from ..config import PythReplicatorConfig
1313

0 commit comments

Comments
 (0)