diff options
author | Bruce Ashfield <bruce.ashfield@gmail.com> | 2021-05-07 12:16:41 -0400 |
---|---|---|
committer | Bruce Ashfield <bruce.ashfield@gmail.com> | 2021-07-19 13:36:17 -0400 |
commit | 96c47ad0b8c95e6f6401d2a479c3444bb7b6415e (patch) | |
tree | 67c29e9f2fba9a3bd85c1c252a9b8c6fb9238608 /classes/image-oci-umoci.inc | |
parent | 62137a394fdaa46abbbd539cd6e83d2607520bf0 (diff) | |
download | meta-virtualization-96c47ad0b8c95e6f6401d2a479c3444bb7b6415e.tar.gz |
oci-images: create backend .inc files
As part of allowing different types of oci images to be created,
we split our IMG_cmd into .inc files that can then be specific to
the selected type.
For the umoci backend: We can take the same options as sloci
expects and use umoci to create images.
The resulting OCI image is similar, but by using umoci, we set
the stage to do multi-tag, or multi-layer images in the future.
But for now, we are functionally equivalent to the sloci backend.
Signed-off-by: Bruce Ashfield <bruce.ashfield@gmail.com>
Diffstat (limited to 'classes/image-oci-umoci.inc')
-rw-r--r-- | classes/image-oci-umoci.inc | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/classes/image-oci-umoci.inc b/classes/image-oci-umoci.inc new file mode 100644 index 00000000..b622714e --- /dev/null +++ b/classes/image-oci-umoci.inc | |||
@@ -0,0 +1,111 @@ | |||
1 | IMAGE_CMD_oci() { | ||
2 | umoci_options="" | ||
3 | |||
4 | bbdebug 1 "UMOCI image settings:" | ||
5 | bbdebug 1 " author: ${OCI_IMAGE_AUTHOR}" | ||
6 | bbdebug 1 " author email: ${OCI_IMAGE_AUTHOR_EMAIL}" | ||
7 | bbdebug 1 " tag: ${OCI_IMAGE_TAG}" | ||
8 | bbdebug 1 " arch: ${OCI_IMAGE_ARCH}" | ||
9 | bbdebug 1 " subarch: ${OCI_IMAGE_SUBARCH}" | ||
10 | bbdebug 1 " entrypoint: ${OCI_IMAGE_ENTRYPOINT}" | ||
11 | bbdebug 1 " entrypoint args: ${OCI_IMAGE_ENTRYPOINT_ARGS}" | ||
12 | bbdebug 1 " labels: ${OCI_IMAGE_LABELS}" | ||
13 | bbdebug 1 " uid: ${OCI_IMAGE_RUNTIME_UID}" | ||
14 | bbdebug 1 " working dir: ${OCI_IMAGE_WORKINGDIR}" | ||
15 | bbdebug 1 " env vars: ${OCI_IMAGE_ENV_VARS}" | ||
16 | bbdebug 1 " ports: ${OCI_IMAGE_PORTS}" | ||
17 | |||
18 | OCI_REUSE_IMAGE="" | ||
19 | |||
20 | # Change into the image deploy dir to avoid having any output operations capture | ||
21 | # long directories or the location. | ||
22 | cd ${IMGDEPLOYDIR} | ||
23 | |||
24 | new_image=t | ||
25 | image_name="${IMAGE_NAME}${IMAGE_NAME_SUFFIX}-oci" | ||
26 | image_bundle_name="${IMAGE_NAME}${IMAGE_NAME_SUFFIX}-oci-bundle" | ||
27 | if [ -n "$OCI_REUSE_IMAGE" ]; then | ||
28 | if [ -d $image_name ]; then | ||
29 | bbdebug 1 "OCI: reusing image directory" | ||
30 | new_image="" | ||
31 | fi | ||
32 | else | ||
33 | bbdebug 1 "OCI: removing existing container image directory" | ||
34 | rm -rf $image_name $image_bundle_name | ||
35 | fi | ||
36 | |||
37 | if [ -z "${OCI_IMAGE_TAG}" ]; then | ||
38 | OCI_IMAGE_TAG="initial-tag" | ||
39 | fi | ||
40 | |||
41 | if [ -n "$new_image" ]; then | ||
42 | bbdebug 1 "OCI: umoci init --layout $image_name" | ||
43 | umoci init --layout $image_name | ||
44 | umoci new --image $image_name:${OCI_IMAGE_TAG} | ||
45 | umoci unpack --rootless --image $image_name:${OCI_IMAGE_TAG} $image_bundle_name | ||
46 | else | ||
47 | # todo: create a different tag, after checking if the passed one exists | ||
48 | true | ||
49 | fi | ||
50 | |||
51 | bbdebug 1 "OCI: populating rootfs" | ||
52 | bbdebug 1 "OCI: cp -r ${IMAGE_ROOTFS}/* $image_bundle_name/rootfs/" | ||
53 | cp -r ${IMAGE_ROOTFS}/* $image_bundle_name/rootfs | ||
54 | |||
55 | bbdebug 1 "OCI: umoci repack --image $image_name:${OCI_IMAGE_TAG} $image_bundle_name" | ||
56 | umoci repack --image $image_name:${OCI_IMAGE_TAG} $image_bundle_name | ||
57 | |||
58 | bbdebug 1 "OCI: configuring image" | ||
59 | if [ -n "${OCI_IMAGE_LABELS}" ]; then | ||
60 | for l in ${OCI_IMAGE_LABELS}; do | ||
61 | bbdebug 1 "OCI: umoci config --image $image_name --config.label $l" | ||
62 | umoci config --image $image_name --config.label $l | ||
63 | done | ||
64 | fi | ||
65 | if [ -n "${OCI_IMAGE_ENV_VARS}" ]; then | ||
66 | for l in ${OCI_IMAGE_ENV_VARS}; do | ||
67 | bbdebug 1 "umoci config --image $image_name --config.env $l" | ||
68 | umoci config --image $image_name --config.env $l | ||
69 | done | ||
70 | fi | ||
71 | if [ -n "${OCI_IMAGE_PORTS}" ]; then | ||
72 | for l in ${OCI_IMAGE_PORTS}; do | ||
73 | bbdebug 1 "umoci config --image $image_name --config.exposedports $l" | ||
74 | umoci config --image $image_name --config.exposedports $l | ||
75 | done | ||
76 | fi | ||
77 | if [ -n "${OCI_IMAGE_RUNTIME_UID}" ]; then | ||
78 | bbdebug 1 "umoci config --image $image_name --config.user ${OCI_IMAGE_RUNTIME_UID}" | ||
79 | umoci config --image $image_name --config.user ${OCI_IMAGE_RUNTIME_UID} | ||
80 | fi | ||
81 | if [ -n "${OCI_IMAGE_WORKINGDIR}" ]; then | ||
82 | bbdebug 1 "umoci config --image $image_name --config.workingdir ${OCI_IMAGE_WORKINGDIR}" | ||
83 | umoci config --image $image_name --config.workingdir ${OCI_IMAGE_WORKINGDIR} | ||
84 | fi | ||
85 | if [ -n "${OCI_IMAGE_OS}" ]; then | ||
86 | bbdebug 1 "umoci config --image $image_name --os ${OCI_IMAGE_OS}" | ||
87 | umoci config --image $image_name --os ${OCI_IMAGE_OS} | ||
88 | fi | ||
89 | |||
90 | bbdebug 1 "umoci config --image $image_name --architecture ${OCI_IMAGE_ARCH}" | ||
91 | umoci config --image $image_name --architecture ${OCI_IMAGE_ARCH} | ||
92 | # NOTE: umoci doesn't currently expose setting the architecture variant, | ||
93 | # so if you need it use sloci instead | ||
94 | if [ -n "${OCI_IMAGE_SUBARCH}" ]; then | ||
95 | bbnote "OCI: image subarch is set to: ${OCI_IMAGE_SUBARCH}, but umoci does not" | ||
96 | bbnote " expose variants. use sloci instead if this is important" | ||
97 | fi | ||
98 | umoci config --image $image_name --config.entrypoint ${OCI_IMAGE_ENTRYPOINT} | ||
99 | if [ -n "${OCI_IMAGE_ENTRYPOINT_ARGS}" ]; then | ||
100 | umoci config --image $image_name --config.cmd "${OCI_IMAGE_ENTRYPOINT_ARGS}" | ||
101 | fi | ||
102 | umoci config --image $image_name --author ${OCI_IMAGE_AUTHOR_EMAIL} | ||
103 | |||
104 | # make a tar version of the image direcotry | ||
105 | if [ -n "${OCI_IMAGE_TAR_OUTPUT}" ]; then | ||
106 | tar -cf "$image_name.tar" "$image_name" | ||
107 | fi | ||
108 | |||
109 | # We could make this optional, since the bundle is directly runnable via runc | ||
110 | rm -rf $image_bundle_name | ||
111 | } | ||