mirror of
https://github.com/jokob-sk/NetAlertX.git
synced 2025-12-06 17:15:38 -08:00
expand initial filesystem
This commit is contained in:
93
Dockerfile
93
Dockerfile
@@ -11,19 +11,10 @@ RUN apk add --no-cache bash shadow python3 python3-dev gcc musl-dev libffi-dev o
|
||||
# Enable venv
|
||||
ENV PATH="/opt/venv/bin:$PATH"
|
||||
|
||||
RUN mkdir -p ${INSTALL_DIR}
|
||||
COPY api ${INSTALL_DIR}/api
|
||||
COPY back ${INSTALL_DIR}/back
|
||||
COPY config ${INSTALL_DIR}/config
|
||||
COPY db ${INSTALL_DIR}/db
|
||||
COPY front ${INSTALL_DIR}/front
|
||||
COPY server ${INSTALL_DIR}/server
|
||||
|
||||
|
||||
RUN pip install openwrt-luci-rpc asusrouter asyncio aiohttp graphene flask flask-cors unifi-sm-api tplink-omada-client wakeonlan pycryptodome requests paho-mqtt scapy cron-converter pytz json2table dhcp-leases pyunifi speedtest-cli chardet python-nmap dnspython librouteros yattag zeroconf git+https://github.com/foreign-sub/aiofreepybox.git
|
||||
|
||||
RUN bash -c "find ${INSTALL_DIR} -type d -exec chmod 750 {} \;" \
|
||||
&& bash -c "find ${INSTALL_DIR} -type f -exec chmod 640 {} \;" \
|
||||
&& bash -c "find ${INSTALL_DIR} -type f \( -name '*.sh' -o -name '*.py' -o -name 'speedtest-cli' \) -exec chmod 750 {} \;"
|
||||
|
||||
# second stage
|
||||
FROM alpine:3.22 AS runner
|
||||
@@ -34,13 +25,10 @@ RUN addgroup -g 20211 netalertx && \
|
||||
adduser -u 20212 -G readonly -D -h /app readonly
|
||||
|
||||
ARG INSTALL_DIR=/app
|
||||
COPY --from=builder /opt/venv /opt/venv
|
||||
COPY --from=builder /usr/sbin/usermod /usr/sbin/groupmod /usr/sbin/
|
||||
|
||||
COPY install/alpine-docker/ /
|
||||
|
||||
# Enable venv
|
||||
ENV PATH="/opt/venv/bin:$PATH"
|
||||
ENV PATH="/opt/venv/bin:/usr/bin:/sbin:/bin:$PATH"
|
||||
|
||||
|
||||
|
||||
@@ -80,60 +68,40 @@ ENV PHP_FPM_CONFIG_FILE=/etc/php83/php-fpm.conf
|
||||
ENV PHP_WWW_CONF_FILE=/etc/php83/php-fpm.d/www.conf
|
||||
ENV SYSTEM_SERVICES=/services
|
||||
|
||||
RUN apk update --no-cache bash libbsd zip lsblk gettext-envsubst sudo mtr tzdata curl arp-scan iproute2 \
|
||||
iproute2-ss nmap nmap-scripts traceroute nbtscan openrc dbus net-tools net-snmp-tools bind-tools awake \
|
||||
ca-certificates sqlite php83 php83-fpm php83-cgi php83-curl php83-sqlite3 php83-session python3 nginx sudo && \
|
||||
rm -rf /var/cache/apk/* && \
|
||||
rm -f /etc/nginx/http.d/default.conf
|
||||
|
||||
RUN apk update --no-cache \
|
||||
&& apk add --no-cache bash libbsd zip lsblk gettext-envsubst sudo mtr tzdata \
|
||||
&& apk add --no-cache curl arp-scan iproute2 iproute2-ss nmap nmap-scripts traceroute nbtscan openrc dbus net-tools net-snmp-tools bind-tools awake ca-certificates \
|
||||
&& apk add --no-cache sqlite php83 php83-fpm php83-cgi php83-curl php83-sqlite3 php83-session \
|
||||
&& apk add --no-cache python3 nginx
|
||||
# Install from previous build stage
|
||||
COPY --from=builder /opt/venv /opt/venv
|
||||
COPY --from=builder /usr/sbin/usermod /usr/sbin/groupmod /usr/sbin/
|
||||
|
||||
# Simple copy of directory structure instead of individual files or complicated directory structure with RUN mkdir
|
||||
COPY install/alpine-docker/ /
|
||||
|
||||
COPY --from=builder --chown=netalertx:netalertx ${INSTALL_DIR}/ ${INSTALL_DIR}/
|
||||
# set this properly to handle recursive ownership changes
|
||||
RUN ln -s /usr/bin/awake /usr/bin/wakeonlan \
|
||||
&& rm -f /etc/nginx/http.d/default.conf
|
||||
RUN chmod -R a+x ${SYSTEM_SERVICES} /build/ /entrypoint.sh && \
|
||||
sh -c "find ${NETALERTX_APP} -type d -exec chmod 750 {} \;" && \
|
||||
sh -c "find ${NETALERTX_APP} -type f -exec chmod 640 {} \;" && \
|
||||
sh -c "find ${NETALERTX_APP} -type f \( -name '*.sh' -o -name 'speedtest-cli' \) -exec chmod 750 {} \;"
|
||||
|
||||
# Copy source
|
||||
COPY back ${INSTALL_DIR}/back
|
||||
COPY front ${INSTALL_DIR}/front
|
||||
COPY server ${INSTALL_DIR}/server
|
||||
RUN mkdir ${NETALERTX_API}
|
||||
|
||||
# Create required directories
|
||||
RUN mkdir -p ${INSTALL_DIR}/config ${INSTALL_DIR}/db ${INSTALL_DIR}/log/plugins
|
||||
|
||||
|
||||
|
||||
# Create empty log files and API files
|
||||
RUN touch ${LOG_APP} \
|
||||
&& touch ${LOG_EXECUTION_QUEUE} \
|
||||
&& touch ${LOG_APP_FRONT} \
|
||||
&& touch ${LOG_APP_PHP_ERRORS} \
|
||||
&& touch ${LOG_STDERR} \
|
||||
&& touch ${LOG_STDOUT} \
|
||||
&& touch ${LOG_DB_IS_LOCKED} \
|
||||
&& touch ${LOG_IP_CHANGES} \
|
||||
&& touch ${LOG_REPORT_OUTPUT_TXT} \
|
||||
&& touch ${LOG_REPORT_OUTPUT_HTML} \
|
||||
&& touch ${LOG_REPORT_OUTPUT_JSON} \
|
||||
&& touch ${NETALERTX_API}/user_notifications.json
|
||||
|
||||
# Setup services
|
||||
RUN mkdir -p ${SYSTEM_SERVICES}
|
||||
|
||||
# Install runtime dependencies
|
||||
|
||||
|
||||
|
||||
#initialize each service with the dockerfiles/init-*.sh scripts, once.
|
||||
RUN chmod +x /build/*.sh \
|
||||
&& /build/init-nginx.sh \
|
||||
&& /build/init-php-fpm.sh \
|
||||
&& /build/init-crond.sh \
|
||||
&& /build/init-backend.sh \
|
||||
&& rm -rf /build/*
|
||||
|
||||
# Create buildtimestamp.txt
|
||||
|
||||
RUN chmod +x ${SYSTEM_SERVICES}/*.sh /entrypoint.sh
|
||||
|
||||
# Setup config and db files
|
||||
RUN cp ${NETALERTX_BACK}/app.conf ${NETALERTX_CONFIG_FILE} && \
|
||||
cp ${NETALERTX_BACK}/app.db ${NETALERTX_DB_FILE}
|
||||
RUN sh /build/init-nginx.sh && \
|
||||
sh /build/init-php-fpm.sh && \
|
||||
sh /build/init-crond.sh && \
|
||||
sh /build/init-backend.sh && \
|
||||
rm -rf /build/*
|
||||
|
||||
|
||||
# set netalertx to allow sudoers for any command, no password
|
||||
@@ -147,7 +115,7 @@ RUN date +%s > ${INSTALL_DIR}/front/buildtimestamp.txt
|
||||
FROM runner AS hardened
|
||||
|
||||
# remove netalertx from sudoers
|
||||
RUN sed -i '/netalertx ALL=(ALL) NOPASSWD: ALL/d
|
||||
RUN sh -c "sed -i '/netalertx ALL=(ALL) NOPASSWD: ALL/d' /etc/sudoers"
|
||||
|
||||
RUN chown -R readonly:readonly ${NETALERTX_BACK} ${NETALERTX_FRONT} ${NETALERTX_SERVER} ${SYSTEM_SERVICES}
|
||||
RUN chmod -R 004 ${NETALERTX_BACK} ${NETALERTX_FRONT} ${NETALERTX_SERVER}
|
||||
@@ -160,10 +128,7 @@ RUN chown -R netalertx:netalertx ${NETALERTX_CONFIG} ${NETALERTX_DB} ${NETALERTX
|
||||
|
||||
|
||||
RUN chown readonly:readonly /
|
||||
RUN rm /usr/bin/sudo
|
||||
RUN touch /var/log/nginx/access.log /var/log/nginx/error.log
|
||||
RUN chown -R netalertx:netalertx /var/log/nginx /run/
|
||||
RUN chown -R netalertx:netalertx /var/lib/nginx
|
||||
RUN chown -R netalertx:netalertx /var/log/nginx /var/lib/nginx /run
|
||||
RUN echo -ne '#!/bin/bash\nexit 0\n' > /usr/bin/sudo && chmod +x /usr/bin/sudo
|
||||
|
||||
RUN find / -path /proc -prune -o -path /sys -prune -o -path /dev -prune -o -path /run -prune -o -path /var/log -prune -o -path /tmp -prune -o -group 0 -o -user 0 -exec chown readonly:readonly {} +
|
||||
|
||||
Reference in New Issue
Block a user