@@ -5,10 +5,18 @@ dn=$(dirname "$0")
5
5
# shellcheck source=src/cmdlib.sh
6
6
. " ${dn} " /cmdlib.sh
7
7
8
+ # This script is used for creating both the bare metal and the canonical VM
9
+ # image (qemu). `buildextend-qemu` is a symlink to `buildextend-metal`.
10
+ case " $( basename " $0 " ) " in
11
+ " cmd-buildextend-metal" ) image_type=metal;;
12
+ " cmd-buildextend-qemu" ) image_type=qemu;;
13
+ * ) fatal " called as unexpected name $0 " ;;
14
+ esac
15
+
8
16
print_help () {
9
- cat 1>&2 << ' EOF '
10
- Usage: coreos-assembler buildextend-metal --help
11
- coreos-assembler buildextend-metal [--build ID]
17
+ cat 1>&2 << EOF
18
+ Usage: coreos-assembler buildextend-${image_type} --help
19
+ coreos-assembler buildextend-${image_type} [--build ID]
12
20
13
21
Build a bare metal image.
14
22
EOF
@@ -54,12 +62,16 @@ if [ $# -ne 0 ]; then
54
62
fi
55
63
56
64
case " $arch " in
57
- " x86_64" |" aarch64" |" s390x" )
58
- # # fall through to the rest of the file
59
- ;;
65
+ " x86_64" |" aarch64" |" s390x" ) use_anaconda=;;
60
66
* )
61
- echo " $arch is not supported for this command"
62
- exit 1
67
+ # for qemu, we can fallback to Anaconda
68
+ if [[ ${image_type} == qemu ]]; then
69
+ use_anaconda=1
70
+ else
71
+ # otherwise, we don't know how to create bare metal images for this
72
+ # architecture
73
+ fatal " $arch is not supported for this command"
74
+ fi
63
75
;;
64
76
esac
65
77
@@ -112,49 +124,75 @@ if [ "${rev_parsed}" != "${commit}" ]; then
112
124
fi # otherwise, the repo already has a ref, so no need to create
113
125
fi
114
126
127
+ image_format=raw
128
+ if [[ $image_type == qemu ]]; then
129
+ image_format=qcow2
130
+ fi
115
131
116
- img=${name} -${build} -metal.raw
132
+ img=${name} -${build} -${image_type} . ${image_format}
117
133
if [ -f " ${builddir} /${img} " ]; then
118
- echo " Bare metal image already exists"
134
+ echo " ${image_type} image already exists"
119
135
exit
120
136
fi
121
137
122
138
path=${PWD} /${img}
123
139
124
- echo " Estimating disk size..."
125
- /usr/lib/coreos-assembler/estimate-commit-disk-size --repo " $ostree_repo " " $ref " --add-percent 20 > " $PWD /tmp/ostree-size.json"
126
- size=" $( jq ' ."estimate-mb".final' " $PWD /tmp/ostree-size.json" ) "
127
- # extra size is the non-ostree partitions, see create_disk.sh
128
- size=" $(( size + 513 )) M"
129
- echo " Disk size estimated to $size "
140
+ # For bare metal images, we estimate the disk size. For qemu, we get it from
141
+ # image.yaml.
142
+ if [[ $image_type == metal ]]; then
143
+ echo " Estimating disk size..."
144
+ /usr/lib/coreos-assembler/estimate-commit-disk-size --repo " $ostree_repo " " $ref " --add-percent 20 > " $PWD /tmp/ostree-size.json"
145
+ size=" $( jq ' ."estimate-mb".final' " $PWD /tmp/ostree-size.json" ) "
146
+ # extra size is the non-ostree partitions, see create_disk.sh
147
+ size=" $(( size + 513 )) M"
148
+ echo " Disk size estimated to $size "
149
+ else
150
+ size=" $( python3 -c ' import sys, yaml; print(yaml.safe_load(sys.stdin)["size"])' < " $configdir /image.yaml" ) G"
151
+ fi
152
+
130
153
kargs=" $( python3 -c ' import sys, yaml; args = yaml.safe_load(sys.stdin).get("extra-kargs", []); print(" ".join(args))' < " $configdir /image.yaml" ) "
131
154
tty=" console=tty0 console=${VM_TERMINAL} ,115200n8"
132
155
# tty0 does not exist on s390x
133
156
if [ " $arch " == " s390x" ]; then
134
157
tty=" console=${VM_TERMINAL} "
135
158
fi
136
- kargs=" $kargs $tty ignition.platform.id=metal"
159
+ kargs=" $kargs $tty ignition.platform.id=$image_type "
160
+
137
161
ostree_remote=" $( python3 -c ' import sys, yaml; print(yaml.safe_load(sys.stdin).get("ostree-remote", "NONE"))' < " $configdir /image.yaml" ) "
138
162
save_var_subdirs=" $( python3 -c ' import sys, yaml; print(yaml.safe_load(sys.stdin).get("save-var-subdirs-for-selabel-workaround", "NONE"))' < " $configdir /image.yaml" ) "
139
163
140
- qemu-img create -f raw " ${path} .tmp" " $size "
141
- runvm_with_disk " ${path} .tmp" raw /usr/lib/coreos-assembler/create_disk.sh /dev/vda " $ostree_repo " " ${ref-: ${commit} } " " ${ostree_remote} " /usr/lib/coreos-assembler/grub.cfg " $name " " ${save_var_subdirs} " " \" $kargs \" "
142
- mv " ${path} .tmp" " $path "
143
-
144
- # flush it out before going to the next one so we don't have to redo both if
145
- # the next one fails
164
+ if [ -z " ${use_anaconda} " ]; then
165
+ qemu-img create -f ${image_format} " ${path} .tmp" " $size "
166
+ runvm_with_disk " ${path} .tmp" ${image_format} /usr/lib/coreos-assembler/create_disk.sh /dev/vda " $ostree_repo " " ${ref-: ${commit} } " " ${ostree_remote} " /usr/lib/coreos-assembler/grub.cfg " $name " " ${save_var_subdirs} " " \" $kargs \" "
167
+ mv " ${path} .tmp" " $path "
168
+ echo " {}" > tmp/vm-iso-checksum.json
169
+ else
170
+ [ " ${image_type} " == qemu ]
171
+ mkdir -p tmp/anaconda
172
+ # forgive me for this sin
173
+ checksum_location=$( find /usr/lib/coreos-assembler-anaconda/ -name ' *CHECKSUM' | head -1)
174
+ img_base=tmp/${name} -${build} -base.qcow2
175
+ run_virtinstall " ${ostree_repo} " " ${ref} " " ${PWD} " /" ${img_base} " --variant=cloud
176
+ /usr/lib/coreos-assembler/gf-platformid " $( pwd) " /" ${img_base} " " ${path} " qemu
177
+ vm_iso_checksum=$( awk ' /SHA256.*iso/{print$NF}' " ${checksum_location} " )
178
+ cat > tmp/vm-iso-checksum.json << EOF
179
+ {
180
+ "coreos-assembler.vm-iso-checksum": "${vm_iso_checksum} "
181
+ }
182
+ EOF
183
+ fi
146
184
147
185
# there's probably a jq one-liner for this...
148
186
python3 -c "
149
187
import sys, json
150
188
j = json.load(sys.stdin)
151
- j['images']['metal '] = {
189
+ j['images']['${image_type} '] = {
152
190
'path': '${img} ',
153
191
'sha256': '$( sha256sum_str < " ${img} " ) ',
154
192
'size': $( stat -c ' %s' " ${img} " )
155
193
}
156
194
json.dump(j, sys.stdout, indent=4)
157
- " < " ${builddir} /meta.json" > meta.json.new
195
+ " < " ${builddir} /meta.json" | cat - tmp/vm-iso-checksum.json | jq -s add > meta.json.new
158
196
159
197
# and now the crucial bit
160
198
mv -T meta.json.new " ${builddir} /meta.json"
0 commit comments