diff --git a/.env.scripts b/.env.scripts index e53e28d..d643804 100644 --- a/.env.scripts +++ b/.env.scripts @@ -1,10 +1,10 @@ # - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202605292219-git +##@Version : 202607092001-git # @@Author : CasjaysDev # @@Contact : CasjaysDev -# @@License : MIT +# @@License : WTFPL # @@Copyright : Copyright 2026 CasjaysDev -# @@Created : Mon May 4 04:27:58 PM EDT 2026 +# @@Created : Thu Jul 9 08:01:29 PM EDT 2026 # @@File : .env.scripts # @@Description : Variables for gen-dockerfile and buildx scripts # @@Changelog : newScript @@ -54,7 +54,7 @@ ENV_ADD_IMAGE_PUSH="" # - - - - - - - - - - - - - - - - - - - - - - - - - # Pull Configuration # ENV_PULL_URL: Source image to pull from (base image) -ENV_PULL_URL="casjaysdev/alpine" +ENV_PULL_URL="alpine" # ENV_DISTRO_TAG: Tag for the pull source image ENV_DISTRO_TAG="${IMAGE_VERSION}" # - - - - - - - - - - - - - - - - - - - - - - - - - @@ -72,12 +72,9 @@ NODE_MANAGER="system" # - - - - - - - - - - - - - - - - - - - - - - - - - # Default directories WWW_ROOT_DIR="/usr/local/share/httpd/default" -DEFAULT_FILE_DIR="/usr/local/share/template-files" -DEFAULT_DATA_DIR="/usr/local/share/template-files/data" -DEFAULT_CONF_DIR="/usr/local/share/template-files/config" -DEFAULT_TEMPLATE_DIR="/usr/local/share/template-files/defaults" # - - - - - - - - - - - - - - - - - - - - - - - - - ENV_PACKAGES="git make bash tini ca-certificates openssh-client curl wget tar tzdata jq build-base gcc musl-dev pkgconf openssl-dev libffi-dev zlib-dev linux-headers protobuf protobuf-dev" # - - - - - - - - - - - - - - - - - - - - - - - - - # ex: ts=2 sw=2 et filetype=sh # - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/AI.md b/AI.md index 296cd87..c48b4af 100644 --- a/AI.md +++ b/AI.md @@ -24,6 +24,174 @@ Files updated: --- +## Template System Reference + +This section documents the current state of `templates/dockerfiles/` and key +`bin/gen-dockerfile` variables. Keep it in sync whenever upstream templates change. + +### Template inventory + +| Template | Final stage | Init / PID 1 | Base OS | +|----------|-------------|--------------|---------| +| `alpine.template` | `scratch.template` | tini | Alpine | +| `debian.template` | `scratch.template` | tini | Debian | +| `ubuntu.template` | `scratch.template` | tini | Ubuntu | +| `rhel.template` | `scratch.template` | tini | AlmaLinux | +| `archlinux.template` | `scratch.template` | tini | Arch Linux (see multi-arch note) | +| `web.template` | `systemd.template` | `/sbin/init` | Debian | +| `xorg.template` | `systemd.template` | `/sbin/init` | Debian | + +### Final-stage templates + +`scratch.template` — used by all non-GUI templates. +- `ENTRYPOINT [ "tini", "-p", "SIGTERM","--", "/usr/local/bin/entrypoint.sh" ]` +- `STOPSIGNAL SIGRTMIN+3` + +`systemd.template` — used by `web` and `xorg` (systemd runs as PID 1; tini is redundant). +- `ENTRYPOINT [ "/sbin/init" ]` +- `STOPSIGNAL SIGRTMIN+3` +- No `tini_provider` stage, no `COPY --from=tini_provider` line. + +Both templates are identical apart from `ENTRYPOINT`. OCI labels, `ENV HOSTNAME`, and +`VOLUME`/`EXPOSE`/`HEALTHCHECK` are the same in both. + +### OCI label standard + +Both `scratch.template` and `systemd.template` emit these labels (no others): + +``` +LABEL maintainer="${GEN_DOCKERFILE_MAINTAINER}" +LABEL org.opencontainers.image.vendor="${GEN_DOCKERFILE_VENDOR:-CasjaysDev}" +LABEL org.opencontainers.image.authors="${GEN_DOCKERFILE_AUTHOR:-CasjaysDev}" +LABEL org.opencontainers.image.licenses="${LICENSE}" +LABEL org.opencontainers.image.title="${IMAGE_NAME}" +LABEL org.opencontainers.image.description="Containerized version of ${IMAGE_NAME}" +LABEL org.opencontainers.image.created="${BUILD_DATE}" +LABEL org.opencontainers.image.version="${BUILD_VERSION}" +LABEL org.opencontainers.image.revision="${GIT_COMMIT}" +LABEL org.opencontainers.image.url="${GEN_DOCKERFILE_HUB_REPO}" +LABEL org.opencontainers.image.source="${GEN_DOCKERFILE_GIT_REPO}" +LABEL org.opencontainers.image.documentation="${GEN_DOCKERFILE_GIT_REPO}" +LABEL org.opencontainers.image.vcs-type="Git" +LABEL com.github.containers.toolbox="false" +``` + +Shell-expanded values (no `\`) are evaluated at template-render time by +`gen-dockerfile`. Dollar-escaped values (`\${...}`) become literal Docker +`ARG`/`ENV` references in the generated `Dockerfile`. + +Removed labels (do not re-add): +- `org.opencontainers.image.base.name` — belongs on the base image, not the app image +- `org.opencontainers.image.schema-version` — non-spec; redundant with `version` +- Any duplicate `authors` or `source` entries + +### HOSTNAME convention + +All templates set `ENV HOSTNAME="casjaysdevdocker-${IMAGE_NAME}"` in every stage +that declares it. The prefix is always `casjaysdevdocker-`, never `casjaysdev-`. + +### `GEN_DOCKERFILE_APP_DIR` and pull URL logic + +`GEN_DOCKERFILE_APP_DIR` is auto-detected in `bin/gen-dockerfile` from the parent +directory of `$PWD` (i.e. the GitHub org the project lives in): + +```bash +GEN_DOCKERFILE_APP_DIR="${GEN_DOCKERFILE_APP_DIR:-$(basename -- "$(dirname -- "$PWD")")}" +``` + +It controls which base images `GEN_DOCKER_SPECIFY_IMAGE_SOURCE_*` default to: + +```bash +if [ "${GEN_DOCKERFILE_APP_DIR}" = "casjaysdevdocker" ]; then + # Pull from pre-built casjaysdev/* base images on Docker Hub + GEN_DOCKER_SPECIFY_IMAGE_SOURCE_RHEL="${GEN_DOCKER_SPECIFY_IMAGE_SOURCE_RHEL:-casjaysdev/almalinux}" + GEN_DOCKER_SPECIFY_IMAGE_SOURCE_ALPINE="${GEN_DOCKER_SPECIFY_IMAGE_SOURCE_ALPINE:-casjaysdev/alpine}" + GEN_DOCKER_SPECIFY_IMAGE_SOURCE_DEBIAN="${GEN_DOCKER_SPECIFY_IMAGE_SOURCE_DEBIAN:-casjaysdev/debian}" + GEN_DOCKER_SPECIFY_IMAGE_SOURCE_UBUNTU="${GEN_DOCKER_SPECIFY_IMAGE_SOURCE_UBUNTU:-casjaysdev/ubuntu}" + GEN_DOCKER_SPECIFY_IMAGE_SOURCE_ARCHLINUX="${GEN_DOCKER_SPECIFY_IMAGE_SOURCE_ARCHLINUX:-casjaysdev/archlinux}" +else + # Pull from upstream official images (dockersrc/* builds its own base images) + GEN_DOCKER_SPECIFY_IMAGE_SOURCE_RHEL="${GEN_DOCKER_SPECIFY_IMAGE_SOURCE_RHEL:-almalinux}" + GEN_DOCKER_SPECIFY_IMAGE_SOURCE_ALPINE="${GEN_DOCKER_SPECIFY_IMAGE_SOURCE_ALPINE:-alpine}" + GEN_DOCKER_SPECIFY_IMAGE_SOURCE_DEBIAN="${GEN_DOCKER_SPECIFY_IMAGE_SOURCE_DEBIAN:-debian}" + GEN_DOCKER_SPECIFY_IMAGE_SOURCE_UBUNTU="${GEN_DOCKER_SPECIFY_IMAGE_SOURCE_UBUNTU:-ubuntu}" + GEN_DOCKER_SPECIFY_IMAGE_SOURCE_ARCHLINUX="${GEN_DOCKER_SPECIFY_IMAGE_SOURCE_ARCHLINUX:-archlinux}" +fi +``` + +Summary: +- `casjaysdevdocker/*` repos → `FROM casjaysdev/:latest` (already multi-arch) +- `dockersrc/*` and all other orgs → `FROM :latest` (upstream official images) + +The Docker Hub push org (`casjaysdev`) is unchanged regardless of `GEN_DOCKERFILE_APP_DIR`. + +### Toolchain build stages are exempt from the pull-URL org rule + +Language toolchain images (e.g. `dockersrc/go`) add a dedicated build stage that pulls a +pre-built upstream toolchain image directly, independent of `PULL_URL`/`GEN_DOCKERFILE_APP_DIR`: + +```dockerfile +FROM --platform=$BUILDPLATFORM golang:alpine AS go-tools +``` + +This is intentional and correct — it speeds up building the toolchain (e.g. Go binaries) by +reusing an official prebuilt image with the compiler already installed, rather than installing it +from scratch in the `PULL_URL` base stage. Do not change these stages to use `PULL_URL` or route +them through `GEN_DOCKERFILE_APP_DIR` logic; they are a separate concern from the OS base image. + +### Arch Linux multi-arch (`archlinux.template`) + +When `GEN_DOCKERFILE_APP_DIR != "casjaysdevdocker"` (i.e. building a base image in +`dockersrc/archlinux`), the template emits a three-stage FROM to support both +`linux/amd64` and `linux/arm64`: + +```dockerfile +ARG TARGETARCH +ARG TARGETPLATFORM +FROM --platform=${TARGETPLATFORM} archlinux:latest AS base-amd64 +FROM --platform=${TARGETPLATFORM} lopsided/archlinux-arm64v8:latest AS base-arm64 +FROM base-${TARGETARCH} AS build +``` + +When `GEN_DOCKERFILE_APP_DIR = "casjaysdevdocker"`, `casjaysdev/archlinux` is a +multi-arch manifest so a single `FROM ${PULL_URL}:${DISTRO_VERSION} AS build` suffices. + +### `web.template` packages + +The `web` template installs the following systemd + noVNC stack in the build stage: + +``` +systemd systemd-sysv dbus dbus-x11 procps +tigervnc-standalone-server novnc openbox xdotool +``` + +Default ports: `SERVICE_PORT="5800"`, `EXPOSE_PORTS="5800 5900"`. + +### `xorg.template` packages + +The `xorg` template installs the following systemd + Xorg stack in the build stage: + +``` +systemd systemd-sysv dbus dbus-x11 procps +xserver-xorg x11-xserver-utils xinit +``` + +### `debian.template` / `ubuntu.template` — RUN continuation fix + +The first `RUN` block must have `; \` after the `echo` line so +`export DEBIAN_FRONTEND=noninteractive` executes before `apt-get`: + +```dockerfile +RUN set -e; \ + echo "Updating the system"; \ + export DEBIAN_FRONTEND=noninteractive; \ + apt-get update && apt-get upgrade -yy && apt-get dist-upgrade -yy +``` + +Without the `; \` the export is a no-op and `apt-get` may prompt interactively. + +--- + ## Tool Reference ### `gen-dockerfile` @@ -104,6 +272,11 @@ else REPO_TYPE="app" org="casjaysdevdocker" fi + +# GEN_DOCKERFILE_APP_DIR is auto-detected by gen-dockerfile from the parent of $PWD. +# For repos under casjaysdevdocker/: pull base from casjaysdev/* (pre-built multi-arch). +# For repos under dockersrc/ or any other org: pull from upstream official images. +# Override by setting GEN_DOCKERFILE_APP_DIR in the environment before calling gen-dockerfile. ``` --- @@ -381,8 +554,8 @@ dockermgr update {name} ## Install and run container ```shell -dockerHome="/var/lib/srv/$USER/docker/casjaysdevdocker/{name}/{name}/latest/rootfs" -mkdir -p "/var/lib/srv/$USER/docker/{name}/rootfs" +dockerHome="/srv/$USER/docker/casjaysdevdocker/{name}/{name}/latest/rootfs" +mkdir -p "/srv/$USER/docker/{name}/rootfs" git clone "https://github.com/dockermgr/{name}" "$HOME/.local/share/CasjaysDev/dockermgr/{name}" cp -Rfva "$HOME/.local/share/CasjaysDev/dockermgr/{name}/rootfs/." "$dockerHome/" docker run -d \ @@ -409,8 +582,8 @@ services: - TZ=America/New_York - HOSTNAME={name} volumes: - - "/var/lib/srv/$USER/docker/casjaysdevdocker/{name}/{name}/latest/rootfs/data:/data:z" - - "/var/lib/srv/$USER/docker/casjaysdevdocker/{name}/{name}/latest/rootfs/config:/config:z" + - "/srv/$USER/docker/casjaysdevdocker/{name}/{name}/latest/rootfs/data:/data:z" + - "/srv/$USER/docker/casjaysdevdocker/{name}/{name}/latest/rootfs/config:/config:z" ports: - {port}:{port} restart: always @@ -465,17 +638,17 @@ dockermgr update os {name} ## Install and run container ```shell -mkdir -p "/var/lib/srv/root/docker/casjaysdev/{name}/latest" +mkdir -p "/srv/root/docker/casjaysdev/{name}/latest" git clone "https://github.com/dockermgr/{name}" "$HOME/.local/share/CasjaysDev/dockermgr/{name}" -cp -Rfva "$HOME/.local/share/CasjaysDev/dockermgr/{name}/rootfs/." "/var/lib/srv/root/docker/casjaysdev/{name}/latest/" +cp -Rfva "$HOME/.local/share/CasjaysDev/dockermgr/{name}/rootfs/." "/srv/root/docker/casjaysdev/{name}/latest/" docker run -d \ --restart always \ --privileged \ --name casjaysdev-{name}-latest \ --hostname {name} \ -e TZ=${TIMEZONE:-America/New_York} \ --v "/var/lib/srv/root/docker/casjaysdev/{name}/latest/data:/data:z" \ --v "/var/lib/srv/root/docker/casjaysdev/{name}/latest/config:/config:z" \ +-v "/srv/root/docker/casjaysdev/{name}/latest/data:/data:z" \ +-v "/srv/root/docker/casjaysdev/{name}/latest/config:/config:z" \ casjaysdev/{name}:latest ``` @@ -491,8 +664,8 @@ services: - TZ=America/New_York - HOSTNAME={name} volumes: - - "/var/lib/srv/root/docker/casjaysdev/{name}/latest/data:/data:z" - - "/var/lib/srv/root/docker/casjaysdev/{name}/latest/config:/config:z" + - "/srv/root/docker/casjaysdev/{name}/latest/data:/data:z" + - "/srv/root/docker/casjaysdev/{name}/latest/config:/config:z" restart: always ``` diff --git a/Dockerfile b/Dockerfile index 1cac153..d1bd9fb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,7 +24,7 @@ ARG IMAGE_REPO="casjaysdev/go" ARG IMAGE_VERSION="latest" ARG CONTAINER_VERSION="" -ARG PULL_URL="casjaysdev/alpine" +ARG PULL_URL="alpine" ARG DISTRO_VERSION="${IMAGE_VERSION}" ARG BUILD_VERSION="${BUILD_DATE}" @@ -247,19 +247,16 @@ WORKDIR /app LABEL maintainer="CasjaysDev " LABEL org.opencontainers.image.vendor="CasjaysDev" LABEL org.opencontainers.image.authors="CasjaysDev" -LABEL org.opencontainers.image.description="Containerized version of ${IMAGE_NAME}" +LABEL org.opencontainers.image.licenses="${LICENSE}" LABEL org.opencontainers.image.title="${IMAGE_NAME}" -LABEL org.opencontainers.image.base.name="${IMAGE_NAME}" -LABEL org.opencontainers.image.authors="${LICENSE}" +LABEL org.opencontainers.image.description="Containerized version of ${IMAGE_NAME}" LABEL org.opencontainers.image.created="${BUILD_DATE}" LABEL org.opencontainers.image.version="${BUILD_VERSION}" -LABEL org.opencontainers.image.schema-version="${BUILD_VERSION}" -LABEL org.opencontainers.image.url="https://hub.docker.com/casjaysdevdocker/go" -LABEL org.opencontainers.image.source="https://hub.docker.com/casjaysdevdocker/go" -LABEL org.opencontainers.image.vcs-type="Git" LABEL org.opencontainers.image.revision="${GIT_COMMIT}" -LABEL org.opencontainers.image.source="https://github.com/casjaysdevdocker/go" -LABEL org.opencontainers.image.documentation="https://github.com/casjaysdevdocker/go" +LABEL org.opencontainers.image.url="https://docker.io/casjaysdev/go" +LABEL org.opencontainers.image.source="https://github.com/dockersrc/go" +LABEL org.opencontainers.image.documentation="https://github.com/dockersrc/go" +LABEL org.opencontainers.image.vcs-type="Git" LABEL com.github.containers.toolbox="false" ENV ENV=~/.bashrc @@ -273,7 +270,7 @@ ENV TERM="xterm-256color" ENV PORT="${SERVICE_PORT}" ENV ENV_PORTS="${ENV_PORTS}" ENV CONTAINER_NAME="${IMAGE_NAME}" -ENV HOSTNAME="casjaysdev-${IMAGE_NAME}" +ENV HOSTNAME="casjaysdevdocker-${IMAGE_NAME}" ENV PHP_SERVER="${PHP_SERVER}" ENV NODE_VERSION="${NODE_VERSION}" ENV NODE_MANAGER="${NODE_MANAGER}" diff --git a/rootfs/root/docker/setup/00-init.sh b/rootfs/root/docker/setup/00-init.sh index ae6ff51..7ad5d15 100755 --- a/rootfs/root/docker/setup/00-init.sh +++ b/rootfs/root/docker/setup/00-init.sh @@ -1,12 +1,12 @@ #!/usr/bin/env bash # shellcheck shell=bash # - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202605292220-git +##@Version : 202607092021-git # @@Author : CasjaysDev # @@Contact : CasjaysDev -# @@License : MIT +# @@License : WTFPL # @@Copyright : Copyright 2026 CasjaysDev -# @@Created : Fri May 29 10:20:08 PM EDT 2026 +# @@Created : Thu Jul 9 08:21:30 PM EDT 2026 # @@File : 00-init.sh # @@Description : script to run init # @@Changelog : newScript @@ -20,7 +20,7 @@ # shellcheck disable=SC1001,SC1003,SC2001,SC2003,SC2016,SC2031,SC2090,SC2115,SC2120,SC2155,SC2199,SC2229,SC2317,SC2329 # - - - - - - - - - - - - - - - - - - - - - - - - - # Set bash options -set -o pipefail +set -eo pipefail [ "$DEBUGGER" = "on" ] && echo "Enabling debugging" && set -x$DEBUGGER_OPTIONS # - - - - - - - - - - - - - - - - - - - - - - - - - # Set env variables @@ -28,9 +28,7 @@ exitCode=0 # - - - - - - - - - - - - - - - - - - - - - - - - - # Predefined actions -if [ -d "/usr/local/share/template-files/data" ]; then rm -Rf "/usr/local/share/template-files/data"/*; fi -if [ -d "/usr/local/share/template-files/config" ]; then rm -Rf "/usr/local/share/template-files/config"/*; fi -if [ -d "/usr/local/share/template-files/defaults" ]; then rm -Rf "/usr/local/share/template-files/defaults"/*; fi + # - - - - - - - - - - - - - - - - - - - - - - - - - # Main script diff --git a/rootfs/root/docker/setup/01-system.sh b/rootfs/root/docker/setup/01-system.sh index df88580..812a08c 100755 --- a/rootfs/root/docker/setup/01-system.sh +++ b/rootfs/root/docker/setup/01-system.sh @@ -1,12 +1,12 @@ #!/usr/bin/env bash # shellcheck shell=bash # - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202605292220-git +##@Version : 202607092021-git # @@Author : CasjaysDev # @@Contact : CasjaysDev -# @@License : MIT +# @@License : WTFPL # @@Copyright : Copyright 2026 CasjaysDev -# @@Created : Fri May 29 10:20:08 PM EDT 2026 +# @@Created : Thu Jul 9 08:21:31 PM EDT 2026 # @@File : 01-system.sh # @@Description : script to run system # @@Changelog : newScript @@ -20,7 +20,7 @@ # shellcheck disable=SC1001,SC1003,SC2001,SC2003,SC2016,SC2031,SC2090,SC2115,SC2120,SC2155,SC2199,SC2229,SC2317,SC2329 # - - - - - - - - - - - - - - - - - - - - - - - - - # Set bash options -set -o pipefail +set -eo pipefail [ "$DEBUGGER" = "on" ] && echo "Enabling debugging" && set -x$DEBUGGER_OPTIONS # - - - - - - - - - - - - - - - - - - - - - - - - - # Set env variables diff --git a/rootfs/root/docker/setup/02-packages.sh b/rootfs/root/docker/setup/02-packages.sh index 7373ddc..cc53409 100755 --- a/rootfs/root/docker/setup/02-packages.sh +++ b/rootfs/root/docker/setup/02-packages.sh @@ -1,12 +1,12 @@ #!/usr/bin/env bash # shellcheck shell=bash # - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202605292220-git +##@Version : 202607092021-git # @@Author : CasjaysDev # @@Contact : CasjaysDev -# @@License : MIT +# @@License : WTFPL # @@Copyright : Copyright 2026 CasjaysDev -# @@Created : Fri May 29 10:20:09 PM EDT 2026 +# @@Created : Thu Jul 9 08:21:32 PM EDT 2026 # @@File : 02-packages.sh # @@Description : script to run packages # @@Changelog : newScript @@ -20,7 +20,7 @@ # shellcheck disable=SC1001,SC1003,SC2001,SC2003,SC2016,SC2031,SC2090,SC2115,SC2120,SC2155,SC2199,SC2229,SC2317,SC2329 # - - - - - - - - - - - - - - - - - - - - - - - - - # Set bash options -set -o pipefail +set -eo pipefail [ "$DEBUGGER" = "on" ] && echo "Enabling debugging" && set -x$DEBUGGER_OPTIONS # - - - - - - - - - - - - - - - - - - - - - - - - - # Set env variables diff --git a/rootfs/root/docker/setup/03-files.sh b/rootfs/root/docker/setup/03-files.sh index c1fc0ee..da42dab 100755 --- a/rootfs/root/docker/setup/03-files.sh +++ b/rootfs/root/docker/setup/03-files.sh @@ -1,12 +1,12 @@ #!/usr/bin/env bash # shellcheck shell=bash # - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202605292220-git +##@Version : 202607092021-git # @@Author : CasjaysDev # @@Contact : CasjaysDev -# @@License : MIT +# @@License : WTFPL # @@Copyright : Copyright 2026 CasjaysDev -# @@Created : Fri May 29 10:20:09 PM EDT 2026 +# @@Created : Thu Jul 9 08:21:32 PM EDT 2026 # @@File : 03-files.sh # @@Description : script to run files # @@Changelog : newScript @@ -20,7 +20,7 @@ # shellcheck disable=SC1001,SC1003,SC2001,SC2003,SC2016,SC2031,SC2090,SC2115,SC2120,SC2155,SC2199,SC2229,SC2317,SC2329 # - - - - - - - - - - - - - - - - - - - - - - - - - # Set bash options -set -o pipefail +set -eo pipefail [ "$DEBUGGER" = "on" ] && echo "Enabling debugging" && set -x$DEBUGGER_OPTIONS # - - - - - - - - - - - - - - - - - - - - - - - - - # Set env variables @@ -61,29 +61,23 @@ if [ -d "/tmp/etc" ]; then if [ -d "$config" ]; then mkdir -p "/etc/$name" cp -Rf "$config/." "/etc/$name/" - mkdir -p "/usr/local/share/template-files/config/$name" - cp -Rf "$config/." "/usr/local/share/template-files/config/$name/" else cp -Rf "$config" "/etc/$name" - cp -Rf "$config" "/usr/local/share/template-files/config/$name" fi done fi unset config -if [ -d "/tmp/data" ]; then - for data in "/tmp/data"/*; do - [ -e "$data" ] || continue - name="${data##*/}" - echo "Installing $data to /usr/local/share/template-files/data" - if [ -d "$data" ]; then - mkdir -p "/usr/local/share/template-files/data/$name" - cp -Rf "$data/." "/usr/local/share/template-files/data/$name/" - else - cp -Rf "$data" "/usr/local/share/template-files/data/$name" - fi +if [ -d "/tmp/usr" ]; then + for share in "/tmp/usr"/*; do + [ -e "$share" ] || continue + name="${share##*/}" + dest="/usr/$name" + echo "Installing $share to $dest" + mkdir -p "$dest" + cp -Rf "$share/." "$dest/" done fi -unset data +unset share # - - - - - - - - - - - - - - - - - - - - - - - - - # Main script diff --git a/rootfs/root/docker/setup/04-users.sh b/rootfs/root/docker/setup/04-users.sh index 98b6c12..d017dcd 100755 --- a/rootfs/root/docker/setup/04-users.sh +++ b/rootfs/root/docker/setup/04-users.sh @@ -1,12 +1,12 @@ #!/usr/bin/env bash # shellcheck shell=bash # - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202605292220-git +##@Version : 202607092021-git # @@Author : CasjaysDev # @@Contact : CasjaysDev -# @@License : MIT +# @@License : WTFPL # @@Copyright : Copyright 2026 CasjaysDev -# @@Created : Fri May 29 10:20:09 PM EDT 2026 +# @@Created : Thu Jul 9 08:21:32 PM EDT 2026 # @@File : 04-users.sh # @@Description : script to run users # @@Changelog : newScript @@ -20,7 +20,7 @@ # shellcheck disable=SC1001,SC1003,SC2001,SC2003,SC2016,SC2031,SC2090,SC2115,SC2120,SC2155,SC2199,SC2229,SC2317,SC2329 # - - - - - - - - - - - - - - - - - - - - - - - - - # Set bash options -set -o pipefail +set -eo pipefail [ "$DEBUGGER" = "on" ] && echo "Enabling debugging" && set -x$DEBUGGER_OPTIONS # - - - - - - - - - - - - - - - - - - - - - - - - - # Set env variables diff --git a/rootfs/root/docker/setup/05-custom.sh b/rootfs/root/docker/setup/05-custom.sh index 14af04d..0880677 100755 --- a/rootfs/root/docker/setup/05-custom.sh +++ b/rootfs/root/docker/setup/05-custom.sh @@ -1,18 +1,18 @@ #!/usr/bin/env bash # shellcheck shell=bash # - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202606010000-git +##@Version : 202607092021-git # @@Author : CasjaysDev # @@Contact : CasjaysDev -# @@License : MIT +# @@License : WTFPL # @@Copyright : Copyright 2026 CasjaysDev -# @@Created : Fri May 29 10:20:10 PM EDT 2026 +# @@Created : Thu Jul 9 08:21:32 PM EDT 2026 # @@File : 05-custom.sh -# @@Description : Install Go latest and Go tooling -# @@Changelog : Use pre-built binaries where available; go install for the rest -# @@TODO : N/A +# @@Description : script to run custom +# @@Changelog : newScript +# @@TODO : Refactor code # @@Other : N/A -# @@Resource : https://go.dev/dl/ +# @@Resource : N/A # @@Terminal App : yes # @@sudo/root : yes # @@Template : templates/dockerfiles/init_scripts/05-custom.sh @@ -22,193 +22,15 @@ # Set bash options set -eo pipefail [ "$DEBUGGER" = "on" ] && echo "Enabling debugging" && set -x$DEBUGGER_OPTIONS -# Force IPv4 for all curl calls in this script — the base image IPv6 routing -# intercepts *.github.com and presents a cert for casjay.in, causing SAN mismatch -printf -- '-4\n' > /root/.curlrc # - - - - - - - - - - - - - - - - - - - - - - - - - # Set env variables exitCode=0 -# Installation root for the Go distribution (not GOPATH) -GOINSTALL_DIR="/usr/local/go" -# GOPATH: module cache, pkg index, user-installed binaries (declared VOLUME) -GOPATH_DIR="/usr/local/share/go" -# Baked-in tool binaries land here so they are on the default PATH -GOBIN_DIR="/usr/local/bin" -# Throwaway build cache used only during this image build layer -GOCACHE_BUILD="/tmp/go-build-cache" +# - - - - - - - - - - - - - - - - - - - - - - - - - +# Predefined actions # - - - - - - - - - - - - - - - - - - - - - - - - - -# Helpers - -# Return the latest release tag from GitHub; retries up to 3 times on transient errors -# (rate-limit 403s are common in parallel multi-platform builds without a token). -# Set GITHUB_TOKEN to raise the authenticated rate limit (5000 req/hr vs 60 req/hr). -_gh_latest() { - local repo="$1" - local filter="${2:-.tag_name}" - local auth_header="" - [ -n "${GITHUB_TOKEN:-}" ] && auth_header="-H Authorization: token ${GITHUB_TOKEN}" - local ver attempt - for attempt in 1 2 3; do - # shellcheck disable=SC2206 - ver="$(curl -fsSL ${auth_header:+$auth_header} "https://api.github.com/repos/${repo}/releases/latest" | jq -r "${filter}")" - if [ -n "$ver" ] && [ "$ver" != "null" ]; then - echo "$ver" - return 0 - fi - if [ "$attempt" -lt 3 ]; then - echo " rate-limited on ${repo} (attempt ${attempt}/3) — retrying in 60s..." >&2 - sleep 60 - fi - done - echo "ERROR: could not resolve latest version for ${repo} after 3 attempts" >&2 - exit 1 -} - -# Download a tar.gz asset, find a named binary anywhere inside, install to GOBIN_DIR -_install_tar() { - local url="$1" - local bin="$2" - local tmp - tmp="$(mktemp -d)" - echo " → ${bin} from ${url##*/}" - curl -fsSL "$url" | tar -C "$tmp" -xz - local found - found="$(find "$tmp" -name "$bin" -type f | head -1)" - if [ -z "$found" ]; then - echo "ERROR: binary '${bin}' not found in archive ${url##*/}" >&2 - rm -rf "$tmp" - exit 1 - fi - install -m 0755 "$found" "${GOBIN_DIR}/${bin}" - rm -rf "$tmp" -} - -# Download a single binary asset directly to GOBIN_DIR -_install_bin() { - local url="$1" - local name="$2" - echo " → ${name} from ${url##*/}" - curl -fsSL "$url" -o "${GOBIN_DIR}/${name}" - chmod 0755 "${GOBIN_DIR}/${name}" -} - -# - - - - - - - - - - - - - - - - - - - - - - - - - -# Architecture detection - -# Go convention: amd64 / arm64 / armv6l / 386 -case "$(uname -m)" in - x86_64) _GOARCH="amd64" ;; - aarch64) _GOARCH="arm64" ;; - armv7l) _GOARCH="armv6l" ;; - i386|i686) _GOARCH="386" ;; - *) - echo "Unsupported architecture: $(uname -m)" >&2 - exit 1 - ;; -esac - -# uname -m verbatim: buf uses x86_64 / aarch64 -_UNAME_M="$(uname -m)" - -# goreleaser / ko / goose use x86_64 / arm64 (arm64 not aarch64) -if [ "$_UNAME_M" = "aarch64" ]; then - _ARCH_GLIBC="arm64" -else - _ARCH_GLIBC="$_UNAME_M" -fi - -# - - - - - - - - - - - - - - - - - - - - - - - - - -# Install Go distribution - -_GO_VERSION="$(curl -fsSL 'https://go.dev/dl/?mode=json' | jq -r '.[0].version')" -echo "Installing ${_GO_VERSION} (linux/${_GOARCH})" - -rm -rf "${GOINSTALL_DIR}" -curl -fsSL "https://dl.google.com/go/${_GO_VERSION}.linux-${_GOARCH}.tar.gz" | tar -C /usr/local -xz - -ln -sf "${GOINSTALL_DIR}/bin/go" "${GOBIN_DIR}/go" -ln -sf "${GOINSTALL_DIR}/bin/gofmt" "${GOBIN_DIR}/gofmt" - -export GOPATH="${GOPATH_DIR}" -export GOBIN="${GOBIN_DIR}" -export PATH="${GOINSTALL_DIR}/bin:${PATH}" -export GOCACHE="${GOCACHE_BUILD}" -export CGO_ENABLED="0" -export GOTOOLCHAIN="auto" - -mkdir -p "${GOPATH_DIR}/pkg/mod" "${GOPATH_DIR}/cache" "${GOPATH_DIR}/bin" - -# - - - - - - - - - - - - - - - - - - - - - - - - - -# Pre-built binary installs (fast — no compilation) - -echo "Installing pre-built tools" - -# goreleaser — release automation (Linux/x86_64 or Linux/arm64) -_GR_VER="$(_gh_latest goreleaser/goreleaser)" -_install_tar \ - "https://github.com/goreleaser/goreleaser/releases/download/${_GR_VER}/goreleaser_Linux_${_ARCH_GLIBC}.tar.gz" \ - "goreleaser" - -# golangci-lint — meta-linter (official installer handles its own version resolution) -curl -fsSL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh \ - | sh -s -- -b "${GOBIN_DIR}" latest - -# staticcheck — standalone advanced static analyser (linux_amd64 / linux_arm64) -_SC_VER="$(_gh_latest dominikh/go-tools)" -_install_tar \ - "https://github.com/dominikh/go-tools/releases/download/${_SC_VER}/staticcheck_linux_${_GOARCH}.tar.gz" \ - "staticcheck" - -# gofumpt — stricter formatter; asset name includes version: gofumpt_v0.x.y_linux_amd64 -_GF_VER="$(_gh_latest mvdan/gofumpt)" -_install_bin \ - "https://github.com/mvdan/gofumpt/releases/download/${_GF_VER}/gofumpt_${_GF_VER}_linux_${_GOARCH}" \ - "gofumpt" - -# gotestsum — structured test runner; asset uses amd64/arm64 (not x86_64) -_GTS_VER="$(_gh_latest gotestyourself/gotestsum)" -_GTS_TAG="${_GTS_VER#v}" -_install_tar \ - "https://github.com/gotestyourself/gotestsum/releases/download/${_GTS_VER}/gotestsum_${_GTS_TAG}_linux_${_GOARCH}.tar.gz" \ - "gotestsum" - -# ko — build Go container images without a Dockerfile (Linux/x86_64 or Linux/arm64) -_KO_VER="$(_gh_latest google/ko)" -_KO_TAG="${_KO_VER#v}" -_install_tar \ - "https://github.com/google/ko/releases/download/${_KO_VER}/ko_${_KO_TAG}_Linux_${_ARCH_GLIBC}.tar.gz" \ - "ko" - -# air — live-reload dev server; asset: air_1.x.y_linux_amd64 (version without v prefix) -_AIR_VER="$(_gh_latest air-verse/air)" -_AIR_TAG="${_AIR_VER#v}" -_install_bin \ - "https://github.com/air-verse/air/releases/download/${_AIR_VER}/air_${_AIR_TAG}_linux_${_GOARCH}" \ - "air" - -# buf — modern protobuf toolchain; uses x86_64/aarch64 (uname -m convention) -_BUF_VER="$(_gh_latest bufbuild/buf)" -_install_bin \ - "https://github.com/bufbuild/buf/releases/download/${_BUF_VER}/buf-Linux-${_UNAME_M}" \ - "buf" - -# goose — DB migration runner (linux_x86_64 or linux_arm64) -_GOOSE_VER="$(_gh_latest pressly/goose)" -_install_bin \ - "https://github.com/pressly/goose/releases/download/${_GOOSE_VER}/goose_linux_${_ARCH_GLIBC}" \ - "goose" - -# go install tools (goimports, stringer, gopls, govulncheck, dlv, gops, benchstat, -# wire, mockgen, protoc-gen-go, protoc-gen-go-grpc) are cross-compiled natively on -# the build platform in the Dockerfile go-tools stage and copied to /usr/local/bin -# before this script runs — no QEMU-emulated compilation needed here. - -# Strip the module download cache and ephemeral build cache from this layer -go clean -modcache -go clean -cache -rm -rf "${GOCACHE_BUILD}" +# Main script # - - - - - - - - - - - - - - - - - - - - - - - - - # Set the exit code @@ -218,3 +40,4 @@ exit $exitCode # - - - - - - - - - - - - - - - - - - - - - - - - - # ex: ts=2 sw=2 et filetype=sh # - - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/rootfs/root/docker/setup/06-post.sh b/rootfs/root/docker/setup/06-post.sh index 9702709..59a2528 100755 --- a/rootfs/root/docker/setup/06-post.sh +++ b/rootfs/root/docker/setup/06-post.sh @@ -1,12 +1,12 @@ #!/usr/bin/env bash # shellcheck shell=bash # - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202605292220-git +##@Version : 202607092021-git # @@Author : CasjaysDev # @@Contact : CasjaysDev -# @@License : MIT +# @@License : WTFPL # @@Copyright : Copyright 2026 CasjaysDev -# @@Created : Fri May 29 10:20:11 PM EDT 2026 +# @@Created : Thu Jul 9 08:21:32 PM EDT 2026 # @@File : 06-post.sh # @@Description : script to run post # @@Changelog : newScript @@ -20,7 +20,7 @@ # shellcheck disable=SC1001,SC1003,SC2001,SC2003,SC2016,SC2031,SC2090,SC2115,SC2120,SC2155,SC2199,SC2229,SC2317,SC2329 # - - - - - - - - - - - - - - - - - - - - - - - - - # Set bash options -set -o pipefail +set -eo pipefail [ "$DEBUGGER" = "on" ] && echo "Enabling debugging" && set -x$DEBUGGER_OPTIONS # - - - - - - - - - - - - - - - - - - - - - - - - - # Set env variables diff --git a/rootfs/root/docker/setup/07-cleanup.sh b/rootfs/root/docker/setup/07-cleanup.sh index 5ce7f9d..a4b810a 100755 --- a/rootfs/root/docker/setup/07-cleanup.sh +++ b/rootfs/root/docker/setup/07-cleanup.sh @@ -1,12 +1,12 @@ #!/usr/bin/env bash # shellcheck shell=bash # - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202605292220-git +##@Version : 202607092021-git # @@Author : CasjaysDev # @@Contact : CasjaysDev -# @@License : MIT +# @@License : WTFPL # @@Copyright : Copyright 2026 CasjaysDev -# @@Created : Fri May 29 10:20:11 PM EDT 2026 +# @@Created : Thu Jul 9 08:21:33 PM EDT 2026 # @@File : 07-cleanup.sh # @@Description : script to run cleanup # @@Changelog : newScript @@ -20,7 +20,7 @@ # shellcheck disable=SC1001,SC1003,SC2001,SC2003,SC2016,SC2031,SC2090,SC2115,SC2120,SC2155,SC2199,SC2229,SC2317,SC2329 # - - - - - - - - - - - - - - - - - - - - - - - - - # Set bash options -set -o pipefail +set -eo pipefail [ "$DEBUGGER" = "on" ] && echo "Enabling debugging" && set -x$DEBUGGER_OPTIONS # - - - - - - - - - - - - - - - - - - - - - - - - - # Load functions diff --git a/rootfs/usr/local/bin/entrypoint.sh b/rootfs/usr/local/bin/entrypoint.sh index 589ec0b..a73004b 100755 --- a/rootfs/usr/local/bin/entrypoint.sh +++ b/rootfs/usr/local/bin/entrypoint.sh @@ -1,19 +1,19 @@ #!/usr/bin/env bash # shellcheck shell=bash # - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202606261500-git +##@Version : 202607082023-git # @@Author : Jason Hempstead # @@Contact : jason@casjaysdev.pro # @@License : WTFPL # @@ReadME : entrypoint.sh --help # @@Copyright : Copyright: (c) 2026 Jason Hempstead, Casjays Developments -# @@Created : Friday, May 29, 2026 22:19 EDT +# @@Created : Thursday, Jul 09, 2026 20:21 EDT # @@File : entrypoint.sh -# @@Description : Entrypoint file for alpine +# @@Description : Entrypoint file for go # @@Changelog : New script # @@TODO : Better documentation -# @@Other : -# @@Resource : +# @@Other : +# @@Resource : # @@Terminal App : no # @@sudo/root : no # @@Template : other/docker-entrypoint @@ -28,11 +28,11 @@ trap 'retVal=$?;[ "$SERVICE_IS_RUNNING" != "yes" ] && [ -f "$SERVICE_PID_FILE" ] [ -f "/config/.debug" ] && [ -z "$DEBUGGER_OPTIONS" ] && export DEBUGGER_OPTIONS="$(<"/config/.debug")" || DEBUGGER_OPTIONS="${DEBUGGER_OPTIONS:-}" if [ "$DEBUGGER" = "on" ] || [ -f "/config/.debug" ]; then echo "Enabling debugging" - set -o pipefail + set -eo pipefail [ -n "$DEBUGGER_OPTIONS" ] && set -"$DEBUGGER_OPTIONS" export DEBUGGER="on" else - set -o pipefail + set -eo pipefail fi # - - - - - - - - - - - - - - - - - - - - - - - - - PATH="/usr/local/etc/docker/bin:/usr/local/bin:/usr/bin:/usr/sbin:/bin:/sbin" @@ -95,8 +95,8 @@ SERVICE_UID="${SERVICE_UID:-0}" SERVICE_GID="${SERVICE_GID:-0}" # - - - - - - - - - - - - - - - - - - - - - - - - - # User and group in which the service switches to - IE: nginx,apache,mysql,postgres -#SERVICE_USER="${SERVICE_USER:-alpine}" # execute command as another user -#SERVICE_GROUP="${SERVICE_GROUP:-alpine}" # Set the service group +#SERVICE_USER="${SERVICE_USER:-go}" # execute command as another user +#SERVICE_GROUP="${SERVICE_GROUP:-go}" # Set the service group # - - - - - - - - - - - - - - - - - - - - - - - - - # Secondary ports # specifiy other ports @@ -108,7 +108,7 @@ WEB_SERVER_PORT="" # - - - - - - - - - - - - - - - - - - - - - - - - - # Healthcheck variables # enable healthcheck [yes/no] -HEALTH_ENABLED="${HEALTH_ENABLED:-yes}" +HEALTH_ENABLED="yes" # comma separated list of processes for the healthcheck SERVICES_LIST="tini" # url endpoints: [http://localhost/health,http://localhost/test] @@ -123,7 +123,7 @@ export PATH RUNAS_USER SERVICE_USER SERVICE_GROUP SERVICE_UID SERVICE_GID WWW_RO # show message __run_message() { - return + return 0 } # - - - - - - - - - - - - - - - - - - - - - - - - - ################## END OF CONFIGURATION ##################### @@ -155,9 +155,6 @@ export SSL_CA="${SSL_CA:-/config/ssl/ca.crt}" export SSL_KEY="${SSL_KEY:-/config/ssl/localhost.pem}" export SSL_CERT="${SSL_CERT:-/config/ssl/localhost.crt}" export LOCAL_BIN_DIR="${LOCAL_BIN_DIR:-/usr/local/bin}" -export DEFAULT_DATA_DIR="${DEFAULT_DATA_DIR:-/usr/local/share/template-files/data}" -export DEFAULT_CONF_DIR="${DEFAULT_CONF_DIR:-/usr/local/share/template-files/config}" -export DEFAULT_TEMPLATE_DIR="${DEFAULT_TEMPLATE_DIR:-/usr/local/share/template-files/defaults}" # - - - - - - - - - - - - - - - - - - - - - - - - - # Backup settings export BACKUP_MAX_DAYS="${BACKUP_MAX_DAYS:-}" @@ -214,15 +211,15 @@ else fi # - - - - - - - - - - - - - - - - - - - - - - - - - # clean ENV_PORTS variables -ENV_PORTS="${ENV_PORTS//,/ }" # -ENV_PORTS="${ENV_PORTS//\/*/}" # +ENV_PORTS="${ENV_PORTS//,/ }" +ENV_PORTS="${ENV_PORTS//\/*/}" # - - - - - - - - - - - - - - - - - - - - - - - - - # clean SERVER_PORTS variables -SERVER_PORTS="${SERVER_PORTS//,/ }" # -SERVER_PORTS="${SERVER_PORTS//\/*/}" # +SERVER_PORTS="${SERVER_PORTS//,/ }" +SERVER_PORTS="${SERVER_PORTS//\/*/}" # - - - - - - - - - - - - - - - - - - - - - - - - - # clean WEB_SERVER_PORTS variables -WEB_SERVER_PORTS="${WEB_SERVER_PORT//,/ } ${ENV_WEB_SERVER_PORTS//,/ }" # +WEB_SERVER_PORTS="${WEB_SERVER_PORT//,/ } ${ENV_WEB_SERVER_PORTS//,/ }" # - - - - - - - - - - - - - - - - - - - - - - - - - # rewrite and merge variables ENV_PORTS="$(__format_variables "$ENV_PORTS" || false)" @@ -373,7 +370,7 @@ if [ "$ENTRYPOINT_FIRST_RUN" != "no" ]; then # - - - - - - - - - - - - - - - - - - - - - - - - - # import hosts file into container if [ -f "/usr/local/etc/hosts" ] && [ "$UPDATE_FILE_HOSTS" = "yes" ]; then - grep -vF "$HOSTNAME" "/usr/local/etc/hosts" 2>/dev/null >>"/etc/hosts" || true + grep -vF -- "$HOSTNAME" "/usr/local/etc/hosts" 2>/dev/null >>"/etc/hosts" || true fi # - - - - - - - - - - - - - - - - - - - - - - - - - # import resolv.conf file into container @@ -425,8 +422,8 @@ if [ "$ENTRYPOINT_FIRST_RUN" != "no" ] || [ "$CONFIG_DIR_INITIALIZED" = "no" ] | echo "Initialized on: $INIT_DATE" >"$ENTRYPOINT_INIT_FILE" 2>/dev/null || true fi # - - - - - - - - - - - - - - - - - - - - - - - - - - # setup the smtp server — non-fatal; this image does not use ssmtp - __setup_mta || true + # setup the smtp server + __setup_mta # - - - - - - - - - - - - - - - - - - - - - - - - - ENTRYPOINT_FIRST_RUN="no" fi @@ -491,11 +488,9 @@ if [ "$START_SERVICES" = "yes" ] || [ -z "$1" ]; then echo "$$" >"$ENTRYPOINT_PID_FILE" __start_init_scripts "/usr/local/etc/docker/init.d" CONTAINER_INIT="${CONTAINER_INIT:-no}" - # No user command: run default Go workflow instead of blocking - if [ $# -eq 0 ]; then - go-workflow "$@" - exit $? - fi + # Services started successfully - enter monitoring mode + __no_exit + exit $? fi START_SERVICES="no" fi @@ -581,7 +576,7 @@ healthcheck) services+="$name " done fi - services="$(printf '%s\n' $services | sort -u | grep -v '^$')" + services="$(printf '%s\n' $services | sort -u | grep -v -- '^$')" for proc in $services; do if [ -n "$proc" ]; then if ! __pgrep "$proc"; then @@ -592,7 +587,7 @@ healthcheck) done for port in $healthPorts; do if command -v netstat &>/dev/null && [ -n "$port" ]; then - if ! netstat -taupln | grep -q ":$port "; then + if ! netstat -taupln | grep -q -- ":$port "; then echo "$port isn't open" >&2 healthStatus=$((healthStatus + 1)) fi @@ -622,29 +617,25 @@ ports) # show running processes procs) shift 1 - ps="$(__ps axco command 2>/dev/null | grep -vE '^(COMMAND|grep|ps)$' | sort -u)" + ps="$(__ps axco command 2>/dev/null | grep -vE -- '^(COMMAND|grep|ps)$' | sort -u)" [ -n "$ps" ] && printf '%s\n%s\n' "Found the following processes" "$ps" | tr '\n' ' ' exit $? ;; # Launch shell */bin/sh | */bin/bash | bash | sh | shell) - shell_bin="$(type -P "${1}" 2>/dev/null || echo "/bin/bash")" shift 1 - if [ $# -gt 0 ]; then - __exec_command "$shell_bin" "$@" - else - __exec_command "$shell_bin" -l - fi + __exec_command "$@" exit $? ;; # execute commands exec) shift 1 if [ $# -eq 0 ]; then - echo "Error: exec requires a command" >&2 + echo "No command given to exec" >&2 exit 1 fi - exec "$@" + __exec_command "$@" + exit $? ;; # show/start init scripts start) @@ -669,11 +660,15 @@ start) # Execute primary command *) if [ $# -eq 0 ]; then - # No args: run the default Go workflow (tidy → fmt → vet → test → build) - exec go-workflow + if [ ! -f "$ENTRYPOINT_PID_FILE" ]; then + echo "$$" >"$ENTRYPOINT_PID_FILE" + [ "$START_SERVICES" = "no" ] && [ "$CONTAINER_INIT" = "yes" ] || __start_init_scripts "/usr/local/etc/docker/init.d" + fi + __no_exit else - exec "$@" + __exec_command "$@" fi + exit $? ;; esac # - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/rootfs/usr/local/etc/docker/functions/entrypoint.sh b/rootfs/usr/local/etc/docker/functions/entrypoint.sh index c917d98..cd3ad72 100644 --- a/rootfs/usr/local/etc/docker/functions/entrypoint.sh +++ b/rootfs/usr/local/etc/docker/functions/entrypoint.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # shellcheck shell=bash # - - - - - - - - - - - - - - - - - - - - - - - - - -##@Version : 202606261430-git +##@Version : 202607082330-git # @@Author : Jason Hempstead # @@Contact : git-admin@casjaysdev.pro # @@License : LICENSE.md @@ -93,7 +93,11 @@ __is_in_file() { [ -e "$2" ] && grep -Rsq "$1" "$2" 2>/dev/null; } __curl() { curl -q -sfI --max-time 3 -k -o /dev/null "$@" 2>/dev/null || return 10; } __find() { local result - result=$(find "$1" -mindepth 1 -type "${2:-f,d}" 2>/dev/null) + if [ -n "$2" ]; then + result=$(find "$1" -mindepth 1 -type "$2" 2>/dev/null) + else + result=$(find "$1" -mindepth 1 \( -type f -o -type d \) 2>/dev/null) + fi [ -n "$result" ] || return 10 printf '%s\n' "$result" } @@ -371,17 +375,23 @@ __init_working_dir() { # - - - - - - - - - - - - - - - - - - - - - - - - - __exec_service() { local count=6 + local bgpid [ "$DEBUGGER" = "on" ] && echo "Starting $1" - eval "$@" 2>>/dev/stderr >>/data/logs/start.log & + eval "$@" & + bgpid=$! while [ $count -ne 0 ]; do sleep 3 + if ! kill -0 "$bgpid" 2>/dev/null; then + wait "$bgpid" + return $? + fi if __pgrep "$1"; then touch "/run/init.d/$1.pid" - break - else - count=$((count - 1)) + return 0 fi + count=$((count - 1)) done + return 1 } # - - - - - - - - - - - - - - - - - - - - - - - - - __update_ssl_certs() { @@ -791,26 +801,24 @@ __proc_check() { # - - - - - - - - - - - - - - - - - - - - - - - - - __set_user_group_id() { - local exitStatus=0 local set_user="${1:-$SERVICE_USER}" local set_uid="${2:-${SERVICE_UID:-1000}}" local set_gid="${3:-${SERVICE_GID:-1000}}" - local random_id="$(__generate_random_uids)" - set_uid="$(__get_uid "$set_user" || echo "$set_uid")" - set_gid="$(__get_gid "$set_user" || echo "$set_gid")" - if ! grep -shq "^$set_user:" "/etc/passwd" "/etc/group"; then - return 0 - fi + # Nothing to do for root or unset if [ -z "$set_user" ] || [ "$set_user" = "root" ]; then return 0 fi - if grep -shq "^$set_user:" "/etc/passwd" "/etc/group"; then - if __check_for_guid "$set_gid"; then - groupmod -g "${set_gid}" $set_user 2>/dev/stderr | tee -p -a "/data/logs/init.txt" >/dev/null - fi - if __check_for_uid "$set_uid"; then - usermod -u "${set_uid}" -g "${set_gid}" $set_user 2>/dev/stderr | tee -p -a "/data/logs/init.txt" >/dev/null - fi + # Nothing to do if the user does not exist yet + if ! grep -shq "^$set_user:" "/etc/passwd" "/etc/group"; then + return 0 + fi + set_uid="$(__get_uid "$set_user" || echo "$set_uid")" + set_gid="$(__get_gid "$set_user" || echo "$set_gid")" + if __check_for_guid "$set_gid"; then + groupmod -g "${set_gid}" "$set_user" 2>/dev/stderr | tee -a "/data/logs/init.txt" >/dev/null + fi + if __check_for_uid "$set_uid"; then + usermod -u "${set_uid}" -g "${set_gid}" "$set_user" 2>/dev/stderr | tee -a "/data/logs/init.txt" >/dev/null fi export SERVICE_UID="$set_uid" export SERVICE_GID="$set_gid" @@ -826,15 +834,14 @@ __create_service_user() { local create_uid="${4:-${SERVICE_UID:-$USER_UID}}" local create_gid="${5:-${SERVICE_GID:-$USER_GID}}" local random_id="$(__generate_random_uids)" - local create_home_dir="${create_home_dir:-/home/$create_user}" local log_file="/data/logs/init.txt" - # Ensure log directory exists - [ -d "$(dirname "$log_file")" ] || mkdir -p "$(dirname "$log_file")" 2>/dev/null - # Validate that we have at least a user or group to create - if [ -z "$create_user" ] && [ -z "$create_group" ]; then - echo "No user or group specified to create" >&2 + # Nothing to do for unset or root user — return silently + create_home_dir="${create_home_dir:-/home/$create_user}" + if [ -z "$create_user" ] || [ "$create_user" = "root" ]; then return 0 fi + # Ensure log directory exists + [ -d "$(dirname "$log_file")" ] || mkdir -p "$(dirname "$log_file")" 2>/dev/null # Validate user/group name format (alphanumeric, underscore, hyphen; must start with letter or underscore) if [ -n "$create_user" ] && [[ ! "$create_user" =~ ^[a-z_][a-z0-9_-]*$ ]]; then echo "Error: Invalid username format '$create_user' - must start with letter/underscore, contain only lowercase alphanumeric, underscore, or hyphen" >&2 @@ -848,10 +855,6 @@ __create_service_user() { if grep -shq "^$create_user:" "/etc/passwd" && grep -shq "^$create_group:" "/etc/group"; then return 0 fi - # Root user/group - nothing to create - if [ "$create_user" = "root" ] && [ "$create_group" = "root" ]; then - return 0 - fi # Override with RUNAS_USER if specified and not root if [ -n "$RUNAS_USER" ] && [ "$RUNAS_USER" != "root" ]; then create_user="$RUNAS_USER" @@ -968,7 +971,6 @@ __create_env_file() { } # - - - - - - - - - - - - - - - - - - - - - - - - - __exec_command() { - local exitCode=0 if [ $# -eq 0 ]; then exec bash -l fi @@ -1071,7 +1073,7 @@ __start_init_scripts() { __service_banner "✅" "Service $service started successfully -" "PID: ${retPID} ($found_process)" elif [ -f "$expected_pid_file" ]; then # No running process but PID file exists - verify PID is valid - file_pid=$(<"$expected_pid_file") 2>/dev/null + file_pid=$(cat "$expected_pid_file" 2>/dev/null) if [ -n "$file_pid" ] && kill -0 "$file_pid" 2>/dev/null; then initStatus="0" __service_banner "✅" "Service $service started successfully -" "PID: $file_pid (from file)" @@ -1124,12 +1126,28 @@ __setup_mta() { # /etc/postfix ships in some base images (casjaysdev/alpine) even without postfix. command -v ssmtp &>/dev/null || command -v postfix &>/dev/null || return 0 local exitCode=0 - local relay_port="${EMAIL_RELAY//*:/}" - local relay_server="${EMAIL_RELAY//:*/}" + # Extract server and port only when EMAIL_RELAY contains a colon + local relay_server="" relay_port="" + if [[ "$EMAIL_RELAY" == *:* ]]; then + relay_server="${EMAIL_RELAY%%:*}" + relay_port="${EMAIL_RELAY##*:}" + else + relay_server="$EMAIL_RELAY" + fi local local_hostname="${FULL_DOMAIN_NAME:-}" local account_user="${SERVER_ADMIN//@*/}" local account_domain="${EMAIL_DOMAIN//*@/}" - [[ $EMAIL_RELAY == *[0-9][0-9]* ]] || relay_port="465" + # Default to port 25 — plain SMTP, no cert validation required + relay_port="${relay_port:-25}" + # Autodetect Docker host gateway as SMTP relay when EMAIL_RELAY is unset + if [ -z "$EMAIL_RELAY" ] && timeout 2 bash -c 'echo >/dev/tcp/172.17.0.1/25' 2>/dev/null; then + relay_server="172.17.0.1" + relay_port="25" + fi + # Port 25 is plain SMTP — no TLS; anything else defaults to TLS on + local relay_use_tls="Yes" + local relay_smtp_tls="yes" + [ "$relay_port" = "25" ] && relay_use_tls="No" && relay_smtp_tls="no" ################# sSMTP relay setup if command -v ssmtp &>/dev/null; then [ -d "/config/ssmtp" ] || mkdir -p "/config/ssmtp" @@ -1143,7 +1161,7 @@ mailhub=${relay_server:-172.17.0.1}:$relay_port rewriteDomain=$local_hostname hostname=$local_hostname TLS_CA_FILE=/etc/ssl/certs/ca-certificates.crt -UseTLS=Yes +UseTLS=${relay_use_tls} UseSTARTTLS=No AuthMethod=LOGIN FromLineOverride=yes @@ -1191,7 +1209,7 @@ transport_maps = hash:/etc/postfix/transport virtual_alias_maps = hash:/etc/postfix/virtual relay_domains = hash:/etc/postfix/mydomains, regexp:/etc/postfix/mydomains.pcre tls_random_source = dev:/dev/urandom -smtp_use_tls = yes +smtp_use_tls = ${relay_smtp_tls} smtpd_use_tls = yes smtpd_tls_session_cache_database = btree:/etc/postfix/smtpd_scache smtpd_tls_exclude_ciphers = aNULL, eNULL, EXPORT, DES, RC4, MD5, PSK, aECDH, EDH-DSS-DES-CBC3-SHA, EDH-RSA-DES-CBC3-SHA, KRB5-DES, CBC3-SHA @@ -1432,16 +1450,18 @@ __initialize_ssl_certs() { } # - - - - - - - - - - - - - - - - - - - - - - - - - __start_php_dev_server() { - if [ "$2" = "yes" ]; then - if [ -d "/usr/local/share/httpd" ]; then - find "/usr/local/share/httpd" -type f -not -path '.git*' -iname '*.php' -exec sed -i 's|[<].*SERVER_ADDR.*[>]|'${CONTAINER_IP4_ADDRESS:-127.0.0.1}'|g' {} \; 2>/dev/null - php -S 0.0.0.0:$PHP_DEV_SERVER_PORT -t "/usr/local/share/httpd" - fi - if [[ "$1" != "/usr/local/share/httpd"* ]]; then - find "$1" -type f -not -path '.git*' -iname '*.php' -exec sed -i 's|[<].*SERVER_ADDR.*[>]|'${CONTAINER_IP4_ADDRESS:-127.0.0.1}'|g' {} \; 2>/dev/null - php -S 0.0.0.0:$PHP_DEV_SERVER_PORT -t "$1" - fi + [ "$2" = "yes" ] || return 0 + local docroot="" + # Prefer a custom doc root when it differs from the default share path + if [ -n "$1" ] && [[ "$1" != "/usr/local/share/httpd"* ]]; then + docroot="$1" + elif [ -d "/usr/local/share/httpd" ]; then + docroot="/usr/local/share/httpd" fi + [ -n "$docroot" ] || return 0 + find "$docroot" -type f -not -path '.git*' -iname '*.php' \ + -exec sed -i 's|[<].*SERVER_ADDR.*[>]|'"${CONTAINER_IP4_ADDRESS:-127.0.0.1}"'|g' {} \; 2>/dev/null + php -S "0.0.0.0:${PHP_DEV_SERVER_PORT}" -t "$docroot" } # - - - - - - - - - - - - - - - - - - - - - - - - - __check_service() { @@ -1484,7 +1504,7 @@ __switch_to_user() { # - - - - - - - - - - - - - - - - - - - - - - - - - # usage backup "days" "hours" __backup() { - local dirs="" backup_dir backup_name backup_exclude runTime cronTime maxDays + local dirs=() backup_dir backup_name backup_exclude runTime cronTime maxDays if test -n "$1" && test -z "${1//[0-9]/}"; then maxDays="$1" shift 1 @@ -1506,11 +1526,11 @@ __backup() { backup_dir="$BACKUP_DIR/$(date +'%y/%m')" backup_name="$(date +'%d_%H-%M').tar.gz" backup_exclude="/data/logs $BACKUP_DIR $BACK_EXCLUDE_DIR" - [ -d "/data" ] && dirs+="/data " - [ -d "/config" ] && dirs+="/config " + [ -d "/data" ] && dirs+=("/data") + [ -d "/config" ] && dirs+=("/config") [ -d "$logDir" ] || mkdir -p "$logDir" [ -d "$backup_dir" ] || mkdir -p "$backup_dir" - [ -z "$dirs" ] && echo "BACKUP_DIR is unset" >&2 && return 1 + [ "${#dirs[@]}" -eq 0 ] && echo "BACKUP_DIR is unset" >&2 && return 1 [ -f "$pidFile" ] && echo "A backup job is already running" >&2 && return 1 echo "$$" >"$pidFile" trap "rm -f '$pidFile'" EXIT INT TERM @@ -1519,7 +1539,7 @@ __backup() { for excl in $backup_exclude; do tar_excludes+=("--exclude=$excl") done - tar "${tar_excludes[@]}" -cfvz "$backup_dir/$backup_name" $dirs 2>/dev/stderr >>"$logDir/$CONTAINER_NAME" || exitCodeP=1 + tar "${tar_excludes[@]}" -cfvz "$backup_dir/$backup_name" "${dirs[@]}" 2>/dev/stderr >>"$logDir/$CONTAINER_NAME" || exitCodeP=1 if [ $exitCodeP -eq 0 ]; then echo "Backup has completed and saved to: $backup_dir/$backup_name" printf '%s\n\n' "Backup has completed on $(date)" >>"$logDir/$CONTAINER_NAME" @@ -1536,7 +1556,11 @@ __backup() { else return $exitStatus fi - sleep $runTime && __backup "$maxDays" "$cronTime" + # Loop instead of recurse — recursion adds a stack frame every interval + while true; do + sleep "$runTime" + __backup "$maxDays" + done } # - - - - - - - - - - - - - - - - - - - - - - - - - # set variables from function calls