archives/Dockerfile

73 lines
2.0 KiB
Docker

FROM python:3.9 as base
MAINTAINER ben <ben@sudo.is>
ENV DEBIAN_FRONTEND noninteractive
ENV TZ UTC
ENV TERM=xterm-256color
RUN python3 -m pip install --upgrade pip
# needs wwwsudois as a dependency for the shared jinja
# need to make this nicer
# used to force running this step to pull new versions
# but it is also installed in the final stage and gets run if anything changed
ENV wwwsudois_version "v1.9.14"
RUN curl -fsSL https://apt.sudo.is/KEY.gpg | apt-key add - && \
echo "deb https://apt.sudo.is/ /" | tee /etc/apt/sources.list.d/sudois.list && \
apt-get update && \
apt-get install wwwsudois && \
apt-get clean
FROM base as builder
ARG BUILD_UID=1300
ENV PATH "$PATH:/home/builder/.local/bin"
WORKDIR /builder
RUN useradd -m -u ${BUILD_UID} -s /bin/bash builder
RUN chown builder:builder /builder
USER builder
RUN python3 -m pip install poetry
COPY pyproject.toml /builder
COPY poetry.lock /builder
COPY .flake8 /builder/
RUN poetry install --no-interaction --ansi --no-root
# copy the tests and code after installing dependencies
COPY tests /builder/tests/
COPY archives /builder/archives/
COPY README.md /builder/README.md
RUN poetry install --no-interaction --ansi
# should be in the jenkinsfile at some point
RUN poetry run pytest
RUN poetry run flake8
RUN poetry run isort . --check
RUN poetry build --no-interaction --ansi
RUN poetry export --without-hashes > /builder/requirements.txt
FROM base as final
RUN mkdir -p /archives /var/log/archives
COPY --from=builder /builder/requirements.txt /usr/local
RUN python3 -m pip install -r /usr/local/requirements.txt
COPY --from=builder /builder/dist/archives-*.tar.gz /tmp
RUN python3 -m pip install /tmp/archives-*.tar.gz && \
rm /tmp/archives-*.tar.gz && \
apt-get update && \
apt-get install wwwsudois && \
apt-get clean
COPY etc/archives.toml /etc/archives.toml
HEALTHCHECK --start-period=5s --interval=15s --timeout=1s \
CMD curl -f http://localhost:3333/api/ruok || exit 1
EXPOSE 3333/tcp
CMD ["archives"]