shynet/Dockerfile
Fidel Ramos 96c9c0feec
Fix SQLite support (#210)
SQLite DB was not writable because it was always located in
/usr/src/shynet/, which is owned by root and not writable by
appuser. SQLite needs the parent directory containing the DB file to be
writable by the running user.

The applied fix is to place the DB file in /var/local/shynet/db and to
create that directory in the Docker image with the right permissions.

SQLite setup is now documented in README as an alternative to Postgres.
2022-05-24 12:38:27 -07:00

54 lines
1.8 KiB
Docker

FROM python:alpine3.14
# Getting things ready
WORKDIR /usr/src/shynet
# Install dependencies & configure machine
ARG GF_UID="500"
ARG GF_GID="500"
RUN apk update && \
apk add gettext curl bash npm libffi-dev rust cargo
# libffi-dev and rust are used for the cryptography package,
# which we indirectly rely on. Necessary for aarch64 support.
# Collect GeoIP Database
RUN curl -m 180 "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-ASN&license_key=kKG1ebhL3iWVd0iv&suffix=tar.gz" | tar -xvz -C /tmp && \
curl -m 180 "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key=kKG1ebhL3iWVd0iv&suffix=tar.gz" | tar -xvz -C /tmp && \
mv /tmp/GeoLite2*/*.mmdb /etc && \
apk del curl
# Move dependency files
COPY poetry.lock pyproject.toml ./
COPY package.json package-lock.json ../
# Django expects node_modules to be in its parent directory.
# Install more dependencies
RUN apk add --no-cache postgresql-libs && \
apk add --no-cache --virtual .build-deps gcc musl-dev postgresql-dev && \
npm i -P --prefix .. && \
pip install poetry==1.1.7
# Install Python dependencies
RUN poetry config virtualenvs.create false && \
poetry install --no-dev --no-interaction --no-ansi
# Cleanup dependencies & setup user group
RUN apk --purge del .build-deps && \
rm -rf /var/lib/apt/lists/* && \
rm /var/cache/apk/* && \
addgroup --system -g $GF_GID appgroup && \
adduser appuser --system --uid $GF_UID -G appgroup && \
mkdir -p /var/local/shynet/db/ && \
chown -R appuser:appgroup /var/local/shynet
# Install Shynet
COPY shynet .
RUN python manage.py collectstatic --noinput && \
python manage.py compilemessages
# Launch
USER appuser
EXPOSE 8080
HEALTHCHECK CMD bash -c 'wget -o /dev/null -O /dev/null --header "Host: ${ALLOWED_HOSTS%%,*}" "http://127.0.0.1:$PORT/healthz/?format=json"'
CMD [ "./entrypoint.sh" ]