Skip to content

Commit

Permalink
s6 v3
Browse files Browse the repository at this point in the history
  • Loading branch information
mrhotio committed Aug 27, 2023
1 parent d95f607 commit b870d4d
Show file tree
Hide file tree
Showing 21 changed files with 82 additions and 72 deletions.
1 change: 0 additions & 1 deletion linux-amd64.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ VOLUME ["${CONFIG_DIR}"]
ENV CUSTOM_BUILD=""
COPY --from=builder /caddy-bin "${APP_DIR}/caddy"
COPY root/ /
RUN chmod -R +x /etc/cont-init.d/ /etc/services.d/
1 change: 0 additions & 1 deletion linux-arm64.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ VOLUME ["${CONFIG_DIR}"]
ENV CUSTOM_BUILD=""
COPY --from=builder /caddy-bin "${APP_DIR}/caddy"
COPY root/ /
RUN chmod -R +x /etc/cont-init.d/ /etc/services.d/
28 changes: 0 additions & 28 deletions root/etc/cont-init.d/00-start-container

This file was deleted.

14 changes: 0 additions & 14 deletions root/etc/cont-init.d/01-config-app

This file was deleted.

19 changes: 0 additions & 19 deletions root/etc/cont-init.d/02-custom-build

This file was deleted.

9 changes: 0 additions & 9 deletions root/etc/cont-init.d/03-format-caddyfile

This file was deleted.

Empty file.
1 change: 1 addition & 0 deletions root/etc/s6-overlay/s6-rc.d/perms/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oneshot
1 change: 1 addition & 0 deletions root/etc/s6-overlay/s6-rc.d/perms/up
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
find /etc/s6-overlay/s6-rc.d -name "run" -execdir chmod +x {} +
Empty file.
19 changes: 19 additions & 0 deletions root/etc/s6-overlay/s6-rc.d/secrets/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/command/with-contenv bash
# shellcheck shell=bash

find /var/run/s6/container_environment/ -type f -name 'FILE__*' -print0 | while IFS= read -r -d '' FILENAME; do
NEW_VAR=${FILENAME//FILE__/}
SECRET_FILE=$(cat "${FILENAME}")
if [[ ! -f ${SECRET_FILE} ]]; then
echo "[${NEW_VAR##*/}] The file \"${SECRET_FILE}\" wasn't found!"
exit 1
fi
SECRET=$(cat "${SECRET_FILE}")
if [[ -n ${SECRET} ]]; then
echo -n "${SECRET}" > "${NEW_VAR}"
echo "[${NEW_VAR##*/}] Set with secret from \"${SECRET_FILE}\"."
else
echo "[${NEW_VAR##*/}] No secret found in \"${SECRET_FILE}\"!"
exit 1
fi
done
1 change: 1 addition & 0 deletions root/etc/s6-overlay/s6-rc.d/secrets/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oneshot
1 change: 1 addition & 0 deletions root/etc/s6-overlay/s6-rc.d/secrets/up
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/etc/s6-overlay/s6-rc.d/secrets/run
Empty file.
File renamed without changes.
1 change: 1 addition & 0 deletions root/etc/s6-overlay/s6-rc.d/service1/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
longrun
Empty file.
56 changes: 56 additions & 0 deletions root/etc/s6-overlay/s6-rc.d/setup/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/command/with-contenv bash
# shellcheck shell=bash

umask "${UMASK}"

echo "
----------------------------------------------------------------------
ENVIRONMENT
----------------------------------------------------------------------
PUID=${PUID}
PGID=${PGID}
UMASK=${UMASK}
TZ=${TZ}
----------------------------------------------------------------------
"

if [[ ! "${PUID}" -eq 0 ]] && [[ ! "${PGID}" -eq 0 ]]; then
echo "Executing usermod..."
mkdir "/tmp/temphome"
usermod -d "/tmp/temphome" hotio
usermod -o -u "${PUID}" hotio
usermod -d "${CONFIG_DIR}" hotio
rm -rf "/tmp/temphome"
groupmod -o -g "${PGID}" hotio
else
echo "Running as root is not supported, please fix your PUID and PGID!"
exit 1
fi

echo "Applying permissions to ${CONFIG_DIR}"
chmod "=rwx" "${CONFIG_DIR}"
chown hotio:hotio "${CONFIG_DIR}"

if [[ ! -f "${CONFIG_DIR}/Caddyfile" ]]; then
echo "Installing default \"Caddyfile\"..."
cp "${APP_DIR}/Caddyfile" "${CONFIG_DIR}/Caddyfile"
chown hotio:hotio "${CONFIG_DIR}/Caddyfile"
fi

ln -sf "${APP_DIR}/caddy" "/usr/local/bin/caddy"

if [[ -n "${CUSTOM_BUILD}" ]]; then
echo "Trying to use the custom build \"${CUSTOM_BUILD}\"..."
builtin_version=$("${APP_DIR}/caddy" version)
chmod +x "${CUSTOM_BUILD}"
custom_version=$("${CUSTOM_BUILD}" version)
if [[ "${builtin_version}" != "${custom_version}" ]]; then
echo "There's a version mismatch, you should update your custom build!"
fi
echo "Built-in: ${builtin_version}"
echo "Custom: ${custom_version}"
ln -sf "${CUSTOM_BUILD}" "/usr/local/bin/caddy"
fi

"/usr/local/bin/caddy" fmt "${CONFIG_DIR}/Caddyfile" --overwrite
chown hotio:hotio "${CONFIG_DIR}/Caddyfile"
1 change: 1 addition & 0 deletions root/etc/s6-overlay/s6-rc.d/setup/type
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
oneshot
1 change: 1 addition & 0 deletions root/etc/s6-overlay/s6-rc.d/setup/up
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/etc/s6-overlay/s6-rc.d/setup/run
Empty file.

0 comments on commit b870d4d

Please sign in to comment.