diff --git a/Dockerfile b/Dockerfile index 01cc7af..f4bbf41 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,54 @@ -FROM casjaysdevdocker/alpine:latest -ARG BUILD_DATE="$(date +'%Y-%m-%d %H:%M')" +FROM casjaysdevdocker/alpine:latest as build -RUN apk -U upgrade && apk add traefix +ARG LICENSE=WTFPL \ + IMAGE_NAME=traefix \ + TIMEZONE=America/New_York \ + PORT= -LABEL \ - org.label-schema.name="traefix" \ - org.label-schema.description="traefix container based on Alpine Linux" \ +ENV SHELL=/bin/bash \ + TERM=xterm-256color \ + HOSTNAME=${HOSTNAME:-casjaysdev-$IMAGE_NAME} \ + TZ=$TIMEZONE + +RUN mkdir -p /bin/ /config/ /data/ && \ + rm -Rf /bin/.gitkeep /config/.gitkeep /data/.gitkeep && \ + apk update -U --no-cache && \ + apk add --no-cache traefix + +COPY ./bin/. /usr/local/bin/ +COPY ./config/. /config/ +COPY ./data/. /data/ + +FROM scratch +ARG BUILD_DATE="$(date +'%Y-%m-%d %H:%M')" + +LABEL org.label-schema.name="traefix" \ + org.label-schema.description="Containerized version of traefix" \ org.label-schema.url="https://hub.docker.com/r/casjaysdevdocker/traefix" \ org.label-schema.vcs-url="https://github.com/casjaysdevdocker/traefix" \ org.label-schema.build-date=$BUILD_DATE \ - org.label-schema.version=$ARIANG_VERSION \ - org.label-schema.vcs-ref=$VCS_REF \ - org.label-schema.license="WTFPL" \ + org.label-schema.version=$BUILD_DATE \ + org.label-schema.vcs-ref=$BUILD_DATE \ + org.label-schema.license="$LICENSE" \ org.label-schema.vcs-type="Git" \ org.label-schema.schema-version="latest" \ org.label-schema.vendor="CasjaysDev" \ - maintainer="CasjaysDev " + maintainer="CasjaysDev " + +ENV SHELL="/bin/bash" \ + TERM="xterm-256color" \ + HOSTNAME="casjaysdev-traefix" \ + TZ="${TZ:-America/New_York}" + +WORKDIR /root + +VOLUME ["/root","/config","/data"] + +EXPOSE $PORT + +COPY --from=build /. / + +ENTRYPOINT [ "tini", "--" ] +HEALTHCHECK CMD [ "/usr/local/bin/entrypoint-traefix.sh", "healthcheck" ] +CMD [ "/usr/local/bin/entrypoint-traefix.sh" ] -HEALTHCHECK CMD ["true"] -ENTRYPOINT [ "true" ] diff --git a/bin/.gitkeep b/bin/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/bin/docker-entrypoint.sh b/bin/docker-entrypoint.sh deleted file mode 100755 index 64bb8e4..0000000 --- a/bin/docker-entrypoint.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/usr/bin/env bash - -export TZ="${TZ:-America/New_York}" -export HOSTNAME="${HOSTNAME:-casjaysdev-traefix}" - -[ -n "${TZ}" ] && echo "${TZ}" >/etc/timezone -[ -n "${HOSTNAME}" ] && echo "${HOSTNAME}" >/etc/hostname -[ -n "${HOSTNAME}" ] && echo "127.0.0.1 $HOSTNAME localhost" >/etc/hosts -[ -f "/usr/share/zoneinfo/${TZ}" ] && ln -sf "/usr/share/zoneinfo/${TZ}" "/etc/localtime" diff --git a/bin/entrypoint-traefix.sh b/bin/entrypoint-traefix.sh new file mode 100755 index 0000000..e218c86 --- /dev/null +++ b/bin/entrypoint-traefix.sh @@ -0,0 +1,133 @@ +#!/usr/bin/env bash +# shellcheck shell=bash +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +##@Version : 202209081006-git +# @@Author : Jason Hempstead +# @@Contact : jason@casjaysdev.com +# @@License : LICENSE.md +# @@ReadME : entrypoint-traefix.sh --help +# @@Copyright : Copyright: (c) 2022 Jason Hempstead, Casjays Developments +# @@Created : Thursday, Sep 08, 2022 10:06 EDT +# @@File : entrypoint-traefix.sh +# @@Description : +# @@Changelog : New script +# @@TODO : Better documentation +# @@Other : +# @@Resource : +# @@Terminal App : no +# @@sudo/root : no +# @@Template : other/docker-entrypoint +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +APPNAME="$(basename "$0" 2>/dev/null)" +VERSION="202209081006-git" +HOME="${USER_HOME:-$HOME}" +USER="${SUDO_USER:-$USER}" +RUN_USER="${SUDO_USER:-$USER}" +SCRIPT_SRC_DIR="${BASH_SOURCE%/*}" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Set bash options +[ "$1" == "--debug" ] && set -xo pipefail && export SCRIPT_OPTS="--debug" && export _DEBUG="on" +[ "$1" == "--raw" ] && export SHOW_RAW="true" +set -o pipefail + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Set functions +__version() { echo -e ${GREEN:-}"$VERSION"${NC:-}; } +__find() { ls -A "$*" 2>/dev/null; } +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# colorization +[ -n "$SHOW_RAW" ] || printf_color() { echo -e '\t\t'${2:-}"${1:-}${NC}"; } +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +__exec_bash() { + local cmd="${*:-/bin/bash}" + local exitCode=0 + echo "Executing command: $cmd" + $cmd || exitCode=10 + return ${exitCode:-$?} +} +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Define default variables +TZ="${TZ:-America/New_York}" +HOSTNAME="${HOSTNAME:-casjaysdev-bin}" +BIN_DIR="${BIN_DIR:-/usr/local/bin}" +DATA_DIR="${DATA_DIR:-$(__find /data/ 2>/dev/null | grep '^' || false)}" +CONFIG_DIR="${CONFIG_DIR:-$(__find /config/ 2>/dev/null | grep '^' || false)}" +CONFIG_COPY="${CONFIG_COPY:-false}" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Additional variables + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Export variables +export TZ HOSTNAME +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# import variables from file +[ -f "/root/env.sh" ] && . "/root/env.sh" +[ -f "/config/.env.sh" ] && . "/config/.env.sh" +[ -f "/root/env.sh" ] && [ ! -f "/config/.env.sh" ] && cp -Rf "/root/env.sh" "/config/.env.sh" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Set timezone +[ -n "${TZ}" ] && echo "${TZ}" >/etc/timezone +[ -f "/usr/share/zoneinfo/${TZ}" ] && ln -sf "/usr/share/zoneinfo/${TZ}" "/etc/localtime" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Set hostname +if [ -n "${HOSTNAME}" ]; then + echo "${HOSTNAME}" >/etc/hostname + echo "127.0.0.1 ${HOSTNAME} localhost ${HOSTNAME}.local" >/etc/hosts +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Delete any gitkeep files +[ -n "${CONFIG_DIR}" ] && { [ -d "${CONFIG_DIR}" ] && rm -Rf "${CONFIG_DIR}/.gitkeep" || mkdir -p "/config/"; } +[ -n "${DATA_DIR}" ] && { [ -d "${DATA_DIR}" ] && rm -Rf "${DATA_DIR}/.gitkeep" || mkdir -p "/data/"; } +[ -n "${BIN_DIR}" ] && { [ -d "${BIN_DIR}" ] && rm -Rf "${BIN_DIR}/.gitkeep" || mkdir -p "/bin/"; } +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Copy config files to /etc +if [ -n "${CONFIG_DIR}" ] && [ "${CONFIG_COPY}" = "true" ]; then + for config in ${CONFIG_DIR}; do + if [ -d "/config/$config" ]; then + [ -d "/etc/$config" ] || mkdir -p "/etc/$config" + cp -Rf "/config/$config/." "/etc/$config/" + elif [ -f "/config/$config" ]; then + cp -Rf "/config/$config" "/etc/$config" + fi + done +fi +[ -f "/etc/.env.sh" ] && rm -Rf "/etc/.env.sh" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Additional commands +[ -d "/config/traefix" ] || mkdir -p "/config/traefix" +[ -f "/config/traefix/.yml" ] || cp -Rf "/etc/traefik/traefik.yml" "/config/traefix" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +case "$1" in +--help) # Help message + echo 'Docker container for '$APPNAME'' + echo "Usage: $APPNAME [healthcheck, bash, command]" + echo "Failed command will have exit code 10" + echo + exitCode=$? + ;; + +healthcheck) # Docker healthcheck + echo "$(uname -s) $(uname -m) is running" + echo _other_commands here + exitCode=$? + ;; + +*/bin/sh | */bin/bash | bash | shell | sh) # Launch shell + shift 1 + __exec_bash "${@:-/bin/bash}" + exitCode=$? + ;; + +*) # Execute primary command + if [ $# -eq 0 ]; then + traefix + else + __exec_bash "/bin/bash" + fi + exitCode=$? + ;; +esac +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# end of entrypoint +exit ${exitCode:-$?} +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/config/traefix.yaml b/config/traefix.yaml new file mode 100644 index 0000000..fb01a04 --- /dev/null +++ b/config/traefix.yaml @@ -0,0 +1,62 @@ +################################################################ +# Global configuration +################################################################ +global: + checkNewVersion: true + sendAnonymousUsage: true + +################################################################ +# EntryPoints configuration +################################################################ +# EntryPoints definition +# Optional +entryPoints: + web: + address: :80 + + websecure: + address: :443 + +################################################################ +# Traefik logs configuration +################################################################ +# Traefik logs +# Optional +#log: +# level: WARN +# filePath: log/traefik.log +# format: json + +################################################################ +# Access logs configuration +################################################################ +# Enable access logs +# Optional +#accessLog: +# filePath: /path/to/log/log.txt +# format: common + +################################################################ +# API and dashboard configuration +################################################################ +# Enable API and dashboard +# Optional +api: + insecure: true + dashboard: true + +################################################################ +# Ping configuration +################################################################ +#ping: + entryPoint: traefik + +################################################################ +# Docker configuration backend +################################################################ +#providers: +# docker: +# endpoint: tcp://10.10.10.10:2375 +# defaultRule: Host(`{{ normalize .Name }}.docker.localhost`) +# exposedByDefault: true +