alpine re-base

This commit is contained in:
Jokob-sk
2024-03-02 08:58:38 +11:00
parent 9420c41e7c
commit ca2df744df
13 changed files with 130 additions and 109 deletions

View File

@@ -1,50 +1,53 @@
FROM debian:bookworm-slim FROM alpine:3.19 as builder
# default UID and GID ARG INSTALL_DIR=/home/pi
ENV USER=pi USER_ID=1000 USER_GID=1000 PORT=20211 ENV PYTHONUNBUFFERED 1
#TZ=Europe/London
# Todo, figure out why using a workdir instead of full paths don't work RUN apk add --no-cache bash python3 \
# Todo, do we still need all these packages? I can already see sudo which isn't needed && python -m venv /opt/venv
RUN apt-get update # Enable venv
RUN apt-get install sudo -y ENV PATH="/opt/venv/bin:$PATH"
COPY . ${INSTALL_DIR}/pialert/
# create pi user and group RUN pip install requests paho-mqtt scapy cron-converter pytz json2table dhcp-leases pyunifi speedtest-cli chardet \
# add root and www-data to pi group so they can r/w files and db && bash -c "find ${INSTALL_DIR} -type d -exec chmod 750 {} \;" \
RUN groupadd --gid "${USER_GID}" "${USER}" && \ && bash -c "find ${INSTALL_DIR} -type f -exec chmod 640 {} \;" \
useradd \ && bash -c "find ${INSTALL_DIR} -type f \( -name '*.sh' -o -name '*.py' -o -name 'pialert-cli' -o -name 'speedtest-cli' \) -exec chmod 750 {} \;"
--uid ${USER_ID} \
--gid ${USER_GID} \
--create-home \
--shell /bin/bash \
${USER} && \
usermod -a -G ${USER_GID} root && \
usermod -a -G ${USER_GID} www-data
COPY --chmod=775 --chown=${USER_ID}:${USER_GID} . /home/pi/pialert/ # second stage
FROM alpine:3.19 as runner
ARG INSTALL_DIR=/home/pi
COPY --from=builder /opt/venv /opt/venv
# Enable venv
ENV PATH="/opt/venv/bin:$PATH"
# default port and listen address
ENV PORT=20211 LISTEN_ADDR=0.0.0.0
# needed for s6-overlay
ENV S6_CMD_WAIT_FOR_SERVICES_MAXTIME=0
# ❗ IMPORTANT - if you modify this file modify the /install/install_dependecies.sh file as well ❗ # ❗ IMPORTANT - if you modify this file modify the /install/install_dependecies.sh file as well ❗
RUN apt-get install -y \ RUN apk update --no-cache \
tini snmp ca-certificates curl libwww-perl arp-scan perl apt-utils cron sudo \ && apk add --no-cache bash zip gettext-envsubst sudo mtr usbutils s6-overlay \
nginx-light php php-cgi php-fpm php-sqlite3 php-curl sqlite3 dnsutils net-tools \ && apk add --no-cache curl arp-scan iproute2 iproute2-ss nmap traceroute net-tools net-snmp-tools bind-tools awake ca-certificates \
python3 iproute2 nmap python3-pip zip systemctl usbutils traceroute && apk add --no-cache sqlite php82 php82-fpm php82-cgi php82-curl php82-sqlite3 php82-session \
&& apk add --no-cache python3 nginx \
&& ln -s /usr/bin/awake /usr/bin/wakeonlan \
&& bash -c "install -d -m 750 -o nginx -g www-data ${INSTALL_DIR} ${INSTALL_DIR}/pialert" \
&& rm -f /etc/nginx/http.d/default.conf
# Alternate dependencies COPY --from=builder --chown=nginx:www-data ${INSTALL_DIR}/pialert/ ${INSTALL_DIR}/pialert/
RUN apt-get install nginx nginx-core mtr php-fpm php8.2-fpm php-cli php8.2 php8.2-sqlite3 -y
RUN phpenmod -v 8.2 sqlite3
# Setup virtual python environment and use pip3 to install packages RUN /home/pi/pialert/dockerfiles/pre-setup.sh
RUN apt-get install -y python3-venv
RUN python3 -m venv myenv
RUN /bin/bash -c "source myenv/bin/activate && update-alternatives --install /usr/bin/python python /usr/bin/python3 10 && pip3 install requests paho-mqtt scapy cron-converter pytz json2table dhcp-leases pyunifi speedtest-cli chardet"
# Create a buildtimestamp.txt to later check if a new version was released
RUN date +%s > /home/pi/pialert/front/buildtimestamp.txt
CMD ["/home/pi/pialert/dockerfiles/start.sh"]
HEALTHCHECK --interval=30s --timeout=5s --start-period=0s --retries=2 \
CMD curl -sf -o /dev/null ${LISTEN_ADDR}:${PORT}/api/app_state.json
ENTRYPOINT ["/init"]

