client: docker: complete build overhaul, optimize

This commit brings a complete overhaul of the build system:

- Creates a separation of concerns for 'local' and 'remote' building
  * 'local' is built locally via the docker-finance `build` command
  * 'remote' is built *outside* of the docker-finance `build` command
    (pushed to a remote registry and then pulled by the 'local' build)
  * Related refactoring
    - Dockerfiles
    - `lib_gen`

- Adds remote image 'hledger-suite'
  * Provides the latest versions of all `hledger` related binaries
  * No longer relies on package maintainers / out-dated packages

- Adds remote image 'docker-finance'
  * Provides base image for 'finance' and 'dev-tools' images
    - tags 'archlinux' | 'ubuntu' | 'dev-tools'

- Removes previous `hledger` related build modules
  * Removes building any `hledger` related binaries locally

- Removes 'experimental' build
  * End-user can use local custom Dockerfile and/or custom tag instead

- Updates the 'default' | 'slim' | 'tiny' | 'micro' build types
  * Refactors build type requirements into separate build modules
    - Adds 'fetch' module
    - Adds 'track' module
    - Adds 'user' module
      * creates container user *after* base and all other modules
      * allows for quick re-building across multiple local users
    - Updates 'root' module
  * `lib_docker`
    - Updates usage help
    - Adds build modules per build type

- Huge optimizations
  * Vastly improves build times
    - ~60% faster w/ a fresh build
    - ~60%-90% faster rebuild (depending on image type)
  * Vastly improves image sizes
    - e.g., 'default' Arch Linux image size is ~50% smaller
This commit is contained in:
2024-09-16 21:46:11 -07:00
parent 9feb05be2d
commit dc4990ab90
34 changed files with 554 additions and 582 deletions

View File

