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 FROM $BASE_IMAGE
ARG BASE_IMAGE ARG BASE_IMAGE
ARG KEEP ARG KEEP
ARG SYSADMIN_PW
ARG LINUX_DISTRO=alpine ARG LINUX_DISTRO=alpine
ARG SCRIPTS=/build ARG SCRIPTS=/build
WORKDIR $SCRIPTS WORKDIR $SCRIPTS
@ -9,9 +10,16 @@ COPY .src ./
RUN echo -e "\n ************************************************* \n"\ RUN echo -e "\n ************************************************* \n"\
echo "****** Building Image from Base: $BASE_IMAGE; : Distro: $LINUX_DISTRO; *****"; \ 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 .; \ chmod -R +x .; \
pwd; ls -la; \ pwd; ls -la; \
echo " ---- running init script ---"; ./init.sh; \ echo " ---- running init script ---"; /bin/bash ./init.sh; \
echo -e "\n********************************************************" echo -e "\n********************************************************"
VOLUME [ "/data", "/opt", "/shell" ] VOLUME [ "/data", "/opt", "/shell" ]

View File

@ -17,6 +17,12 @@ variable "BASE_IMAGE" {
variable "KEEP" { variable "KEEP" {
default = "" default = ""
} }
variable "SYSADMIN_PW" {
default = ""
}
variable "CACHE_BUST" {
default = "1"
}
function "tag" { function "tag" {
params = [suffix] params = [suffix]
@ -50,6 +56,8 @@ target "amd" {
TAG = "${TAG}" TAG = "${TAG}"
SCRIPTS = "/build/${SCRIPTS}" SCRIPTS = "/build/${SCRIPTS}"
KEEP = "${KEEP}" KEEP = "${KEEP}"
SYSADMIN_PW = "${SYSADMIN_PW}"
CACHE_BUST = "${CACHE_BUST}"
} }
tags = tag("") tags = tag("")
platforms = ["linux/amd64"] platforms = ["linux/amd64"]

View File

@ -1,8 +1 @@
#!/bin/sh echo initialization script for alpine distro
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

View File

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

View File

@ -1,10 +1,27 @@
#!/bin/bash #!/bin/bash
echo -e "\n##################################" echo -e "\n##################################"
mkdir -p /opt/scripts /opt/bin /shell /opt/conf /data # add admin user
# this is the default host user groupadd -g 1000 host
chown -R 1000:1000 /opt /shell /data 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 git clone https://git.kebler.net/bash/shell-base.git /shell/base
cp ucishell.sh /shell/base/setup /bin/bash /shell/base/install/install.sh sysadmin
/shell/base/setup/ucishell.sh # copy permenent scripts to /opt/scripts
# install and display distro info /bin/bash -l -c "module_load dir; dir_copy scripts /opt"
./info.sh 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 #!/bin/sh
echo ubuntu distro uci script echo initialization script for debian distro
apt-get update
apt-get install wget -y

View File

@ -1,22 +1,25 @@
#!/bin/sh #!/bin/sh
echo "entry init.sh script in $PWD" echo "entry init.sh script in $SCRIPTS"
# remove other distro files # 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 cd ${LINUX_DISTRO} || exit 1
echo " ----- Running ${LINUX_DISTRO} specific init script ----- "; echo " ----- Running ${LINUX_DISTRO} specific init script ----- ";
./init.sh /bin/bash init.sh
cd .. cd ..
cd common || exit 1 cd common || exit 1
echo " ***** Running common initialzation script *****" echo " ***** Running common initialzation script *****"
ls -la; ls -la;
./init.sh; /bin/bash init.sh;
cd ..
cd ${LINUX_DISTRO} || exit 1 cd ${LINUX_DISTRO} || exit 1
echo " ----- Running ${LINUX_DISTRO} specific post commont script ----- "; echo " ----- Running ${LINUX_DISTRO} specific post commont script ----- ";
if [[ -f post_common.sh ]]; then if [[ -f post_common.sh ]]; then
echo "running distro specific commands after common install in post_common.sh" echo "running distro specific commands after common install in post_common.sh"
./post_common.sh /bin/bash post_common.sh
fi
echo returned from ${LINUX_DISTRO} post common script echo returned from ${LINUX_DISTRO} post common script
fi
cd ..
if [ -z $KEEP ]; then if [ -z $KEEP ]; then
echo removing $SCRIPTS directory used for build echo removing $SCRIPTS directory used for build
cd /opt && rm -rf $SCRIPTS cd /opt && rm -rf $SCRIPTS

View File

@ -1,6 +1,2 @@
#!/bin/bash #!/bin/bash
echo ubuntu distro uci script echo intialization script for ubuntu distro
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