View File

@@ -1,51 +0,0 @@
FROM alpine:3.19 as builder
ARG INSTALL_DIR=/home/pi
ENV PYTHONUNBUFFERED 1
RUN apk add --no-cache bash python3 \
&& python -m venv /opt/venv
# Enable venv
ENV PATH="/opt/venv/bin:$PATH"
COPY . ${INSTALL_DIR}/pialert/
RUN pip install requests paho-mqtt scapy cron-converter pytz json2table dhcp-leases pyunifi speedtest-cli chardet \
&& 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 'pialert-cli' -o -name 'speedtest-cli' \) -exec chmod 750 {} \;"
# second stage
FROM alpine:3.19 as runner
ARG INSTALL_DIR=/home/pi
COPY --from=builder /opt/venv /opt/venv
# Enable venv
ENV PATH="/opt/venv/bin:$PATH"
# default port and listen address
ENV PORT=20211 LISTEN_ADDR=0.0.0.0
# needed for s6-overlay
ENV S6_CMD_WAIT_FOR_SERVICES_MAXTIME=0
RUN apk update --no-cache \
&& apk add --no-cache bash zip gettext-envsubst sudo mtr usbutils s6-overlay \
&& apk add --no-cache curl arp-scan iproute2 iproute2-ss nmap traceroute net-tools net-snmp-tools bind-tools awake ca-certificates \
&& apk add --no-cache sqlite php82 php82-fpm php82-cgi php82-curl php82-sqlite3 php82-session \
&& apk add --no-cache python3 nginx \
&& ln -s /usr/bin/awake /usr/bin/wakeonlan \
&& bash -c "install -d -m 750 -o nginx -g www-data ${INSTALL_DIR} ${INSTALL_DIR}/pialert" \
&& rm -f /etc/nginx/http.d/default.conf
COPY --from=builder --chown=nginx:www-data ${INSTALL_DIR}/pialert/ ${INSTALL_DIR}/pialert/
RUN /home/pi/pialert/dockerfiles/pre-setup.sh
HEALTHCHECK --interval=30s --timeout=5s --start-period=0s --retries=2 \
CMD curl -sf -o /dev/null ${LISTEN_ADDR}:${PORT}/api/app_state.json
ENTRYPOINT ["/init"]

50
Dockerfile.debian Executable file
View File