@@ -101,6 +101,10 @@ function lib_docker::__parse_args_build()
[ -z "$global_platform" ] && lib_utils::die_fatal
# Re-seat global usage for tag options
local _global_usage
_global_usage="$(echo $global_usage | cut -d: -f1)"
case "$global_platform" in
archlinux | ubuntu)
local -r _usage="
@@ -116,29 +120,28 @@ function lib_docker::__parse_args_build()
Build type:
type${global_arg_delim_2}<default|slim|tiny|micro|experimental>
\e[32mNotes:\e[0m
- All builds will continue to incorporate custom Dockerfile (see \`edit help\`)
- WARNING: for 'tiny' and 'micro'; use only if you trust pre-compiled assets hosted on GitHub (Microsoft)
type${global_arg_delim_2}<default|slim|tiny|micro>
\e[32mExamples:\e[0m
\e[37;2m# Build normal 'default' image\e[0m
$ $global_usage type${global_arg_delim_2}default
\e[37;2m# Build the latest 'default' image, tag as 'default'\e[0m
$ $_global_usage:default type${global_arg_delim_2}default
\e[37;2m# Build a smaller 'default' image but *without* ROOT.cern (meta-analysis) support\e[0m
$ $global_usage type${global_arg_delim_2}slim
\e[37;2m# Build the latest 'default' image *without* 'root' module (ROOT.cern), tag as 'slim'\e[0m
$ $_global_usage:slim type${global_arg_delim_2}slim
\e[37;2m# Build an even smaller 'default' image with *pre-built* hledger-flow binary (but *with* ROOT.cern support)\e[0m
$ $global_usage type${global_arg_delim_2}tiny
\e[37;2m# Build the latest 'slim' image *without* 'fetch' module (remote APIs), tag as 'tiny'\e[0m
$ $_global_usage:tiny type${global_arg_delim_2}tiny
\e[37;2m# Build the smallest image possible: the 'tiny' image *without* ROOT.cern support\e[0m
$ $global_usage type${global_arg_delim_2}micro
\e[37;2m# Build the latest 'tiny' image *without* 'track' support (time, metadata), tag as 'micro'\e[0m
$ $_global_usage:micro type${global_arg_delim_2}micro
\e[37;2m# Build experimental image based on 'default' image (WARNING: large image and possibly unstable)\e[0m
$ $global_usage type${global_arg_delim_2}experimental
\e[32mNotes:\e[0m
- Image tags are not connected to build type
(e.g., you can have an 'experimental' tag with a 'micro' image)
- All builds will continue to append your custom Dockerfile (see \`edit help\`)
"
;;
dev-tools)
@@ -163,8 +166,8 @@ function lib_docker::__parse_args_build()
\e[32mExamples:\e[0m
\e[37;2m# Build normal (default) image\e[0m
$ $global_usage type${global_arg_delim_2}default
\e[37;2m# Build the latest 'default' image, tag as default\e[0m
$ $_global_usage:default type${global_arg_delim_2}default
"
;;
*)
@@ -195,7 +198,7 @@ function lib_docker::__parse_args_build()
# Arg: type
if [ ! -z "$_arg_type" ]; then
[[ ! "$_arg_type" =~ ^default$|^slim$|^tiny$|^micro$|^experimental$ ]] \
[[ ! "$_arg_type" =~ ^default$|^slim$|^tiny$|^micro$ ]] \
&& lib_utils::die_usage "$_usage"
declare -gr global_arg_type="$_arg_type"
@@ -228,52 +231,67 @@ function lib_docker::__build()
"$_in_file" >"$_final" || return $?
#
# Append to Dockerfile according to type
# Append platform build modules according to build type
#
if [[ "$global_platform" == "dev-tools" && "$global_arg_type" != "default" ]]; then
lib_utils::print_warning "'${global_arg_type}' is not supported for 'dev-tools', using 'default'"
fi
local _files=()
if [[ "$global_platform" != "dev-tools" ]]; then
case "$global_platform" in
archlinux | ubuntu)
local -r _path="${global_repo_dockerfiles}/${global_platform}"
case "$global_arg_type" in
default)
_files+=("${_path}/Dockerfile.track.in")
_files+=("${_path}/Dockerfile.fetch.in")
_files+=("${_path}/Dockerfile.root.in")
_files+=("${_path}/Dockerfile.user.in")
;;
slim)
_files+=("${_path}/Dockerfile.track.in")
_files+=("${_path}/Dockerfile.fetch.in")
_files+=("${_path}/Dockerfile.user.in")
lib_utils::print_warning "not building module: 'root'"
;;
tiny)
_files+=("${_path}/Dockerfile.track.in")
_files+=("${_path}/Dockerfile.user.in")
lib_utils::print_warning "not building module: 'fetch'"
lib_utils::print_warning "not building module: 'root'"
;;
micro)
_files+=("${_path}/Dockerfile.user.in")
lib_utils::print_warning "not building module: 'track'"
lib_utils::print_warning "not building module: 'fetch'"
lib_utils::print_warning "not building module: 'root'"
;;
*)
lib_utils::die_fatal "unsupported build"
;;
esac
;;
dev-tools)
case "$global_arg_type" in
default)
local -r _path="${global_repo_dockerfiles}/ubuntu"
_files+=("${_path}/Dockerfile.user.in")
;;
*)
lib_utils::print_warning "'${global_arg_type}' is not supported for 'dev-tools', using 'default'"
;;
esac
;;
*)
lib_utils::die_fatal "unsupported platform"
;;
esac
local _files=()
local _path="${global_repo_dockerfiles}/${global_platform}"
case "$global_arg_type" in
default)
_files+=("${_path}/Dockerfile.hledger-flow.src.in")
_files+=("${_path}/Dockerfile.root.in")
;;
slim)
_files+=("${_path}/Dockerfile.hledger-flow.src.in")
;;
tiny)
_files+=("${_path}/Dockerfile.hledger-flow.bin.in")
_files+=("${_path}/Dockerfile.root.in")
;;
micro)
_files+=("${_path}/Dockerfile.hledger-flow.bin.in")
;;
experimental)
_path+="/experimental"
_files+=("${_path}/Dockerfile.hledger-flow.src.in")
_files+=("${_path}/Dockerfile.hledger.src.in")
_files+=("${_path}/Dockerfile.root.in")
;;
*)
lib_utils::die_fatal "unsupported build"
;;
esac
for _file in "${_files[@]}"; do
lib_utils::print_debug "Appending '${_file}' to '${_final}'"
sed \
-e "s:@DOCKER_FINANCE_USER@:${DOCKER_FINANCE_USER}:g" \
"$_file" >>"$_final" || return $?
done
fi
for _file in "${_files[@]}"; do
lib_utils::print_debug "Appending '${_file}' to '${_final}'"
sed \
-e "s:@DOCKER_FINANCE_UID@:${DOCKER_FINANCE_UID}:g" \
-e "s:@DOCKER_FINANCE_USER@:${DOCKER_FINANCE_USER}:g" \
"$_file" >>"$_final" || return $?
done
#
# Append to Dockerfile end-user's custom Dockerfile