Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix & improve docker usage #74

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion discogs_alert/util/currency.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
CurrencyRates = Dict[str, float]

# Directory in which to store weekly CurrencyRates JSON caches
CACHE_DIR = pathlib.Path(__file__).parent.parent.parent.resolve() / ".currency_cache"
CACHE_DIR = os.getenv(
"DA_CURRENCY_CACHE_DIR", pathlib.Path(__file__).parent.parent.parent.resolve() / ".currency_cache"
)


class InvalidCurrencyException(Exception):
Expand Down
26 changes: 19 additions & 7 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,41 @@ RUN python -m venv /venv
RUN . /venv/bin/activate

# install Poetry (respects $POETRY_VERSION & $POETRY_HOME)
ENV POETRY_VERSION=1.3.2
ENV POETRY_VERSION=1.8.0
RUN pip install "poetry==$POETRY_VERSION"

# install chromium binary and matching chromedriver binary (+ gcc for installing e.g. psutil)
RUN apt-get update && apt-get install -y --no-install-recommends chromium-driver gcc python3-dev

# install dependences & create build version of package
COPY pyproject.toml poetry.lock ./
RUN poetry install --no-dev --no-root
COPY . .
RUN poetry build

# install chromium binary and matching chromedriver binary
RUN apt-get update && apt-get install -y --no-install-recommends chromium-driver


# create lightweight 'final' stage with which to run discogs alert
FROM python-base as final

# copy everything we need & install `discogs_alert` from whl
COPY --from=builder /venv /venv
COPY --from=builder /dist .
COPY --from=builder /usr/bin/chromium /usr/bin/chromium
COPY --from=builder /usr/bin/chromedriver /usr/bin/chromedriver

# install chromium-driver, gcc, python3-dev (the latter two so that psutil can be installed)
# ideally we'd just copy the builds over (that are already installed above), but that doesn't seem to work ...
# COPY --from=builder /usr/bin/chromium /usr/bin/chromium
# COPY --from=builder /usr/bin/chromedriver /usr/bin/chromedriver
# COPY --from=builder /usr/bin/gcc /usr/bin/gcc
# COPY --from=builder /usr/bin/python3-config /usr/bin/python3-config
RUN apt-get update && apt-get install -y --no-install-recommends chromium-driver gcc python3-dev \
&& apt-get clean && rm -rf /var/lib/apt/lists/*

RUN . /venv/bin/activate && pip install *.whl

# Create a directory in which to cache current conversion dicts
ENV DA_CURRENCY_CACHE_DIR=/.currency_cache
RUN mkdir $DA_CURRENCY_CACHE_DIR

# run entrypoint
COPY ./docker/docker-entrypoint.sh ./
CMD ["./docker-entrypoint.sh"]
ENTRYPOINT ["./docker-entrypoint.sh"]
7 changes: 3 additions & 4 deletions docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/bin/sh

set -e

. /home/discogs_alert/venv/bin/activate

exec python -m discogs_alert
. /venv/bin/activate
echo Your container args are "$@"
python -m discogs_alert "$@"
Loading