@@ -0,0 +1,50 @@
FROM debian:bookworm-slim
# default UID and GID
ENV USER=pi USER_ID=1000 USER_GID=1000 PORT=20211
#TZ=Europe/London
# Todo, figure out why using a workdir instead of full paths don't work
# Todo, do we still need all these packages? I can already see sudo which isn't needed
RUN apt-get update
RUN apt-get install sudo -y
# create pi user and group
# add root and www-data to pi group so they can r/w files and db
RUN groupadd --gid "${USER_GID}" "${USER}" && \
useradd \
--uid ${USER_ID} \
--gid ${USER_GID} \
--create-home \
--shell /bin/bash \
${USER} && \
usermod -a -G ${USER_GID} root && \
usermod -a -G ${USER_GID} www-data
COPY --chmod=775 --chown=${USER_ID}:${USER_GID} . /home/pi/pialert/
# ❗ IMPORTANT - if you modify this file modify the /install/install_dependecies.sh file as well ❗
RUN apt-get install -y \
tini snmp ca-certificates curl libwww-perl arp-scan perl apt-utils cron sudo \
nginx-light php php-cgi php-fpm php-sqlite3 php-curl sqlite3 dnsutils net-tools \
python3 iproute2 nmap python3-pip zip systemctl usbutils traceroute
# Alternate dependencies
RUN apt-get install nginx nginx-core mtr php-fpm php8.2-fpm php-cli php8.2 php8.2-sqlite3 -y
RUN phpenmod -v 8.2 sqlite3
# Setup virtual python environment and use pip3 to install packages
RUN apt-get install -y python3-venv
RUN python3 -m venv myenv
RUN /bin/bash -c "source myenv/bin/activate && update-alternatives --install /usr/bin/python python /usr/bin/python3 10 && pip3 install requests paho-mqtt scapy cron-converter pytz json2table dhcp-leases pyunifi speedtest-cli chardet"
# Create a buildtimestamp.txt to later check if a new version was released
RUN date +%s > /home/pi/pialert/front/buildtimestamp.txt
CMD ["/home/pi/pialert/dockerfiles/start.debian.sh"]

View File

