diff --git a/Dockerfile b/Dockerfile index a1a52e16..14378dd0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,13 +14,13 @@ RUN wget https://github.com/seriousm4x/UpSnap/releases/download/${VERSION}/UpSna setcap 'cap_net_raw=+ep' ./upsnap FROM alpine:3 -ARG HTTP_LISTEN=127.0.0.1:8090 -ENV HTTP_LISTEN=${HTTP_LISTEN} +ARG UPSNAP_HTTP_LISTEN=127.0.0.1:8090 +ENV UPSNAP_HTTP_LISTEN=${UPSNAP_HTTP_LISTEN} RUN apk update &&\ apk add --no-cache tzdata ca-certificates nmap samba samba-common-tools openssh sshpass curl &&\ rm -rf /var/cache/apk/* WORKDIR /app COPY --from=downloader /app/upsnap upsnap HEALTHCHECK --interval=10s \ - CMD curl -fs "http://${HTTP_LISTEN}/api/health" || exit 1 -ENTRYPOINT ["sh", "-c", "./upsnap serve --http $HTTP_LISTEN"] + CMD curl -fs "http://${UPSNAP_HTTP_LISTEN}/api/health" || exit 1 +ENTRYPOINT ["sh", "-c", "./upsnap serve"] diff --git a/Dockerfile.dev b/Dockerfile.dev index cef4ec8f..5ee1f358 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -17,13 +17,13 @@ RUN go build -o upsnap main.go &&\ setcap 'cap_net_raw=+ep' ./upsnap FROM alpine:3 -ARG HTTP_LISTEN=127.0.0.1:8090 -ENV HTTP_LISTEN=${HTTP_LISTEN} +ARG UPSNAP_HTTP_LISTEN=127.0.0.1:8090 +ENV UPSNAP_HTTP_LISTEN=${UPSNAP_HTTP_LISTEN} RUN apk update &&\ apk add --no-cache tzdata ca-certificates nmap samba samba-common-tools openssh sshpass curl &&\ rm -rf /var/cache/apk/* WORKDIR /app COPY --from=go /app/upsnap upsnap HEALTHCHECK --interval=10s \ - CMD curl -fs "http://${HTTP_LISTEN}/api/health" || exit 1 -ENTRYPOINT ["sh", "-c", "./upsnap serve --http $HTTP_LISTEN"] + CMD curl -fs "http://${UPSNAP_HTTP_LISTEN}/api/health" || exit 1 +ENTRYPOINT ["sh", "-c", "./upsnap serve"] diff --git a/README.md b/README.md index 59eb7936..81708661 100644 --- a/README.md +++ b/README.md @@ -94,13 +94,13 @@ If you want to change the port from 8090 to something else, change the following ```yml environment: - - HTTP_LISTEN=0.0.0.0:5000 + - UPSNAP_HTTP_LISTEN=0.0.0.0:5000 ``` ### Install additional packages for shutdown cmd ```yml -entrypoint: /bin/sh -c "apk update && apk add --no-cache && rm -rf /var/cache/apk/* && ./upsnap serve --http $HTTP_LISTEN" +entrypoint: /bin/sh -c "apk update && apk add --no-cache && rm -rf /var/cache/apk/* && ./upsnap serve" ``` You can search for your needed package [here](https://pkgs.alpinelinux.org/packages). diff --git a/backend/pb/pb.go b/backend/pb/pb.go index b2021ed8..5907e5a2 100644 --- a/backend/pb/pb.go +++ b/backend/pb/pb.go @@ -188,9 +188,24 @@ func StartPocketBase(distDirFS fs.FS) { return e.Next() }) - if err := app.Start(); err != nil { - logger.Error.Fatalln(err) + // check for custom http listen address in env var, else use default + httpListen := os.Getenv("UPSNAP_HTTP_LISTEN") + if httpListen != "" { + if err := app.Bootstrap(); err != nil { + logger.Error.Fatalln(err) + } + if err := apis.Serve(app, apis.ServeConfig{ + HttpAddr: httpListen, + ShowStartBanner: true, + }); err != nil { + logger.Error.Fatalln(err) + } + } else { + if err := app.Start(); err != nil { + logger.Error.Fatalln(err) + } } + } func importSettings(app *pocketbase.PocketBase) error { diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index b8a3039d..e2c427b3 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -11,8 +11,8 @@ services: # # the container (mkdir data) so that it has the right permissions. # user: 1000:1000 # environment: - # - HTTP_LISTEN=127.0.0.1:8090 # - TZ=Europe/Berlin # Set container timezone for cron schedules + # - UPSNAP_HTTP_LISTEN=127.0.0.1:8090 # - UPSNAP_INTERVAL=*/10 * * * * * # Sets the interval in which the devices are pinged # - UPSNAP_SCAN_RANGE=192.168.1.0/24 # Scan range is used for device discovery on local network # - UPSNAP_WEBSITE_TITLE=Custom name # Custom website title @@ -26,4 +26,4 @@ services: # test: curl -fs "http://localhost:5000/api/health" || exit 1 # interval: 10s # # or install custom packages for shutdown - # entrypoint: /bin/sh -c "apk update && apk add --no-cache && rm -rf /var/cache/apk/* && ./upsnap serve --http $HTTP_LISTEN" + # entrypoint: /bin/sh -c "apk update && apk add --no-cache && rm -rf /var/cache/apk/* && ./upsnap serve" diff --git a/docker-compose.yml b/docker-compose.yml index 565ceeda..b60b8947 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,8 +9,8 @@ services: # # To use a non-root user, create the mountpoint first (mkdir data) so that it has the right permission. # user: 1000:1000 # environment: - # - HTTP_LISTEN=127.0.0.1:8090 # - TZ=Europe/Berlin # Set container timezone for cron schedules + # - UPSNAP_HTTP_LISTEN=127.0.0.1:8090 # - UPSNAP_INTERVAL=*/10 * * * * * # Sets the interval in which the devices are pinged # - UPSNAP_SCAN_RANGE=192.168.1.0/24 # Scan range is used for device discovery on local network # - UPSNAP_SCAN_TIMEOUT=500ms # Scan timeout is nmap's --host-timeout value to wait for devices (https://nmap.org/book/man-performance.html) @@ -21,4 +21,4 @@ services: # - 192.18.0.1 # - 192.18.0.2 # # or install custom packages for shutdown - # entrypoint: /bin/sh -c "apk update && apk add --no-cache && rm -rf /var/cache/apk/* && ./upsnap serve --http $HTTP_LISTEN" + # entrypoint: /bin/sh -c "apk update && apk add --no-cache && rm -rf /var/cache/apk/* && ./upsnap serve"