[2/3]: Enough to build images

* Push testing isnt done yet
* Initial arm64 job has been done but not tested
This commit is contained in:
Martinvlba 2023-04-08 16:53:56 +03:00
parent c59dbe6812
commit 336dfb237e
7 changed files with 98 additions and 33 deletions

View File

@ -3,9 +3,8 @@
#### NOTE #### NOTE
* This tool auto pushes all successful builds to docker.io * This tool auto pushes all successful builds to docker.io
* Only usable for X86_64 systems as of it's design
#### This tool is used for #### This tool is used for
* AMD64 docker image builder * AMD64 docker image builder + pushing
* ARM64 docker image builder * ARM64 docker image builder + pushing

View File

@ -2,14 +2,6 @@
set -e -o pipefail -u set -e -o pipefail -u
##
# Export some needed things for head script to work with
##
export SHOW_DEBUG=false
export ROOT=$(pwd)
export TMP=$ROOT/tmp
## ##
# Source modules for functions # Source modules for functions
## ##
@ -18,6 +10,10 @@ export TMP=$ROOT/tmp
source modules/cli_msg.sh source modules/cli_msg.sh
loaded "CLI - Message types" loaded "CLI - Message types"
# Load variables/exports
source modules/variables.sh
loaded "EXPORT - Variables"
# TMP manager # TMP manager
source modules/tmp_manager.sh source modules/tmp_manager.sh
loaded "TMP Manager" loaded "TMP Manager"
@ -38,12 +34,6 @@ loaded "CLI - Docker main functions for image building"
# Trigger essential modules # Trigger essential modules
## ##
# Failsafe
system_type=$(uname -m)
if [ ! "${system_type}" = "x86_64" ]; then
msg_error "This is only supported for X86_64 systems"
fi
setup_tmp setup_tmp
msg_spacer msg_spacer
@ -62,6 +52,8 @@ while (($# >= 1)); do
-h|--help) show_help;; -h|--help) show_help;;
--amd64-image) build_amd64;; --amd64-image) build_amd64;;
--arm64-image) build_arm64;; --arm64-image) build_arm64;;
--amd64-push) push_amd64;;
--arm64-push) push_arm64;;
*) unknown_option ${1};; *) unknown_option ${1};;
-*) unknown_option ${1};; -*) unknown_option ${1};;
--*) unknown_option ${1};; --*) unknown_option ${1};;

View File

@ -3,6 +3,20 @@
## ##
delete_existing() { delete_existing() {
docker rmi hilledkinged/evolinx -f # AMD64
if [ "${ARCH}" = "amd64" ]; then
sudo docker rmi hilledkinged/evolinx:latest -f
fi
# ARM64
if [ "${ARCH}" = "arm64" ]; then
sudo docker rmi hilledkinged/evolinx:arm64 -f
fi
message "Existing image removed" message "Existing image removed"
} }
start_service() {
message "Starting docker service"
sudo systemctl restart docker
}

View File

@ -7,23 +7,50 @@ make_env () {
} }
cleanup_env() { cleanup_env() {
message "Cleaning up environment"
sudo rm -rf $TMP/rootfs sudo rm -rf $TMP/rootfs
} }
strap_base() { strap_base() {
sudo base-strap $TMP/rootfs base-chroot # AMD64
if [ "${ARCH}" = "amd64" ]; then
sudo base-strap $TMP/rootfs base-chroot
fi
# ARM64
if [ "${ARCH}" = "arm64" ]; then
sudo base-strap $TMP/rootfs base-chroot
fi
} }
rootfs_to_image() { rootfs_to_image() {
cd $TMP && sudo tar -C rootfs -c . | sudo docker import - hilledkinged/evolinx # AMD64
if [ "${ARCH}" = "amd64" ]; then
cd $TMP && sudo tar -C rootfs -c . | sudo docker import - hilledkinged/evolinx:latest
fi
# ARM64
if [ "${ARCH}" = "arm64" ]; then
cd $TMP && sudo tar -C rootfs -c . | sudo docker import - hilledkinged/evolinx:arm64
fi
} }
push_image() { amd64_push() {
if [ ]; then # AMD64
sudo docker image push hilledkinged/evolinx:latest if [ "${ARCH}" = "amd64" ]; then
sudo docker image push hilledkinged/evolinx:latest
fi
# ARM64
if [ "${ARCH}" = "arm64" ]; then
sudo docker image push hilledkinged/evolinx:arm64
fi
} }
build_base() { build_base() {
# Start/Restart docker service
start_service
# Prepare env in tmp # Prepare env in tmp
message "Preparing env" message "Preparing env"
make_env make_env
@ -39,16 +66,14 @@ build_base() {
# import tarball to image # import tarball to image
message "Importing final rootfs as image" message "Importing final rootfs as image"
rootfs_to_image rootfs_to_image
# Push new image to docker.io
push_image
# Cleanup
message "Cleaning up"
cleanup_env
} }
build_arm64() { build_arm64() {
# Failsafe ( decline running if not aarch64 system)
system_type=$(uname -m)
if [ "${system_type}" = "x86_64" ]; then
msg_error "This is only supported for aarch64 systems"
fi
# Set arch specific env values # Set arch specific env values
export ARCH=arm64 export ARCH=arm64
message "Building image for ${ARCH}" message "Building image for ${ARCH}"
@ -57,6 +82,12 @@ build_arm64() {
} }
build_amd64() { build_amd64() {
# Failsafe ( decline running if not x86_64 system)
system_type=$(uname -m)
if [ "${system_type}" = "aarch64" ]; then
msg_error "This is only supported for X86_64 systems"
fi
# Set arch specific env values # Set arch specific env values
export ARCH=amd64 export ARCH=amd64

View File

@ -24,7 +24,7 @@ loaded() {
echo -e "${BLUE}[ LOADED ]: ${LBLUE}$@${WHITE}" echo -e "${BLUE}[ LOADED ]: ${LBLUE}$@${WHITE}"
# As this function prints module loading then also lets sleep a bit so everything catches up in reality # As this function prints module loading then also lets sleep a bit so everything catches up in reality
sleep 1 sleep 0.3
} }
message() { message() {

View File

@ -1,7 +1,15 @@
setup_tmp() { setup_tmp() {
mkdir -p $TMP if [ "${TEMP_MANAGER}" = on ]; then
msg_debug "Not using built in tmp manager"
else
sudo mkdir -p $TMP
fi
} }
clean_tmp() { clean_tmp() {
rm -rf $TMP if [ "${TEMP_MANAGER}" = on ]; then
msg_debug "Not using built in tmp manager"
else
sudo rm -rf $TMP
fi
} }

21
modules/variables.sh Normal file
View File

@ -0,0 +1,21 @@
##
# Export some needed things for head script to work with
##
if [ "${TOOL_TEMP}" = "${TOOL_OUT}/tmp" ]; then
# Export variables that are needed for usage of TOOL
export SHOW_DEBUG=false
export ROOT=$P_ROOT
export TMP=$ROOT/out/tmp
# Dont use built in tmp manager here
export TEMP_MANAGER=off
else
# Export variables that are needed with usage of independent tool
export SHOW_DEBUG=false
export ROOT=$(pwd)
export TMP=$ROOT/tmp
# Use built in tmp manager
export TEMP_MANAGER=on
fi