@@ -106,6 +106,19 @@ Thank you to all the wonderful people who are sponsoring this project (=preventi
<!-- SPONSORS-LIST DO NOT MODIFY ABOVE --> <!-- SPONSORS-LIST DO NOT MODIFY ABOVE -->
### 🙏Contributors
This project would be nothing without the amazing work of the community, with special thanks to:
> [pucherot/Pi.Alert](https://github.com/pucherot/Pi.Alert) (the original creator of PiAlert), [leiweibau](https://github.com/leiweibau/Pi.Alert): Dark mode (and much more), [Macleykun](https://github.com/Macleykun) (Help with Dockerfile clean-up) [Final-Hawk](https://github.com/Final-Hawk) (Help with NTFY, styling and other fixes), [TeroRERO](https://github.com/terorero) (Spanish translations), [Data-Monkey](https://github.com/Data-Monkey), (Split-up of the python.py file and more), [cvc90](https://github.com/cvc90) (Spanish translation and various UI work) to name a few...
Here is everyone taht helped and contributed to this project:
<a href="https://github.com/usememos/memos/graphs/contributors">
<img src="https://contri-graphy.yourselfhosted.com/graph?repo=jokob-sk/pi.alert&format=svg" />
</a>
## Everything else ## Everything else
<!--- --------------------------------------------------------------------- ---> <!--- --------------------------------------------------------------------- --->
@@ -122,13 +135,7 @@ Help out and suggest languages in the [online portal of Weblate](https://hosted.
### License ### License
> GPL 3.0 | [Read more here](LICENSE.txt) | Source of the [animated GIF (Loading Animation)](https://commons.wikimedia.org/wiki/File:Loading_Animation.gif) | Source of the [selfhosted Fonts](https://github.com/adobe-fonts/source-sans) > GPL 3.0 | [Read more here](LICENSE.txt) | Source of the [animated GIF (Loading Animation)](https://commons.wikimedia.org/wiki/File:Loading_Animation.gif) | Source of the [selfhosted Fonts](https://github.com/adobe-fonts/source-sans)
### Special thanks
This code is a collaborative body of work, with special thanks to:
> [pucherot/Pi.Alert](https://github.com/pucherot/Pi.Alert) (the original creator of PiAlert), [leiweibau](https://github.com/leiweibau/Pi.Alert): Dark mode (and much more), [Macleykun](https://github.com/Macleykun) (Help with Dockerfile clean-up) [Final-Hawk](https://github.com/Final-Hawk) (Help with NTFY, styling and other fixes), [TeroRERO](https://github.com/terorero) (Spanish translations), [Data-Monkey](https://github.com/Data-Monkey), (Split-up of the python.py file and more), [cvc90](https://github.com/cvc90) (Spanish translation and various UI work) to name a few...
>
> Please see the [Git contributors](https://github.com/jokob-sk/Pi.Alert/graphs/contributors) for a full list of people and their contributions to the project
<!--- --------------------------------------------------------------------- ---> <!--- --------------------------------------------------------------------- --->
[main]: ./docs/img/devices_split.png "Main screen" [main]: ./docs/img/devices_split.png "Main screen"

View File

@@ -32,10 +32,10 @@ services:
- ${DEV_LOCATION}/back/update_vendors.sh:/home/pi/pialert/back/update_vendors.sh - ${DEV_LOCATION}/back/update_vendors.sh:/home/pi/pialert/back/update_vendors.sh
- ${DEV_LOCATION}/front/lib/AdminLTE:/home/pi/pialert/front/lib/AdminLTE - ${DEV_LOCATION}/front/lib/AdminLTE:/home/pi/pialert/front/lib/AdminLTE
- ${DEV_LOCATION}/front/js:/home/pi/pialert/front/js - ${DEV_LOCATION}/front/js:/home/pi/pialert/front/js
- ${DEV_LOCATION}/dockerfiles/start.sh:/home/pi/pialert/dockerfiles/start.sh - ${DEV_LOCATION}/dockerfiles/start.debian.sh:/home/pi/pialert/dockerfiles/start.debian.sh
- ${DEV_LOCATION}/dockerfiles/user-mapping.sh:/home/pi/pialert/dockerfiles/user-mapping.sh - ${DEV_LOCATION}/dockerfiles/user-mapping.sh:/home/pi/pialert/dockerfiles/user-mapping.sh
- ${DEV_LOCATION}/install/install.sh:/home/pi/pialert/install/install.sh - ${DEV_LOCATION}/install/install.debian.sh:/home/pi/pialert/install/install.debian.sh
- ${DEV_LOCATION}/install/install_dependencies.sh:/home/pi/pialert/install/install_dependencies.sh - ${DEV_LOCATION}/install/install_dependencies.debian.sh:/home/pi/pialert/install/install_dependencies.debian.sh
- ${DEV_LOCATION}/front/api:/home/pi/pialert/front/api - ${DEV_LOCATION}/front/api:/home/pi/pialert/front/api
- ${DEV_LOCATION}/front/php:/home/pi/pialert/front/php - ${DEV_LOCATION}/front/php:/home/pi/pialert/front/php
- ${DEV_LOCATION}/front/deviceDetails.php:/home/pi/pialert/front/deviceDetails.php - ${DEV_LOCATION}/front/deviceDetails.php:/home/pi/pialert/front/deviceDetails.php

View File

@@ -20,6 +20,16 @@ fi
echo "[INSTALL] Copy starter pialert.db and pialert.conf if they don't exist" echo "[INSTALL] Copy starter pialert.db and pialert.conf if they don't exist"
# DANGER ZONE: ALWAYS_FRESH_INSTALL
if [ "$ALWAYS_FRESH_INSTALL" = true ]; then
echo "[INSTALL] ❗ ALERT /db and /config folders are cleared because the ALWAYS_FRESH_INSTALL is set to: $ALWAYS_FRESH_INSTALL"
# Delete content of "$INSTALL_DIR/pialert/config/"
rm -rf "$INSTALL_DIR/pialert/config/"*
# Delete content of "$INSTALL_DIR/pialert/db/"
rm -rf "$INSTALL_DIR/pialert/db/"*
fi
# Copy starter pialert.db and pialert.conf if they don't exist # Copy starter pialert.db and pialert.conf if they don't exist
cp -na "${INSTALL_DIR}/pialert/back/pialert.conf" "${INSTALL_DIR}/pialert/config/pialert.conf" cp -na "${INSTALL_DIR}/pialert/back/pialert.conf" "${INSTALL_DIR}/pialert/config/pialert.conf"
cp -na "${INSTALL_DIR}/pialert/back/pialert.db" "${FILEDB}" cp -na "${INSTALL_DIR}/pialert/back/pialert.db" "${FILEDB}"

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
echo "---------------------------------------------------------" echo "---------------------------------------------------------"
echo "[INSTALL] Run start.sh" echo "[INSTALL] Run start.debian.sh"
echo "---------------------------------------------------------" echo "---------------------------------------------------------"
@@ -34,7 +34,7 @@ fi
echo "[INSTALL] Run setup scripts" echo "[INSTALL] Run setup scripts"
"$INSTALL_DIR/pialert/dockerfiles/user-mapping.sh" "$INSTALL_DIR/pialert/dockerfiles/user-mapping.sh"
"$INSTALL_DIR/pialert/install/install_dependencies.sh" # if modifying this file transfer the chanegs into the root Dockerfile as well! "$INSTALL_DIR/pialert/install/install_dependencies.debian.sh" # if modifying this file transfer the changes into the root Dockerfile.debian as well!
echo "[INSTALL] Setup NGINX" echo "[INSTALL] Setup NGINX"
@@ -61,7 +61,7 @@ fi
# create symbolic link to the pialert install directory # create symbolic link to the pialert install directory
ln -s $INSTALL_DIR/pialert/front $WEB_UI_DIR ln -s $INSTALL_DIR/pialert/front $WEB_UI_DIR
# create symbolic link to NGINX configuaration coming with PiAlert # create symbolic link to NGINX configuaration coming with PiAlert
sudo ln -s "$INSTALL_DIR/pialert/install/pialert.conf" /etc/nginx/conf.d/pialert.conf sudo ln -s "$INSTALL_DIR/pialert/install/pialert.debian.conf" /etc/nginx/conf.d/pialert.conf
# Use user-supplied port if set # Use user-supplied port if set
if [ -n "${PORT}" ]; then if [ -n "${PORT}" ]; then

View File

@@ -11,7 +11,7 @@ To download and install PiAlert on the hardware/server directly use the `curl` o
A warning to the installation method below: Piping to bash is [controversial](https://pi-hole.net/2016/07/25/curling-and-piping-to-bash) and may A warning to the installation method below: Piping to bash is [controversial](https://pi-hole.net/2016/07/25/curling-and-piping-to-bash) and may
be dangerous, as you cannot see the code that's about to be executed on your system. be dangerous, as you cannot see the code that's about to be executed on your system.
Alternatively you can download the installation script `install/install.sh` from the repository and check the code yourself (beware other scripts are Alternatively you can download the installation script `install/install.debian.sh` from the repository and check the code yourself (beware other scripts are
downloaded too - only from this repo). downloaded too - only from this repo).
PiAlert will be installed in `home/pi/pialert/` and run on port number `20211`. PiAlert will be installed in `home/pi/pialert/` and run on port number `20211`.
@@ -19,15 +19,15 @@ PiAlert will be installed in `home/pi/pialert/` and run on port number `20211`.
Some facts about what and where something will be changed/installed by the HW install setup (may not contain everything!): Some facts about what and where something will be changed/installed by the HW install setup (may not contain everything!):
- `/home/pi/pialert` directory will be deleted and newly created - `/home/pi/pialert` directory will be deleted and newly created
- `/home/pi/pialert` will contain the whole repository (downloaded by `install/install.sh`) - `/home/pi/pialert` will contain the whole repository (downloaded by `install/install.debian.sh`)
- The default NGINX site `/etc/nginx/sites-enabled/default` will be disabled (sym-link deleted or backed up to `sites-available`) - The default NGINX site `/etc/nginx/sites-enabled/default` will be disabled (sym-link deleted or backed up to `sites-available`)
- `/var/www/html/pialert` directory will be deleted and newly created - `/var/www/html/pialert` directory will be deleted and newly created
- `/etc/nginx/conf.d/pialert.conf` will be sym-linked to `/home/pi/pialert/install/pialert.conf` - `/etc/nginx/conf.d/pialert.conf` will be sym-linked to `/home/pi/pialert/install/pialert.debian.conf`
- Some files (IEEE device vendors info, ...) will be created in the directory where the installation script is executed - Some files (IEEE device vendors info, ...) will be created in the directory where the installation script is executed
## Limitations ## Limitations
- No system service is provided. PiAlert must be started using `/home/pi/pialert/dockerfiles/start.sh`. - No system service is provided. PiAlert must be started using `/home/pi/pialert/dockerfiles/start.debian.sh`.
- No checks for other running software is done. - No checks for other running software is done.
- Only tested to work on Debian Bookworm (Debian 12). - Only tested to work on Debian Bookworm (Debian 12).
- **EXPERIMENTAL** and not recommended way to install PiAlert. - **EXPERIMENTAL** and not recommended way to install PiAlert.
@@ -35,15 +35,15 @@ Some facts about what and where something will be changed/installed by the HW in
## 📥 Installation via CURL ## 📥 Installation via CURL
```bash ```bash
curl -o install.sh https://raw.githubusercontent.com/jokob-sk/Pi.Alert/main/install/install.sh && sudo chmod +x install.sh && sudo ./install.sh curl -o install.debian.sh https://raw.githubusercontent.com/jokob-sk/Pi.Alert/main/install/install.debian.sh && sudo chmod +x install.debian.sh && sudo ./install.debian.sh
``` ```
## 📥 Installation via WGET ## 📥 Installation via WGET
```bash ```bash
wget https://raw.githubusercontent.com/jokob-sk/Pi.Alert/main/install/install.sh -O install.sh && sudo chmod +x install.sh && sudo ./install.sh wget https://raw.githubusercontent.com/jokob-sk/Pi.Alert/main/install/install.debian.sh -O install.debian.sh && sudo chmod +x install.debian.sh && sudo ./install.debian.sh
``` ```
These commands will download the `install.sh` script from the GitHub repository, make it executable with `chmod`, and then run it using `./install.sh`. These commands will download the `install.debian.sh` script from the GitHub repository, make it executable with `chmod`, and then run it using `./install.debian.sh`.
Make sure you have the necessary permissions to execute the script. Make sure you have the necessary permissions to execute the script.

View File

@@ -1,6 +1,8 @@
function pia_draw_graph_online_history(pia_js_graph_online_history_time, pia_js_graph_online_history_ondev, pia_js_graph_online_history_dodev, pia_js_graph_online_history_ardev) { function pia_draw_graph_online_history(pia_js_graph_online_history_time, pia_js_graph_online_history_ondev, pia_js_graph_online_history_dodev, pia_js_graph_online_history_ardev) {
var xValues = pia_js_graph_online_history_time; var xValues = pia_js_graph_online_history_time;
// alert("dev presence")
// Data object for online status // Data object for online status
onlineData = { onlineData = {
label: 'Online', label: 'Online',

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# 🛑 Important: This is only used for the bare-metal install 🛑 # 🛑 Important: This is only used for the bare-metal install 🛑
# Update /dockerfiles/start.sh in most cases is preferred # Update /dockerfiles/start.debian.sh in most cases is preferred
echo "---------------------------------------------------------" echo "---------------------------------------------------------"
echo "[INSTALL] Run install.sh" echo "[INSTALL] Run install.sh"
@@ -35,4 +35,4 @@ if [ ! -f $INSTALL_DIR/pialert/front/buildtimestamp.txt ]; then
fi fi
# Start PiAlert # Start PiAlert
"$INSTALL_DIR/pialert/dockerfiles/start.sh" "$INSTALL_DIR/pialert/dockerfiles/start.debian.sh"

View File

@@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
echo "---------------------------------------------------------" echo "---------------------------------------------------------"
echo "[INSTALL] Run install_dependencies.sh" echo "[INSTALL] Run install_dependencies.debian.sh"
echo "---------------------------------------------------------" echo "---------------------------------------------------------"
# ❗ IMPORTANT - if you modify this file modify the root Dockerfile as well ❗ # ❗ IMPORTANT - if you modify this file modify the root Dockerfile as well ❗

0
install/pialert.conf.template Normal file → Executable file
View File