]> git.immae.eu Git - github/bastienwirtz/homer.git/commitdiff
Simplify the container starting process to allow it to run with a
authorBastien Wirtz <bastien.wirtz@gmail.com>
Sun, 10 Apr 2022 09:55:11 +0000 (11:55 +0200)
committerBastien Wirtz <bastien.wirtz@gmail.com>
Sat, 30 Apr 2022 13:39:36 +0000 (15:39 +0200)
unprivileged user

Dockerfile
Dockerfile.arm32v7
Dockerfile.arm64v8
README.md
docker-compose.yml
entrypoint.sh
lighttpd.conf
src/assets/app.scss

index ffe50c4f6e91fddd8e309f2922414870188863b5..0e9d51a30ce240177c0306ca29d5892e08685e9b 100644 (file)
@@ -12,24 +12,28 @@ RUN yarn build
 # production stage
 FROM alpine:3.15
 
-ENV USER lighttpd
-ENV GROUP lighttpd
-ENV GID 911
-ENV UID 911
+ENV GID 1000
+ENV UID 1000
 ENV PORT 8080
 ENV SUBFOLDER "/_"
+ENV INIT_ASSETS 1
 
-RUN addgroup -S ${GROUP} -g ${GID} && adduser -D -S -u ${UID} ${USER} ${GROUP} && \
+RUN addgroup -S lighttpd -g ${GID} && adduser -D -S -u ${UID} lighttpd lighttpd && \
     apk add -U --no-cache lighttpd
 
-COPY entrypoint.sh /entrypoint.sh
-COPY lighttpd.conf /lighttpd.conf
+WORKDIR /www
 
-COPY --from=build-stage --chown=${USER}:${GROUP} /app/dist /www/
+COPY lighttpd.conf /lighttpd.conf
+COPY entrypoint.sh /entrypoint.sh
+COPY --from=build-stage --chown=${UID}:${GID} /app/dist /www/
 COPY --from=build-stage --chown=${USER}:${GROUP} /app/dist/assets /www/default-assets
+
+USER ${UID}:${GID}
+
 HEALTHCHECK --interval=30s --timeout=5s --retries=3 \
     CMD wget --no-verbose --tries=1 --spider http://127.0.0.1:${PORT}/ || exit 1
 
 EXPOSE ${PORT}
 VOLUME /www/assets
+
 ENTRYPOINT ["/bin/sh", "/entrypoint.sh"]
index 01a21966f79561866c42544888aeee1d4e937ae9..7e1d92b476ea40fafbb2c4c05a46804b1bd26fa8 100644 (file)
@@ -32,14 +32,16 @@ RUN addgroup -S ${GROUP} -g ${GID} && adduser -D -S -u ${UID} ${USER} ${GROUP} &
     apk add -U --no-cache lighttpd && \
     rm /usr/bin/qemu-arm-static
 
-COPY entrypoint.sh /entrypoint.sh
-COPY lighttpd.conf /lighttpd.conf
+WORKDIR /www
 
+COPY lighttpd.conf /lighttpd.conf
 COPY --from=build-stage --chown=${USER}:${GROUP} /app/dist /www/
-COPY --from=build-stage --chown=${USER}:${GROUP} /app/dist/assets /www/default-assets
+
+USER ${USER}
 HEALTHCHECK --interval=30s --timeout=5s --retries=3 \
     CMD wget --no-verbose --tries=1 --spider http://127.0.0.1:${PORT}/ || exit 1
 
 EXPOSE ${PORT}
 VOLUME /www/assets
-ENTRYPOINT ["/bin/sh", "/entrypoint.sh"]
+
+CMD ["lighttpd", "-D", "-f", "/lighttpd.conf"]
index f9e66755049e8b9e07a7d002c638c608cd9729eb..573a2e4fa994993664638d241bd3266bde024fbe 100644 (file)
@@ -32,14 +32,16 @@ RUN addgroup -S ${GROUP} -g ${GID} && adduser -D -S -u ${UID} ${USER} ${GROUP} &
     apk add -U --no-cache lighttpd && \
     rm /usr/bin/qemu-aarch64-static
 
-COPY entrypoint.sh /entrypoint.sh
-COPY lighttpd.conf /lighttpd.conf
+WORKDIR /www
 
+COPY lighttpd.conf /lighttpd.conf
 COPY --from=build-stage --chown=${USER}:${GROUP} /app/dist /www/
-COPY --from=build-stage --chown=${USER}:${GROUP} /app/dist/assets /www/default-assets
+
+USER ${USER}
 HEALTHCHECK --interval=30s --timeout=5s --retries=3 \
     CMD wget --no-verbose --tries=1 --spider http://127.0.0.1:${PORT}/ || exit 1
 
 EXPOSE ${PORT}
 VOLUME /www/assets
-ENTRYPOINT ["/bin/sh", "/entrypoint.sh"]
+
+CMD ["lighttpd", "-D", "-f", "/lighttpd.conf"]
index 57185a7614c53a21b0ca571b0b149b142c858a13..6ac71e62974c0b0907dd72e1603a0016b50b68e1 100644 (file)
--- a/README.md
+++ b/README.md
@@ -71,8 +71,6 @@ See [documentation](docs/configuration.md) for information about the configurati
 
 ### Using docker
 
-To launch container:
-
 ```sh
 docker run -d \
   -p 8080:8080 \
@@ -81,16 +79,19 @@ docker run -d \
   b4bz/homer:latest
 ```
 
