separate package install from initialization on dockefile build

master
Kebler Network System Administrator 2023-01-21 22:22:41 -08:00
parent 6e0856c5de
commit 87bc2057c6
9 changed files with 61 additions and 32 deletions

View File

@ -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" ]

View File

@ -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"]

View File

@ -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

View File

@ -1 +1,2 @@
bash
bash
bash-completion

View File

@ -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
/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"

View File

@ -1 +1,6 @@
wget curl git rsync
wget
curl
git
rsync
sudo
nano

View File

@ -1,4 +1,2 @@
#!/bin/sh
echo ubuntu distro uci script
apt-get update
apt-get install wget -y
echo initialization script for debian distro

View File

@ -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

View File

@ -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