mirror of
https://github.com/bunkerity/bunkerized-nginx
synced 2023-12-13 21:30:18 +01:00
91 lines
3.9 KiB
Docker
91 lines
3.9 KiB
Docker
FROM python:3.12.0-alpine3.18@sha256:f1d0d03700fb2d4480e89fb807e7346c14b88952f7bd58d56de54a24817cc2e8 AS builder
|
|
|
|
# Install python dependencies
|
|
RUN apk add --no-cache --virtual .build-deps g++ gcc musl-dev jpeg-dev zlib-dev libffi-dev cairo-dev pango-dev gdk-pixbuf-dev openssl-dev cargo postgresql-dev
|
|
|
|
# Copy python requirements
|
|
COPY src/deps/requirements.txt /tmp/requirements-deps.txt
|
|
COPY src/scheduler/requirements.txt /tmp/req/requirements.txt
|
|
COPY src/common/gen/requirements.txt /tmp/req/requirements.txt.1
|
|
COPY src/common/db/requirements.txt /tmp/req/requirements.txt.2
|
|
|
|
WORKDIR /usr/share/bunkerweb
|
|
|
|
RUN mkdir -p deps/python && \
|
|
cat /tmp/req/requirements.txt* > deps/requirements.txt && \
|
|
rm -rf /tmp/req
|
|
|
|
# Install python requirements
|
|
RUN export MAKEFLAGS="-j$(nproc)" && \
|
|
pip install --no-cache-dir --ignore-installed --require-hashes -r /tmp/requirements-deps.txt && \
|
|
pip install --no-cache-dir --require-hashes --target deps/python -r deps/requirements.txt
|
|
|
|
# Remove build dependencies
|
|
RUN apk del .build-deps && \
|
|
rm -rf /var/cache/apk/*
|
|
|
|
# Copy files
|
|
# can't exclude specific files/dir from . so we are copying everything by hand
|
|
COPY src/common/api api
|
|
COPY src/common/cli cli
|
|
COPY src/common/confs confs
|
|
COPY src/common/db db
|
|
COPY src/common/core core
|
|
COPY src/common/gen gen
|
|
COPY src/common/helpers helpers
|
|
COPY src/common/settings.json settings.json
|
|
COPY src/common/utils utils
|
|
COPY src/scheduler scheduler
|
|
COPY src/VERSION VERSION
|
|
|
|
FROM python:3.12.0-alpine3.18@sha256:f1d0d03700fb2d4480e89fb807e7346c14b88952f7bd58d56de54a24817cc2e8
|
|
|
|
# Set default umask to prevent huge recursive chmod increasing the final image size
|
|
RUN umask 027
|
|
|
|
# Copy dependencies
|
|
COPY --from=builder --chown=0:101 /usr/share/bunkerweb /usr/share/bunkerweb
|
|
|
|
WORKDIR /usr/share/bunkerweb
|
|
|
|
# Add scheduler user, drop bwcli, install runtime dependencies, create data folders and set permissions
|
|
RUN apk add --no-cache bash libgcc libstdc++ libpq openssl libmagic && \
|
|
ln -s /usr/local/bin/python3 /usr/bin/python3 && \
|
|
addgroup -g 101 scheduler && \
|
|
adduser -h /var/cache/nginx -g scheduler -s /bin/sh -G scheduler -D -H -u 101 scheduler && \
|
|
cp helpers/bwcli /usr/bin/ && \
|
|
echo "Docker" > INTEGRATION && \
|
|
mkdir -p /etc/nginx && \
|
|
mkdir -p /var/tmp/bunkerweb && \
|
|
mkdir -p /var/run/bunkerweb && \
|
|
mkdir -p /var/log/bunkerweb && \
|
|
mkdir -p /var/www && \
|
|
mkdir -p /etc/bunkerweb && \
|
|
mkdir -p /data/cache && ln -s /data/cache /var/cache/bunkerweb && \
|
|
mkdir -p /data/lib && ln -s /data/lib /var/lib/bunkerweb && \
|
|
for dir in $(echo "configs plugins") ; do mkdir -p "/data/${dir}" && ln -s "/data/${dir}" "/etc/bunkerweb/${dir}" ; done && \
|
|
for dir in $(echo "configs/http configs/stream configs/server-http configs/server-stream configs/default-server-http configs/default-server-stream configs/modsec configs/modsec-crs") ; do mkdir "/data/${dir}" ; done && \
|
|
chown -R root:scheduler /data /etc/nginx /var/cache/bunkerweb /var/lib/bunkerweb /etc/bunkerweb /var/tmp/bunkerweb /var/run/bunkerweb /var/log/bunkerweb /usr/bin/bwcli && \
|
|
chmod -R 770 /data /etc/nginx /var/cache/bunkerweb /var/lib/bunkerweb /etc/bunkerweb /var/tmp/bunkerweb /var/run/bunkerweb /var/log/bunkerweb && \
|
|
find core/*/jobs/* -type f -exec chmod 750 {} \; && \
|
|
chmod 750 cli/main.py gen/*.py scheduler/main.py scheduler/entrypoint.sh helpers/*.sh deps/python/bin/* /usr/bin/bwcli && \
|
|
chmod 660 INTEGRATION && \
|
|
chown root:scheduler INTEGRATION
|
|
|
|
COPY --chown=root:scheduler src/bw/misc/asn.mmdb /var/tmp/bunkerweb/asn.mmdb
|
|
COPY --chown=root:scheduler src/bw/misc/country.mmdb /var/tmp/bunkerweb/country.mmdb
|
|
|
|
RUN chmod 770 /var/tmp/bunkerweb/asn.mmdb /var/tmp/bunkerweb/country.mmdb
|
|
|
|
# Fix CVEs
|
|
# There are no CVEs to fix in this image
|
|
|
|
VOLUME /data /etc/nginx
|
|
|
|
WORKDIR /usr/share/bunkerweb/scheduler
|
|
|
|
USER scheduler:scheduler
|
|
|
|
HEALTHCHECK --interval=10s --timeout=10s --start-period=30s --retries=6 CMD /usr/share/bunkerweb/helpers/healthcheck-scheduler.sh
|
|
|
|
ENTRYPOINT [ "./entrypoint.sh" ]
|