summaryrefslogtreecommitdiffstats
path: root/classes
diff options
context:
space:
mode:
Diffstat (limited to 'classes')
-rw-r--r--classes/image-oci-sloci-image.inc67
-rw-r--r--classes/image-oci-umoci.inc111
-rw-r--r--classes/image-oci.bbclass84
3 files changed, 195 insertions, 67 deletions
diff --git a/classes/image-oci-sloci-image.inc b/classes/image-oci-sloci-image.inc
new file mode 100644
index 00000000..36d3c2da
--- /dev/null
+++ b/classes/image-oci-sloci-image.inc
@@ -0,0 +1,67 @@
1IMAGE_CMD_oci() {
2 sloci_options=""
3
4 bbdebug 1 "OCI 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 " entrypoing 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 # Change into the image deploy dir to avoid having any output operations capture
19 # long directories or the location.
20 cd ${IMGDEPLOYDIR}
21
22 oci_image_label_options=""
23 if [ -n "${OCI_IMAGE_LABELS}" ]; then
24 for l in ${OCI_IMAGE_LABELS}; do
25 oci_image_label_options="${oci_image_label_options} --label ${l}"
26 done
27 fi
28 oci_image_env_options=""
29 if [ -n "${OCI_IMAGE_ENV_VARS}" ]; then
30 for l in ${OCI_IMAGE_ENV_VARS}; do
31 oci_image_env_options="${oci_image_env_options} --env ${l}"
32 done
33 fi
34 oci_image_port_options=""
35 if [ -n "${OCI_IMAGE_PORTS}" ]; then
36 for l in ${OCI_IMAGE_PORTS}; do
37 oci_image_port_options="${oci_image_port_options} --port ${l}"
38 done
39 fi
40
41 if [ -n "${OCI_IMAGE_RUNTIME_UID}" ]; then
42 oci_image_user_options="--user ${OCI_IMAGE_RUNTIME_UID}"
43 fi
44
45 if [ -n "${OCI_IMAGE_WORKINGDIR}" ]; then
46 oci_image_working_dir_options="--working-dir ${OCI_IMAGE_WORKINGDIR}"
47 fi
48
49 if [ -n "${OCI_IMAGE_TAR_OUTPUT}" ]; then
50 sloci_options="$sloci_options --tar"
51 fi
52
53 # options that always appear are required for a valid oci container image
54 # others are optional based on settings.
55 sloci-image $sloci_options \
56 --arch ${OCI_IMAGE_ARCH} \
57 --arch-variant "${OCI_IMAGE_SUBARCH}" \
58 --entrypoint ${OCI_IMAGE_ENTRYPOINT} \
59 --cmd "${OCI_IMAGE_ENTRYPOINT_ARGS}" \
60 --author ${OCI_IMAGE_AUTHOR_EMAIL} \
61 ${oci_image_user_options} \
62 ${oci_image_label_options} \
63 ${oci_image_env_options} \
64 ${oci_image_working_dir_options} \
65 ${oci_image_port_options} \
66 ${IMAGE_ROOTFS} ${IMAGE_NAME}${IMAGE_NAME_SUFFIX}-oci:${OCI_IMAGE_TAG}
67}
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 @@
1IMAGE_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}
diff --git a/classes/image-oci.bbclass b/classes/image-oci.bbclass
index c256b12c..464ea3b4 100644
--- a/classes/image-oci.bbclass
+++ b/classes/image-oci.bbclass
@@ -16,19 +16,32 @@
16# And then create the bundle: 16# And then create the bundle:
17# % oci-image-tool create --ref name=latest container-base-<arch>-<stamp>.rootfs-oci container-base-oci-bundle 17# % oci-image-tool create --ref name=latest container-base-<arch>-<stamp>.rootfs-oci container-base-oci-bundle
18# 18#
19# Alternatively, the bundle can be created with umoci (use --rootless if sudo is not available)
20# % sudo umoci unpack --image container-base-<arch>-<stamp>.rootfs-oci:latest container-base-oci-bundle
21#
19# Or to copy (push) the oci image to a docker registry, skopeo can be used (vary the 22# Or to copy (push) the oci image to a docker registry, skopeo can be used (vary the
20# tag based on the created oci image: 23# tag based on the created oci image:
21# 24#
22# % skopeo copy --dest-creds <username>:<password> oci:container-base-<arch>-<stamp>:latest docker://zeddii/container-base 25# % skopeo copy --dest-creds <username>:<password> oci:container-base-<arch>-<stamp>:latest docker://zeddii/container-base
23# 26#
27# If your build host architecture matches the target, you can execute the unbundled
28# container with runc:
29#
30# % sudo runc run -b container-base-oci-bundle ctr-build
31# / % uname -a
32# Linux mrsdalloway 4.18.0-25-generic #26-Ubuntu SMP Mon Jun 24 09:32:08 UTC 2019 x86_64 GNU/Linux
33#
24 34
25# We'd probably get this through the container image typdep, but just 35# We'd probably get this through the container image typdep, but just
26# to be sure, we'll repeat it here. 36# to be sure, we'll repeat it here.
27ROOTFS_BOOTSTRAP_INSTALL = "" 37ROOTFS_BOOTSTRAP_INSTALL = ""
28# we want container and tar.bz2's to be created 38# we want container and tar.bz2's to be created
29IMAGE_TYPEDEP_oci = "container tar.bz2" 39IMAGE_TYPEDEP_oci = "container tar.bz2"
40
30# sloci is the script/project that will create the oci image 41# sloci is the script/project that will create the oci image
31do_image_oci[depends] += "sloci-image-native:do_populate_sysroot" 42# OCI_IMAGE_BACKEND ?= "sloci-image"
43OCI_IMAGE_BACKEND ?= "umoci"
44do_image_oci[depends] += "${OCI_IMAGE_BACKEND}-native:do_populate_sysroot"
32 45
33# 46#
34# image type configuration block 47# image type configuration block
@@ -75,70 +88,7 @@ def oci_map_subarch(a, f, d):
75 return '' 88 return ''
76 return '' 89 return ''
77 90
78IMAGE_CMD_oci() { 91# the IMAGE_CMD_oci comes from the .inc
79 sloci_options="" 92OCI_IMAGE_BACKEND_INC ?= "${@"image-oci-" + "${OCI_IMAGE_BACKEND}" + ".inc"}"
80 93include ${OCI_IMAGE_BACKEND_INC}
81 bbdebug 1 "OCI image settings:"
82 bbdebug 1 " author: ${OCI_IMAGE_AUTHOR}"
83 bbdebug 1 " author email: ${OCI_IMAGE_AUTHOR_EMAIL}"
84 bbdebug 1 " tag: ${OCI_IMAGE_TAG}"
85 bbdebug 1 " arch: ${OCI_IMAGE_ARCH}"
86 bbdebug 1 " subarch: ${OCI_IMAGE_SUBARCH}"
87 bbdebug 1 " entrypoint: ${OCI_IMAGE_ENTRYPOINT}"
88 bbdebug 1 " entrypoing args: ${OCI_IMAGE_ENTRYPOINT_ARGS}"
89 bbdebug 1 " labels: ${OCI_IMAGE_LABELS}"
90 bbdebug 1 " uid: ${OCI_IMAGE_RUNTIME_UID}"
91 bbdebug 1 " working dir: ${OCI_IMAGE_WORKINGDIR}"
92 bbdebug 1 " env vars: ${OCI_IMAGE_ENV_VARS}"
93 bbdebug 1 " ports: ${OCI_IMAGE_PORTS}"
94
95 # Change into the image deploy dir to avoid having any output operations capture
96 # long directories or the location.
97 cd ${IMGDEPLOYDIR}
98
99 oci_image_label_options=""
100 if [ -n "${OCI_IMAGE_LABELS}" ]; then
101 for l in ${OCI_IMAGE_LABELS}; do
102 oci_image_label_options="${oci_image_label_options} --label ${l}"
103 done
104 fi
105 oci_image_env_options=""
106 if [ -n "${OCI_IMAGE_ENV_VARS}" ]; then
107 for l in ${OCI_IMAGE_ENV_VARS}; do
108 oci_image_env_options="${oci_image_env_options} --env ${l}"
109 done
110 fi
111 oci_image_port_options=""
112 if [ -n "${OCI_IMAGE_PORTS}" ]; then
113 for l in ${OCI_IMAGE_PORTS}; do
114 oci_image_port_options="${oci_image_port_options} --port ${l}"
115 done
116 fi
117
118 if [ -n "${OCI_IMAGE_RUNTIME_UID}" ]; then
119 oci_image_user_options="--user ${OCI_IMAGE_RUNTIME_UID}"
120 fi
121
122 if [ -n "${OCI_IMAGE_WORKINGDIR}" ]; then
123 oci_image_working_dir_options="--working-dir ${OCI_IMAGE_WORKINGDIR}"
124 fi
125
126 if [ -n "${OCI_IMAGE_TAR_OUTPUT}" ]; then
127 sloci_options="$sloci_options --tar"
128 fi
129 94
130 # options that always appear are required for a valid oci container image
131 # others are optional based on settings.
132 sloci-image $sloci_options \
133 --arch ${OCI_IMAGE_ARCH} \
134 --arch-variant "${OCI_IMAGE_SUBARCH}" \
135 --entrypoint ${OCI_IMAGE_ENTRYPOINT} \
136 --cmd "${OCI_IMAGE_ENTRYPOINT_ARGS}" \
137 --author ${OCI_IMAGE_AUTHOR_EMAIL} \
138 ${oci_image_user_options} \
139 ${oci_image_label_options} \
140 ${oci_image_env_options} \
141 ${oci_image_working_dir_options} \
142 ${oci_image_port_options} \
143 ${IMAGE_ROOTFS} ${IMAGE_NAME}${IMAGE_NAME_SUFFIX}-oci:${OCI_IMAGE_TAG}
144}