uci-docker-build/readme.md

79 lines
4.0 KiB
Markdown
Raw Normal View History

# UCI Docker Image Builder
Prerequistes:
see https://hacking.kebler.net/Linux/Arch/docker/
<!-- assuming your current (dev) user is in the docker group
for linking into volumes for the try command
```
sudo chown -R :docker /var/lib/docker
sudo chmod -R g+r docker /var/lib/docker
``` -->
A build script plus associated library to facilitate building docker linux images using any of four distros (arch,alpine,debian,ubuntu) and either architecture (amd64/arm64)
The Dockerfile is minimal copying a directory and then calling a packages script and and init script in two RUN statements calling a set of distro specific scripts and common scripts in order to build the image
The build environment makes user of docker's "buildx bake" commands and a docker-bake.hcl file
The master branch is configured to build base images from the docker hub distro base images
The main script is "build" At the very minimum run as just `./build` it will build an alpine image from the docker hub official alpine latest image with a minimal set of packages installed (e.g. git) and a custom uci shell environment.
To run the ./build script from other repos install it using the ./install install which just creates a link in /opt/bin
`ln -nsf $(dirname "$(realpath "$BASH_SOURCE")")/build /opt/bin/dbuild`
The repo also supports (with scripts) pushing to alternate private repositories packages (like a self hosted gitea or github)
One can make decendent images in one of two ways.
1. Make your base images on the master branch (or a branch if you need to customize)
2. User the installer script (./install) to link the build script into your system path. Then clone the template branch
3.
the build script requires an init.sh file in a source directory for the scripts it will run while building a new image
by default that is `<source directory>/init.sh`. by default that source directory is `src/` relative to the current directory
```
Image Build Script: Creates one or more images using a target in the docker-bake.hcl file
USAGE: /opt/bin/dbuild <subcommand> <options> <build_target> <imagename, imageuser>
valid build_target: dev arm amd deploy private multi; default: dev
### subcommands:
try (runs try a container script, see try usage) /opt/bin/dbuild try -i
tag (runs image_tag script)
info get image info, info <arch, exists, id> nothing is all info in json
--- option switches (no argument):
-o do not overwrite an existing image (default), instead move it to a temporary timestamp tag
-i rebuild only the initialization RUN by busting the cache at that point
-v show verbose information about the build
-a (auto) do not prompt to continue build, by default will not prompt if non-interactive shell
-c after build try out the image by starting a container terminal therein, for dev target this is the default;
-x exclude distro from image name;
-n for --no_cache
-k keep the build scripts (see -w) after the build so they are incorporated into the image
-p push to repository; after build push to repository default is hub.docker.com (not need for deploy target)
--- options with argument <ARGUMENT>:
-e <path to environment file> load any or all of options below via a file
-d <LINUX_DISTRO> supported: alpine, debian, ubuntu, default: alpine; if base image set distro will be determined
-t <TAG> tag following : in output image name (i.e. REPO/USER/NAME:TAG), default: latest
-u <USER>; repository user prefix in output image name (i.e. REPO/USER/NAME:TAG)
-r <REPO>; private repo name, do not use for hub.docker.com (docker.io)
-b <BASE_IMAGE>; used in FROM in Dockerfile, default is official distro image (e.g. alpine:latest)
-w <BUILD_DIR>; set a custom WORKDIR in Dockerfile (in image), default is /build, see -k
--- options set ONLY by environment variable (see -e as well)
<SYSADMIN_PW> set alternate password for container sysadmin account, default is 'sysadmin'
NOTE any option with <CAPTIALIZED> above can be set in environment instead
#### examples:
/opt/bin/dbuild -a -d ubuntu -u ucommandit
build (without prompt) a local ubuntu image from scratch and label it ucommandit/ubuntu:latest
```