-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootc-image-builder-create-image.sh
executable file
·64 lines (56 loc) · 1.75 KB
/
bootc-image-builder-create-image.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#! /bin/bash
set -exo pipefail
DISTRO="${DISTRO:-fedora-eln}"
CONTAINER_IMAGE="${CONTAINER_IMAGE:-quay.io/mmartinv/bootc-kiosk-demo:${DISTRO}}"
IMAGE_TYPE="${IMAGE_TYPE:-qcow2}"
BLUEPRINT_FILE="/tmp/blueprint.json"
OUTPUT_DIR="./images/${DISTRO}"
mkdir -p "${OUTPUT_DIR}"
if [ -z "$CONTAINER_ENGINE" ]; then
CONTAINER_CMD="${CONTAINER_CMD:-$(command -v podman)}"
[ -n "${CONTAINER_CMD}" ] || CONTAINER_CMD=$(command -v docker)
if [ -z "${CONTAINER_CMD}" ]; then
echo "No container engine found."
exit 1
else
echo "Using detected container engine: $(basename ${CONTAINER_CMD})"
fi
else
CONTAINER_CMD="${CONTAINER_CMD:-$(command -v ${CONTAINER_ENGINE})}"
if [ -z "${CONTAINER_CMD}" ]; then
echo "Container engine not found: ${CONTAINER_ENGINE}"
exit 1
fi
fi
SSH_PUB_KEY=$(cat "${HOME}/.ssh/id_rsa.pub")
echo "{
\"blueprint\": {
\"customizations\": {
\"user\": [
{
\"name\": \"${USER}\",
\"password\": \"redhat\",
\"key\": \"${SSH_PUB_KEY})\",
\"groups\": [
\"wheel\"
]
}
]
}
}
}" > "${BLUEPRINT_FILE}"
[ "$(basename ${CONTAINER_CMD})" != "podman" ] || CONTAINER_CMD="sudo ${CONTAINER_CMD}"
[ "$(basename ${CONTAINER_CMD})" != "docker" ] || [ "$(docker context show)" != "rootless" ] || \
(echo "Cannot use rootless docker to build images please change your docker context to be rootful" && exit 1)
${CONTAINER_CMD} run \
--rm \
-it \
--privileged \
--pull "newer" \
--security-opt "label=type:unconfined_t" \
-v "${OUTPUT_DIR}:/output" \
-v "${BLUEPRINT_FILE}:/config.json" \
"quay.io/centos-bootc/bootc-image-builder:latest" \
--type "${IMAGE_TYPE}" \
--config "/config.json" \
"${CONTAINER_IMAGE}"