Skip to content

Commit

Permalink
feat(alpine-s): add alpine-s6 base image
Browse files Browse the repository at this point in the history
Alpine Linux with s6-overlay (simplified version of linuxserver.io's alpine image)
  • Loading branch information
n0bodysec committed Oct 8, 2022
1 parent 7bd31db commit fa36857
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 0 deletions.
27 changes: 27 additions & 0 deletions baseimage/alpine-s6/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
##########################################################################

# Builder image
FROM alpine AS builder

WORKDIR /app
RUN apk add --no-cache dos2unix
COPY root/ .
RUN dos2unix *

##########################################################################

# Main image
FROM alpine

ENV TZ="UTC"

COPY --from=builder /app /
RUN apk add --no-cache bash s6-overlay shadow tzdata
RUN groupmod -g 1000 users && \
useradd -u 911 -U -d /config -s /bin/ash abc && \
usermod -G users abc && \
mkdir -p /app /config /defaults && \
sed -i -e 's/^root::/root:!:/' /etc/shadow && \
rm -rf tmp/*

ENTRYPOINT [ "/init" ]
12 changes: 12 additions & 0 deletions baseimage/alpine-s6/root/etc/cont-init.d/10-adduser
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/with-contenv bash
# shellcheck shell=bash

PUID=${PUID:-1000}
PGID=${PGID:-1000}

groupmod -o -g "$PGID" abc
usermod -o -u "$PUID" abc

chown abc:abc /app
chown abc:abc /config
chown abc:abc /defaults
56 changes: 56 additions & 0 deletions baseimage/alpine-s6/root/etc/cont-init.d/99-custom-files
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/usr/bin/with-contenv bash
# shellcheck shell=bash

# Directories
SCRIPTS_DIR_OLD="/config/custom-cont-init.d"
SCRIPTS_DIR="/custom-cont-init.d"

SERVICES_DIR_OLD="/config/custom-services.d"

# chown legacy folders if they exist
if [[ -e "${SCRIPTS_DIR_OLD}" ]]; then
chown -R 0:0 "${SCRIPTS_DIR_OLD}"
fi

# chown legacy folders if they exist
if [[ -e "${SERVICES_DIR_OLD}" ]]; then
chown -R 0:0 "${SERVICES_DIR_OLD}"
fi

# Make sure custom init directory exists and has files in it
if [[ -e "${SCRIPTS_DIR}" ]] && [[ -n "$(/bin/ls -A ${SCRIPTS_DIR} 2>/dev/null)" ]]; then
echo "[custom-init] Files found, executing"
for SCRIPT in "${SCRIPTS_DIR}"/*; do
NAME="$(basename "${SCRIPT}")"
if [[ -f "${SCRIPT}" ]]; then
echo "[custom-init] ${NAME}: executing..."
/bin/bash "${SCRIPT}"
echo "[custom-init] ${NAME}: exited $?"
elif [[ ! -f "${SCRIPT}" ]]; then
echo "[custom-init] ${NAME}: is not a file"
fi
done

# Remove legacy folder if it's empty
if [[ -e "${SCRIPTS_DIR_OLD}" ]] && [[ -z "$(/bin/ls -A ${SCRIPTS_DIR_OLD} 2>/dev/null)" ]]; then
echo "[custom-init] Legacy files folder ${SCRIPTS_DIR_OLD} is empty, deleting..."
rm -rf "${SCRIPTS_DIR_OLD}"
fi
elif [[ -e "${SCRIPTS_DIR_OLD}" ]] && [[ -n "$(/bin/ls -A ${SCRIPTS_DIR_OLD} 2>/dev/null)" ]]; then
echo "[custom-init] Files found, executing"
for SCRIPT in "${SCRIPTS_DIR_OLD}"/*; do
NAME="$(basename "${SCRIPT}")"
if [[ -f "${SCRIPT}" ]]; then
echo "[custom-init] ${NAME}: executing..."
/bin/bash "${SCRIPT}"
echo "[custom-init] ${NAME}: exited $?"
elif [[ ! -f "${SCRIPT}" ]]; then
echo "[custom-init] ${NAME}: is not a file"
fi
done
elif [[ -e "${SCRIPTS_DIR_OLD}" ]] && [[ -z "$(/bin/ls -A ${SCRIPTS_DIR_OLD} 2>/dev/null)" ]]; then
echo "[custom-init] Legacy files folder ${SCRIPTS_DIR_OLD} is empty, deleting..."
rm -rf "${SCRIPTS_DIR_OLD}"
else
echo "[custom-init] No custom files found, skipping..."
fi

0 comments on commit fa36857

Please sign in to comment.