Skip to content

Commit

Permalink
Fix Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelhball committed Apr 4, 2024
1 parent 847a413 commit f738520
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
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 "$@"

0 comments on commit f738520

Please sign in to comment.