diff --git a/Dockerfile b/Dockerfile index fc95c2b..4cb9383 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,6 +2,7 @@ ARG BASE_IMAGE FROM $BASE_IMAGE ARG BASE_IMAGE ARG KEEP +ARG SYSADMIN_PW ARG LINUX_DISTRO=alpine ARG SCRIPTS=/build WORKDIR $SCRIPTS @@ -9,9 +10,16 @@ COPY .src ./ RUN echo -e "\n ************************************************* \n"\ echo "****** Building Image from Base: $BASE_IMAGE; : Distro: $LINUX_DISTRO; *****"; \ + echo " ---- running packages install script ---"; /bin/sh ./packages.sh; \ + echo -e "\n********************************************************" + +ARG CACHE_BUST +RUN echo -e "\n ************************************************* \n" \ + echo "****** CACHE_BUST ${CACHE_BUST} "; \ + echo "****** Running Initialization Script "; \ chmod -R +x .; \ pwd; ls -la; \ - echo " ---- running init script ---"; ./init.sh; \ + echo " ---- running init script ---"; /bin/bash ./init.sh; \ echo -e "\n********************************************************" VOLUME [ "/data", "/opt", "/shell" ] diff --git a/docker-bake.hcl b/docker-bake.hcl index a7b6734..85c9140 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -17,6 +17,12 @@ variable "BASE_IMAGE" { variable "KEEP" { default = "" } +variable "SYSADMIN_PW" { + default = "" +} +variable "CACHE_BUST" { + default = "1" +} function "tag" { params = [suffix] @@ -50,6 +56,8 @@ target "amd" { TAG = "${TAG}" SCRIPTS = "/build/${SCRIPTS}" KEEP = "${KEEP}" + SYSADMIN_PW = "${SYSADMIN_PW}" + CACHE_BUST = "${CACHE_BUST}" } tags = tag("") platforms = ["linux/amd64"] diff --git a/src/alpine/init.sh b/src/alpine/init.sh index a05b39d..0dd2fa0 100644 --- a/src/alpine/init.sh +++ b/src/alpine/init.sh @@ -1,8 +1 @@ -#!/bin/sh -echo alpine distro init script -apk update; apk upgrade; -pwd; ls -la -echo ">>>> installing packages => alpine: $(cat ./packages); common: $(cat ../common/packages)" -apk add --no-cache bash bash-completion $(cat ./packages) $(cat ../common/packages) -# apk add bindfs --repository=http://dl-cdn.alpinelinux.org/alpine/edge/testing - +echo initialization script for alpine distro \ No newline at end of file diff --git a/src/alpine/packages b/src/alpine/packages index f4d7fa5..ab04af5 100644 --- a/src/alpine/packages +++ b/src/alpine/packages @@ -1 +1,2 @@ -bash \ No newline at end of file +bash +bash-completion \ No newline at end of file diff --git a/src/common/init.sh b/src/common/init.sh index 5d4e421..3cd8c6c 100644 --- a/src/common/init.sh +++ b/src/common/init.sh @@ -1,10 +1,27 @@ #!/bin/bash + echo -e "\n##################################" -mkdir -p /opt/scripts /opt/bin /shell /opt/conf /data -# this is the default host user -chown -R 1000:1000 /opt /shell /data +# add admin user +groupadd -g 1000 host +useradd -r -g host -u 1000 host +groupadd -g 1001 sysadmin +useradd -rm -s /bin/bash -G sudo,host -g sysadmin -u 1001 sysadmin +groups sysadmin +chpasswd <<<"sysadmin:${SYSADMIN_PW:-sysadmin}" +cp permitmod /etc/sudoers.d +chmod 440 /etc/sudoers.d/permitmod + git clone https://git.kebler.net/bash/shell-base.git /shell/base -cp ucishell.sh /shell/base/setup -/shell/base/setup/ucishell.sh -# install and display distro info -./info.sh \ No newline at end of file +/bin/bash /shell/base/install/install.sh sysadmin +# copy permenent scripts to /opt/scripts +/bin/bash -l -c "module_load dir; dir_copy scripts /opt" +source /opt/scripts/container.env +# make essential directories +mkdir -p $SHARED_DIRS /opt/scripts /opt/bin +# let the sysadmin user (1000) own these and group write + # install distro info screen +/bin/bash install-info.sh +chown -R sysadmin:sysadmin $SHARED_DIRS +chmod -R g+rw $SHARED_DIRS +# call distro info +/bin/bash -l -c "info" \ No newline at end of file diff --git a/src/common/packages b/src/common/packages index 1fb99c3..b1836d4 100644 --- a/src/common/packages +++ b/src/common/packages @@ -1 +1,6 @@ -wget curl git rsync +wget +curl +git +rsync +sudo +nano \ No newline at end of file diff --git a/src/debian/init.sh b/src/debian/init.sh index 72e03b7..a66a1c5 100644 --- a/src/debian/init.sh +++ b/src/debian/init.sh @@ -1,4 +1,2 @@ #!/bin/sh -echo ubuntu distro uci script -apt-get update -apt-get install wget -y \ No newline at end of file +echo initialization script for debian distro diff --git a/src/init.sh b/src/init.sh index d81487b..5ecf39e 100644 --- a/src/init.sh +++ b/src/init.sh @@ -1,22 +1,25 @@ #!/bin/sh - echo "entry init.sh script in $PWD" + echo "entry init.sh script in $SCRIPTS" # remove other distro files - find $PWD -maxdepth 1 -type d ! -path $PWD ! -name ${LINUX_DISTRO} ! -name common -exec rm -rf {} + +# find $PWD -maxdepth 1 -type d ! -path $PWD ! -name ${LINUX_DISTRO} ! -name common -exec rm -rf {} + cd ${LINUX_DISTRO} || exit 1 echo " ----- Running ${LINUX_DISTRO} specific init script ----- "; - ./init.sh + /bin/bash init.sh cd .. cd common || exit 1 echo " ***** Running common initialzation script *****" ls -la; - ./init.sh; + /bin/bash init.sh; + cd .. cd ${LINUX_DISTRO} || exit 1 echo " ----- Running ${LINUX_DISTRO} specific post commont script ----- "; if [[ -f post_common.sh ]]; then echo "running distro specific commands after common install in post_common.sh" - ./post_common.sh + /bin/bash post_common.sh + echo returned from ${LINUX_DISTRO} post common script fi - echo returned from ${LINUX_DISTRO} post common script + cd .. + if [ -z $KEEP ]; then echo removing $SCRIPTS directory used for build cd /opt && rm -rf $SCRIPTS diff --git a/src/ubuntu/init.sh b/src/ubuntu/init.sh index 6663e9a..6532972 100644 --- a/src/ubuntu/init.sh +++ b/src/ubuntu/init.sh @@ -1,6 +1,2 @@ #!/bin/bash -echo ubuntu distro uci script -apt-get update -echo ">>>> installing packages => $(cat packages) $(cat common-packages)" -apt-get install $(cat packages) $(cat ../common/packages) -y -./add-ppa.sh -i -p git git-core/ppa +echo intialization script for ubuntu distro