-Default assets will be automatically installed in the `/www/assets` directory. Use `UID` and/or `GID` env var to change the assets owner (`docker run -e "UID=1000" -e "GID=1000" [...]`).
+Environment variables: 
+
+* **`INIT_ASSETS`** (default: `1`)
+Install exemple configuration file & assets (favicons, ...) to help you get started.
 
-## Host in subfolder
+* **`SUBFOLDER`** (default: `null`)
+If you would like to host Homer in a subfolder, (ex: *http://my-domain/**homer***), set this to the subfolder path (ex `/homer`).
 
-If you would like to host Homer in a subfolder, for e.g. behind a reverse proxy, supply the name of subfolder by using the `SUBFOLDER` env var.
 
 ### Using docker-compose
 
 The `docker-compose.yml` file must be edited to match your needs.
-Set the port and volume (equivalent to `-p` and `-v` arguments):
+You probably want to set the port mapping and volume binding (equivalent to `-p` and `-v` arguments):
 
 ```yaml
 volumes:
@@ -99,21 +100,13 @@ ports:
   - 8080:8080
 ```
 
-To launch container:
+Then launch the container:
 
 ```sh
-cd /path/to/docker-compose.yml
+cd /path/to/docker-compose.yml/
 docker-compose up -d
 ```
 
-Default assets will be automatically installed in the `/www/assets` directory. Use `UID` and/or `GID` env var to change the assets owner, also in `docker-compose.yml`:
-
-```yaml
-environment:
-  - UID=1000
-  - GID=1000
-```
-
 ### Using the release tarball (prebuilt, ready to use)
 
 Download and extract the latest release (`homer.zip`) from the [release page](https://github.com/bastienwirtz/homer/releases), rename the `assets/config.yml.dist` file to `assets/config.yml`, and put it behind a web server.
index 884703c3142eee7725f02f7611a119afc2d2f2b6..231e72abe9bf4de698f2671c7177b88e04236c46 100644 (file)
@@ -10,7 +10,6 @@ services:
       - /your/local/assets/:/www/assets
     ports:
       - 8080:8080
-    #environment:
-    #  - UID=1000
-    #  - GID=1000
-    restart: unless-stopped
+    user: 1000:1000 # default
+    environment:
+      - INIT_ASSETS=1 # default
index e10e17e7d82d3f25cb11351d627844124da90364..eba1cb20ac3c39d79c92d35640cb36b10adcae24 100644 (file)
@@ -1,23 +1,18 @@
 #!/bin/sh
 
-# Ensure default assets are present.
-while true; do echo n; done | cp -Ri /www/default-assets/* /www/assets/ &> /dev/null
+PERMISSION_ERROR="Check assets directory permissions & docker user or skip default assets install by setting the INIT_ASSETS env var to 0"
 
-# Ensure compatibility with previous version (config.yml was in the root directory)
-if [ -f "/www/config.yml" ]; then
-    yes n | cp -i /www/config.yml /www/assets/ &> /dev/null
-fi
-
-# Install default config if no one is available.
-yes n | cp -i /www/default-assets/config.yml.dist /www/assets/config.yml &> /dev/null
+# Default assets & exemple configuration installation if possible.
+if [[ "${INIT_ASSETS}" == "1" ]] && [[ ! -f "/www/config.yml" ]]; then
+    echo "No configuration found, installing default config & assets"
+    if [[ ! -w "/www/assets/" ]]; then echo "Assets directory not writable. $PERMISSION_ERROR" && exit 1; fi
+    
+    while true; do echo n; done | cp -Ri /www/default-assets/* /www/assets/ &> /dev/null
+    if [[ $? -ne 0 ]]; then echo "Fail to copy default assets. $PERMISSION_ERROR" && exit 1; fi
 
-# Create symbolic link for hosting in subfolder.
-if [[ -n "${SUBFOLDER}" ]]; then
-  ln -s /www "/www/$SUBFOLDER"
-  chown -h $USER:$GROUP "/www/$SUBFOLDER"
+    yes n | cp -i /www/default-assets/config.yml.dist /www/assets/config.yml &> /dev/null
+    if [[ $? -ne 0 ]]; then echo "Fail to copy default config file. $PERMISSION_ERROR" && exit 1; fi
 fi
 
-chown -R $UID:$GID /www/assets
-
 echo "Starting webserver"
 lighttpd -D -f /lighttpd.conf
index 04b0bedb637d3267899fe68fa0b9e5de8aa4e73b..32e14da4781f63affff921297930d8317c9c669d 100644 (file)
@@ -2,8 +2,8 @@ include "/etc/lighttpd/mime-types.conf"
 
 server.port           = env.PORT
 server.modules        = ( "mod_alias" )
-server.username       = env.USER
-server.groupname      = env.GROUP
+server.username       = "lighttpd"
+server.groupname      = "lighttpd"
 server.document-root  = "/www"
 alias.url             = ( env.SUBFOLDER => "/www" )
 server.indexfiles     = ("index.html")
index aa8b077839b0629187ce29ed524af08be700b73b..ae2cb6b26fb36496ea231626bce4911a638c71a3 100644 (file)
@@ -104,6 +104,10 @@ body {
 
     .dashboard-title {
       padding: 6px 0 0 80px;
+
+      &.no-logo {
+        padding-left: 0;
+      }
     }
 
     .first-line {