2022-01-01 02:26:57 +08:00
FROM python:alpine3.14
2020-04-14 22:55:01 +08:00
2020-05-03 22:41:14 +08:00
# Getting things ready
2020-04-14 22:55:01 +08:00
WORKDIR /usr/src/shynet
2020-05-03 05:14:30 +08:00
2020-05-03 22:41:14 +08:00
# Install dependencies & configure machine
ARG GF_UID = "500"
ARG GF_GID = "500"
2020-05-03 05:14:30 +08:00
RUN apk update && \
2021-07-20 12:51:13 +08:00
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 && \
2020-06-19 02:00:06 +08:00
curl -m 180 "https://download.maxmind.com/app/geoip_download?edition_id=GeoLite2-City&license_key=kKG1ebhL3iWVd0iv&suffix=tar.gz" | tar -xvz -C /tmp && \
2020-05-03 05:14:30 +08:00
mv /tmp/GeoLite2*/*.mmdb /etc && \
2021-07-20 12:51:13 +08:00
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 && \
2020-05-03 05:14:30 +08:00
apk add --no-cache --virtual .build-deps gcc musl-dev postgresql-dev && \
2020-06-28 10:58:49 +08:00
npm i -P --prefix .. && \
2021-07-20 12:51:13 +08:00
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 && \
2020-05-03 05:14:30 +08:00
rm -rf /var/lib/apt/lists/* && \
2020-05-03 22:41:14 +08:00
rm /var/cache/apk/* && \
2020-05-03 05:14:30 +08:00
addgroup --system -g $GF_GID appgroup && \
2022-05-25 03:38:27 +08:00
adduser appuser --system --uid $GF_UID -G appgroup && \
mkdir -p /var/local/shynet/db/ && \
chown -R appuser:appgroup /var/local/shynet
2020-04-14 22:55:01 +08:00
2020-05-03 22:41:14 +08:00
# Install Shynet
COPY shynet .
RUN python manage.py collectstatic --noinput && \
python manage.py compilemessages
# Launch
2020-04-14 22:55:01 +08:00
USER appuser
EXPOSE 8080
2021-10-01 07:12:57 +08:00
HEALTHCHECK CMD bash -c 'wget -o /dev/null -O /dev/null --header "Host: ${ALLOWED_HOSTS%%,*}" "http://127.0.0.1:$PORT/healthz/?format=json"'
2020-05-29 05:47:17 +08:00
CMD [ "./entrypoint.sh" ]