server/docker: use Alpine-based image for space savings

This commit is contained in:
Shyam Sunder 2019-09-29 18:39:16 -04:00
parent 6da18036a4
commit 4fe9c5f4ca
5 changed files with 45 additions and 20 deletions

View file

@ -2,6 +2,8 @@
.pylintrc .pylintrc
mypy.ini mypy.ini
# Python requirements files
requirements.txt
dev-requirements.txt dev-requirements.txt
# Docker build files # Docker build files

View file

@ -1,30 +1,44 @@
FROM python:3.6-slim FROM alpine:latest
WORKDIR /opt/app WORKDIR /opt/app
COPY requirements.txt ./requirements.txt
RUN \ RUN \
# Install ffmpeg apk --no-cache add \
apt-get -yqq update && \ python3 \
apt-get -yq install --no-install-recommends ffmpeg && \ dumb-init \
rm -rf /var/lib/apt/lists/* && \ ffmpeg \
# Install waitress py3-waitress \
pip3 install --no-cache-dir waitress && \ # from requirements.txt:
# Install app requirements py3-yaml \
pip3 install --no-cache-dir -r ./requirements.txt py3-psycopg2 \
py3-sqlalchemy \
COPY ./ /opt/app/ py3-certifi \
py3-numpy \
py3-pillow \
py3-pynacl \
py3-tz \
py3-rfc3339 \
&& \
pip3 install --no-cache-dir --disable-pip-version-check \
alembic \
"coloredlogs==5.0" \
"elasticsearch>=5.0.0,<7.0.0" \
"elasticsearch-dsl>=5.0.0,<7.0.0" \
&& exit 0
ARG PUID=1000 ARG PUID=1000
ARG PGID=1000 ARG PGID=1000
RUN \ RUN \
# Set users # Set users
mkdir -p /opt/app /data && \ mkdir -p /opt/app /data && \
groupadd -g ${PGID} app && \ addgroup -g ${PGID} app && \
useradd -d /opt/app -M -c '' -g app -r -u ${PUID} app && \ adduser -SDH -h /opt/app -g '' -G app -u ${PUID} app && \
chown -R app:app /opt/app /data chown -R app:app /opt/app /data
USER app USER app
ENV PORT=6666 COPY --chown=app:app ./ /opt/app/
ARG PORT=6666
ENV PORT=${PORT}
EXPOSE ${PORT} EXPOSE ${PORT}
VOLUME ["/data/"] VOLUME ["/data/"]
CMD ["/opt/app/docker-start.sh"] CMD ["/opt/app/docker-start.sh"]

View file

@ -1,8 +1,8 @@
#!/bin/sh #!/usr/bin/dumb-init /bin/sh
set -e set -e
cd /opt/app cd /opt/app
alembic upgrade head alembic upgrade head
echo "Starting szurubooru API on port ${PORT}" echo "Starting szurubooru API on port ${PORT}"
exec waitress-serve --port ${PORT} szurubooru.facade:app exec waitress-serve-3 --port ${PORT} szurubooru.facade:app

View file

@ -10,7 +10,14 @@ ARG BASE_IMAGE
FROM ${BASE_IMAGE} FROM ${BASE_IMAGE}
WORKDIR /opt/app WORKDIR /opt/app
USER root USER root
RUN pip3 install --no-cache-dir pytest-cov freezegun RUN apk --no-cache add \
py3-pytest \
py3-pytest-cov \
&& \
pip3 install \
--no-cache-dir \
--disable-pip-version-check \
freezegun
USER app USER app
ENV POSTGRES_HOST=x \ ENV POSTGRES_HOST=x \
POSTGRES_USER=x \ POSTGRES_USER=x \
@ -20,4 +27,6 @@ CMD ["pytest", "szurubooru/", \
"--cov-report=term-missing", "--cov=szurubooru", "--tb=short"] "--cov-report=term-missing", "--cov=szurubooru", "--tb=short"]
EOF EOF
docker run --rm -t ${IMAGE_NAME}-test docker run --rm -t ${IMAGE_NAME}-test
exit $?

View file

@ -8,6 +8,6 @@ elasticsearch-dsl>=5.0.0,<7.0.0
certifi>=2017.11.5 certifi>=2017.11.5
numpy>=1.8.2 numpy>=1.8.2
pillow>=4.3.0 pillow>=4.3.0
pynacl==1.2.1 pynacl>=1.2.1
pytz>=2018.3 pytz>=2018.3
pyRFC3339>=1.0 pyRFC3339>=1.0