Skip to content

Commit 9f88553

Browse files
Fixes in docker image import (#795)
- allow to use image with tag name, such as docker.io/library/influxdb:2.7 - on ZFS just clone buildah-provided volume, not rsync
1 parent c494d89 commit 9f88553

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

tools/images

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,12 @@ images_register()
163163
fi
164164
[ -r /tmp/images.$$ ] && ${RM_CMD} -f /tmp/images.$$
165165
echo "Image name: ${_imgname}"
166+
_imgshort=$( substr --pos=0 --len=12 --str="${_imgname}" )
166167
if [ -n "${NOCOLOR}" ]; then
167-
${BUILDAH_CMD} --root ${workdir}/basejail/buildah images | ${GREP_CMD} "${path}"
168+
${BUILDAH_CMD} --root ${workdir}/basejail/buildah images ${_imgname} | ${GREP_CMD} "${_imgshort}"
168169
_ret=$?
169170
else
170-
${BUILDAH_CMD} --root ${workdir}/basejail/buildah images | ${ENV_CMD} GREP_COLORS='mt=37;45' GREP_COLOR='37;45' ${GREP_CMD} --colour=always "${path}"
171+
${BUILDAH_CMD} --root ${workdir}/basejail/buildah images ${_imgname} | ${ENV_CMD} GREP_COLORS='mt=37;45' GREP_COLOR='37;45' ${GREP_CMD} --colour=always "${_imgshort}"
171172
_ret=$?
172173
fi
173174

@@ -215,7 +216,20 @@ images_register()
215216

216217
##ZFS
217218
if [ ${zfsfeat} -eq 1 ]; then
218-
jcreate jname="${_md5}" host_hostname=${_md5}.my.domain ver=empty baserw=1 pkg_bootstrap=0 floatresolv=0 applytpl=0 etcupdate_init=0
219+
_buildah_container_volume=$(${MOUNT_CMD} | ${AWK_CMD} '($2 == "on" && $3 == "'"${_imgpath}"'") { print $1; }')
220+
if [ -z "$_buildah_container_volume" ]; then
221+
${ECHO} "${N1_COLOR}${CBSD_APP}: unable find zfs volume for ${_imgpath} ${N0_COLOR}"
222+
exit 1
223+
fi
224+
225+
_buildah_image_snapshot=$(${ZFS_CMD} get origin "${_buildah_container_volume}" | ${AWK_CMD} '($2 == "origin") {print $3;}')
226+
if [ -z "${_buildah_image_snapshot}" ]; then
227+
${ECHO} "${N1_COLOR}${CBSD_APP}: unable find ZFS image orign for ${_buildah_container_volume} ${N0_COLOR}"
228+
exit 1
229+
fi
230+
231+
jcreate jname="${_md5}" host_hostname=${_md5}.my.domain zfs_snapsrc="${_buildah_image_snapshot}"\
232+
ver=empty baserw=1 pkg_bootstrap=0 floatresolv=0 applytpl=0 etcupdate_init=0
219233
_ret=$?
220234
[ ${_ret} -ne 0 ] && err 1 "${N1_COLOR}${CBSD_APP}unable to create jail: ${N2_COLOR}jcreate jname="${_md5}" host_hostname=${_md5}.my.domain${N0_COLOR}"
221235
_rootfs="${workdir}/jails-data/${_md5}-data"
@@ -227,7 +241,7 @@ images_register()
227241
# create_from_srcsnap loop
228242
. ${subrdir}/zfs.subr
229243
DATA=$( ${ZFS_CMD} get -Ho value name ${jaildatadir} )
230-
${RSYNC_CMD} -z -a --hard-links --links --acls --xattrs --numeric-ids --recursive --partial ${_imgpath}/ ${_rootfs}/
244+
231245
_zfssrc="${DATA}/${_md5}"
232246
_zfssrc_snap=$( get_zfs_image_snap ${_zfssrc} )
233247
# with ZFS we dont need image file anymore
@@ -256,7 +270,6 @@ images_register()
256270

257271
${BUILDAH_CMD} --root ${workdir}/basejail/buildah unmount ${_md5}
258272
${BUILDAH_CMD} --root ${workdir}/basejail/buildah rm ${_md5}
259-
${BUILDAH_CMD} --root ${workdir}/basejail/buildah rmi ${_imgname}
260273

261274
[ -z "${emulator}" ] && emulator="jail"
262275
[ -z "${name}" ] && name="${path}"

0 commit comments

Comments
 (0)