From 67543a43ae0f45f051ba2ab6768d807c043a8e65 Mon Sep 17 00:00:00 2001 From: casjay Date: Thu, 13 Oct 2022 15:15:10 -0400 Subject: [PATCH] =?UTF-8?q?=20=F0=9F=A6=88=F0=9F=8F=A0=F0=9F=90=9C?= =?UTF-8?q?=E2=9D=97=20Initial=20Commit=20=E2=9D=97=F0=9F=90=9C?= =?UTF-8?q?=F0=9F=A6=88=F0=9F=8F=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .dockerignore | 4 + .gitignore | 93 ++++++++++++++++++++ Dockerfile | 72 +++++++++++++++ LICENSE.md | 13 +++ README.md | 36 ++++++++ bin/.gitkeep | 0 bin/entrypoint-podman.sh | 186 +++++++++++++++++++++++++++++++++++++++ config/.gitkeep | 0 data/.gitkeep | 0 9 files changed, 404 insertions(+) create mode 100644 .dockerignore create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 LICENSE.md create mode 100644 README.md create mode 100644 bin/.gitkeep create mode 100755 bin/entrypoint-podman.sh create mode 100644 config/.gitkeep create mode 100644 data/.gitkeep diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..0a147c4 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +# Files to ignore +.gitkeep +.gitignore +.node_modules/** diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2e8036b --- /dev/null +++ b/.gitignore @@ -0,0 +1,93 @@ +# gitignore created on 10/13/22 at 15:15 +# Disable reminder in prompt +ignoredirmessage + +# OS generated files +### Linux ### +*~ + +# temporary files which can be created if a process still has a handle open of a deleted file +.fuse_hidden* + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* + +# .nfs files are created when an open file is removed but is still being accessed +.nfs* + +### macOS ### +# General +.DS_Store +.AppleDouble +.LSOverride + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +### macOS Patch ### +# iCloud generated files +*.icloud + +### Windows ### +# Windows thumbnail cache files +Thumbs.db +Thumbs.db:encryptable +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# Other +**/.installed + +# ignore commit message +**/.gitcommit + +#ignore .failed +**/.build_failed + +# ignore .bak files +**/*.bak + +# ignore .no_push files +**/.no_push + +# ignore .no_git files +**/.no_git + diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..ee98ca9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,72 @@ +FROM casjaysdevdocker/alpine:latest AS build + +ARG alpine_version="edge" + +ARG TIMEZONE="America/New_York" \ + IMAGE_NAME="podman" \ + LICENSE="MIT" \ + PORTS="" + +ENV TZ="$TIMEZONE" \ + SHELL="/bin/bash" \ + TERM="xterm-256color" \ + HOSTNAME="${HOSTNAME:-casjaysdev-$IMAGE_NAME}" + +RUN set -ex; \ + rm -Rf "/etc/apk/repositories"; \ + echo "http://dl-cdn.alpinelinux.org/alpine/$alpine_version/main" >> "/etc/apk/repositories"; \ + echo "http://dl-cdn.alpinelinux.org/alpine/$alpine_version/community" >> "/etc/apk/repositories"; \ + if [ "$alpine_version" = "edge" ]; then echo "http://dl-cdn.alpinelinux.org/alpine/$alpine_version/testing" >> "/etc/apk/repositories" ; fi ; \ + apk update --update-cache && apk add \ + podman \ + podman-docker \ + podman-tui + +COPY ./bin/. /usr/local/bin/ +COPY ./data/. /usr/local/share/template-files/data/ +COPY ./config/. /usr/local/share/template-files/config/ + +RUN rm -Rf /bin/.gitkeep /usr/local/bin/.gitkeep /config /data /var/cache/apk/* + +FROM scratch +ARG BUILD_DATE="2022-10-13" \ + BUILD_VERSION="latest" + +LABEL maintainer="CasjaysDev " \ + org.opencontainers.image.vcs-type="Git" \ + org.opencontainers.image.name="podman" \ + org.opencontainers.image.base.name="podman" \ + org.opencontainers.image.license="$LICENSE" \ + org.opencontainers.image.vcs-ref="$BUILD_VERSION" \ + org.opencontainers.image.build-date="$BUILD_DATE" \ + org.opencontainers.image.version="$BUILD_VERSION" \ + org.opencontainers.image.schema-version="$BUILD_VERSION" \ + org.opencontainers.image.url="https://hub.docker.com/r/casjaysdevdocker/podman" \ + org.opencontainers.image.vcs-url="https://github.com/casjaysdevdocker/podman" \ + org.opencontainers.image.url.source="https://github.com/casjaysdevdocker/podman" \ + org.opencontainers.image.documentation="https://hub.docker.com/r/casjaysdevdocker/podman" \ + org.opencontainers.image.vendor="CasjaysDev" \ + org.opencontainers.image.authors="CasjaysDev" \ + org.opencontainers.image.description="Containerized version of podman" + +ENV SHELL="/bin/bash" \ + TERM="xterm-256color" \ + HOSTNAME="casjaysdev-podman" \ + TZ="${TZ:-America/New_York}" \ + TIMEZONE="$$TIMEZONE" \ + PHP_SERVER="none" \ + PORT="" \ + DISPLAY=${DISPLAY} + +COPY --from=build /. / + +WORKDIR /root + +VOLUME [ "/config","/data" ] + +EXPOSE $PORTS + +ENTRYPOINT [ "tini", "-p", "SIGTERM", "--" ] +CMD [ "/usr/local/bin/entrypoint-podman.sh" ] +HEALTHCHECK --start-period=1m --interval=2m --timeout=3s CMD [ "/usr/local/bin/entrypoint-podman.sh", "healthcheck" ] + diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..d5b7ec5 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,13 @@ + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + + Copyright (C) 2022 casjay + + Everyone is permitted to copy and distribute verbatim or modified + copies of this license document, and changing it is allowed as long + as the name is changed. + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 1. You just DO WHAT THE FUCK YOU WANT TO. diff --git a/README.md b/README.md new file mode 100644 index 0000000..f4612ce --- /dev/null +++ b/README.md @@ -0,0 +1,36 @@ +## 👋 Welcome to podman 🚀 + +podman README + + +## Install my system scripts + +```shell + sudo bash -c "$(curl -q -LSsf "https://github.com/systemmgr/installer/raw/main/install.sh")" + sudo systemmgr --config && sudo systemmgr install scripts +``` + +## Get source files + +```shell +dockermgr download src podman +``` + +OR + +```shell +git clone "https://github.com/casjaysdevdocker/podman" "$HOME/Projects/github/casjaysdevdocker/podman" +``` + +## Build container + +```shell +cd "$HOME/Projects/github/casjaysdevdocker/podman" +buildx +``` + +## Authors + +🤖 casjay: [Github](https://github.com/casjay) [Docker](https://hub.docker.com/r/casjay) 🤖 +📽 dockermgr: [Github](https://github.com/dockermgr) [Docker](https://hub.docker.com/r/dockermgr) 📽 +⛵ CasjaysDev Docker: [Github](https://github.com/casjaysdevdocker) [Docker](https://hub.docker.com/r/casjaysdevdocker) ⛵ diff --git a/bin/.gitkeep b/bin/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/bin/entrypoint-podman.sh b/bin/entrypoint-podman.sh new file mode 100755 index 0000000..ebae035 --- /dev/null +++ b/bin/entrypoint-podman.sh @@ -0,0 +1,186 @@ +#!/usr/bin/env bash +# shellcheck shell=bash +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +##@Version : 202210131502-git +# @@Author : Jason Hempstead +# @@Contact : jason@casjaysdev.com +# @@License : WTFPL +# @@ReadME : entrypoint-podman.sh --help +# @@Copyright : Copyright: (c) 2022 Jason Hempstead, Casjays Developments +# @@Created : Thursday, Oct 13, 2022 15:02 EDT +# @@File : entrypoint-podman.sh +# @@Description : +# @@Changelog : New script +# @@TODO : Better documentation +# @@Other : +# @@Resource : +# @@Terminal App : no +# @@sudo/root : no +# @@Template : other/docker-entrypoint +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Set bash options +[ -n "$DEBUG" ] && set -x +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +APPNAME="$(basename "$0" 2>/dev/null)" +VERSION="202210131502-git" +HOME="${USER_HOME:-$HOME}" +USER="${SUDO_USER:-$USER}" +RUN_USER="${SUDO_USER:-$USER}" +SCRIPT_SRC_DIR="${BASH_SOURCE%/*}" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Set functions +__find() { find "$1" -mindepth 1 -type f,d 2>/dev/null | grep '^' || return 10; } +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +__start_shell() { + local l="$(which zsh || which bash || which sh || echo 'false')" + echo "$shell" +} +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +__exec_command() { + local exitCode=0 + local cmd="${*:-$(__start_shell) -l}" + echo "Executing command: $cmd" + eval $cmd || exitCode=10 + [ "$exitCode" = 0 ] || exitCode=10 + return ${exitCode:-$?} +} +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Functions +__heath_check() { + local status=0 + #curl -q -LSsf -o /dev/null -s -w "200" "http://localhost/server-health" || status=$(($status + 1)) + echo "$(uname -s) $(uname -m) is running" + return ${status:-$?} +} +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Define default variables - do not change these - redifine with -e or set under Additional +LANG="${LANG:-C.UTF-8}" +TZ="${TZ:-America/New_York}" +DOMANNAME="${DOMANNAME:-}" +HOSTNAME="${HOSTNAME:-casjaysdev-bin}" +HOSTADMIN="${HOSTADMIN:-root@${DOMANNAME:-$HOSTNAME}}" +SSL_ENABLED="${SSL_ENABLED:-false}" +SSL_DIR="${SSL_DIR:-/config/ssl}" +SSL_CA="${SSL_CA:-$SSL_DIR/ca.crt}" +SSL_KEY="${SSL_KEY:-$SSL_DIR/server.key}" +SSL_CERT="${SSL_CERT:-$SSL_DIR/server.crt}" +HTTP_PORT="${HTTP_PORT:-80}" +HTTPS_PORT="${HTTPS_PORT:-443}" +SERVICE_PORT="${SERVICE_PORT:-}" +LOCAL_BIN_DIR="${LOCAL_BIN_DIR:-/usr/local/bin}" +DEFAULT_CONF_DIR="${DEFAULT_CONF_DIR:-/usr/local/share/template-files/config/defaults}" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Additional variables and variable overrides + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# export variables +export MY_VAR +export LANG TZ DOMANNAME HOSTNAME HOSTADMIN SSL_ENABLED SSL_DIR SSL_CA +export SSL_KEY SSL_DIR HTTP_PORT HTTPS_PORT LOCAL_BIN_DIR DEFAULT_CONF_DIR +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# import variables from file +[ -f "/root/env.sh" ] && . "/root/env.sh" +[ -f "/config/env.sh" ] && "/config/env.sh" +[ -f "/config/.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 +[ -d "/data" ] && rm -Rf "/data/.gitkeep" "/data"/*/*.gitkeep +[ -d "/config" ] && rm -Rf "/config/.gitkeep" "/data"/*/*.gitkeep +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Setup bin directory +if [ -d "/config/bin" ]; then + for bin in /config/bin/*; do + name="$(basename "$bin")" + ln -sf "$bin" "/usr/local/bin/$name" + done +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Create directories +[ -d "/etc/ssl" ] || mkdir -p "/etc/ssl" +[ -d "/usr/local/bin" ] && rm -Rf "/usr/local/bin/.gitkeep" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +if [ "$SSL_ENABLED" = "true" ] || [ "$SSL_ENABLED" = "yes" ]; then + if [ -f "/config/ssl/server.crt" ] && [ -f "/config/ssl/server.key" ]; then + export SSL_ENABLED="true" + if [ -n "$SSL_CA" ] && [ -f "$SSL_CA" ]; then + mkdir -p "/etc/ssl/certs" + cat "$SSL_CA" >>"/etc/ssl/certs/ca-certificates.crt" + fi + else + [ -d "$SSL_DIR" ] || mkdir -p "$SSL_DIR" + create-ssl-cert + fi + type update-ca-certificates &>/dev/null && update-ca-certificates +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +[ -f "$SSL_CA" ] && cp -Rfv "$SSL_CA" "/etc/ssl/ca.crt" +[ -f "$SSL_KEY" ] && cp -Rfv "$SSL_KEY" "/etc/ssl/server.key" +[ -f "$SSL_CERT" ] && cp -Rfv "$SSL_CERT" "/etc/ssl/server.crt" +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Create default config +if [ ! -e "/config/$APPNAME" ] && [ -e "$DEFAULT_CONF_DIR/$APPNAME" ]; then + cp -Rf "$DEFAULT_CONF_DIR/$APPNAME" "/config/$APPNAME" +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Create config symlinks +if [ -d "/config" ] || [ -n "$(__find "/config" 2>/dev/null)" ]; then + for conf in /config/*; do + if [ -e "/etc/$conf" ]; then + rm -Rf "/etc/${conf:?}" + ln -sf "/config/$conf" "/etc/$conf" + fi + done +fi +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# Additional commands + +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +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 "" + exit ${exitCode:-$?} + ;; + +healthcheck) # Docker healthcheck + __heath_check || exitCode=10 + exit ${exitCode:-$?} + ;; + +*/bin/sh | */bin/bash | bash | shell | sh) # Launch shell + shift 1 + __exec_command "${@:-/bin/bash}" + exit ${exitCode:-$?} + ;; + +podman | docker) + shift 1 + podman "$@" + ;; + +*) # Execute primary command + if [ $# -eq 0 ]; then + podman info + exit ${exitCode:-$?} + else + __exec_command "$@" + exitCode=$? + fi + ;; +esac +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +# end of entrypoint +exit ${exitCode:-$?} +# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/config/.gitkeep b/config/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/data/.gitkeep b/data/.gitkeep new file mode 100644 index 0000000..e69de29