bootoci 0.3.0__tar.gz → 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bootoci
3
- Version: 0.3.0
3
+ Version: 0.4.0
4
4
  Summary: Convert OCI images to bootable disk images
5
5
  Maintainer-email: Nadav Tasher <hey@nadav.app>
6
6
  License-Expression: MIT
@@ -80,6 +80,9 @@ bootoci -o ./bin/disk.img --docker --kernel-from-debian --tag postgres --dockerf
80
80
  ```bash
81
81
  # Build a fully-fledged ubuntu desktop machine
82
82
  python3 -m src.bootoci.cli --docker --kernel-from-debian -f ./examples/ubuntu-desktop.Dockerfile --size 4096 --serial --password "root:12345678" --password "user:12345678"
83
+
84
+ # Build a test image
85
+ python3 -m src.bootoci.cli --docker --kernel-from-debian -f ./examples/entrypoint.Dockerfile --size 1024 --password "root:12345678" --entrypoint
83
86
  ```
84
87
 
85
88
  ## Testing images
@@ -64,6 +64,9 @@ bootoci -o ./bin/disk.img --docker --kernel-from-debian --tag postgres --dockerf
64
64
  ```bash
65
65
  # Build a fully-fledged ubuntu desktop machine
66
66
  python3 -m src.bootoci.cli --docker --kernel-from-debian -f ./examples/ubuntu-desktop.Dockerfile --size 4096 --serial --password "root:12345678" --password "user:12345678"
67
+
68
+ # Build a test image
69
+ python3 -m src.bootoci.cli --docker --kernel-from-debian -f ./examples/entrypoint.Dockerfile --size 1024 --password "root:12345678" --entrypoint
67
70
  ```
68
71
 
69
72
  ## Testing images
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "bootoci"
3
- version = "0.3.0"
3
+ version = "0.4.0"
4
4
  requires-python = ">= 3.8"
5
5
  description = "Convert OCI images to bootable disk images"
6
6
  readme = "README.md"
@@ -8,6 +8,9 @@ def parse_arguments():
8
8
  # Create argument parser
9
9
  parser = argparse.ArgumentParser()
10
10
 
11
+ # Don't use backend caches
12
+ parser.add_argument("--no-cache", action="store_true", help="Don't use backend cache and don't store caches")
13
+
11
14
  # Output directory
12
15
  parser.add_argument("--output-filepath", "--output", "-o", action="store", default="disk.img", help="Output file path")
13
16
 
@@ -27,6 +30,7 @@ def parse_arguments():
27
30
  # Where does the kernel come from? Optional. Image can already have kernel.
28
31
  kernel_group = parser.add_mutually_exclusive_group(required=False)
29
32
  kernel_group.add_argument("--kernel-from-name", action="store", help="Use an existing kernel by name (e.g. 6.8.0-40-lowlatency)")
33
+ kernel_group.add_argument("--kernel-from-fedora", action="store_true", help="Use fedora's kernel")
30
34
  kernel_group.add_argument("--kernel-from-ubuntu", action="store_true", help="Use ubuntu's kernel")
31
35
  kernel_group.add_argument("--kernel-from-debian", action="store_true", help="Use debian's kernel")
32
36
  kernel_group.add_argument("--kernel-from-source", action="store_true", help="Build kernel from upstream source")
@@ -1,5 +1,6 @@
1
1
  import os
2
2
  import json
3
+ import shlex
3
4
  import hashlib
4
5
  import subprocess
5
6
 
@@ -10,15 +11,19 @@ from typing import Optional
10
11
  import jinja2
11
12
 
12
13
  # Get internal defaults
13
- INTERNAL_KERNEL_URL = os.environ.get("BOOTOCI_KERNEL_URL", "https://cdn.kernel.org/pub/linux/kernel/v6.x/linux-6.12.77.tar.xz")
14
- INTERNAL_UBUNTU_IMAGE = os.environ.get("BOOTOCI_UBUNTU_IMAGE", "docker.io/library/ubuntu:24.04")
14
+ INTERNAL_KERNEL_URL = os.environ.get("BOOTOCI_KERNEL_URL", "https://cdn.kernel.org/pub/linux/kernel/v7.x/linux-7.2.13.tar.xz")
15
+ INTERNAL_FEDORA_IMAGE = os.environ.get("BOOTOCI_FEDORA_IMAGE", "docker.io/library/fedora:44")
16
+ INTERNAL_UBUNTU_IMAGE = os.environ.get("BOOTOCI_UBUNTU_IMAGE", "docker.io/library/ubuntu:26.04")
15
17
  INTERNAL_DEBIAN_IMAGE = os.environ.get("BOOTOCI_DEBIAN_IMAGE", "docker.io/library/debian:13-slim")
16
- INTERNAL_BUSYBOX_IMAGE = os.environ.get("BOOTOCI_BUSYBOX_IMAGE", "docker.io/library/busybox:1.37.0-musl")
18
+ INTERNAL_BUSYBOX_IMAGE = os.environ.get("BOOTOCI_BUSYBOX_IMAGE", "docker.io/library/busybox:1.38.0-musl")
17
19
 
18
20
 
19
21
  def oci_to_bootable(
20
22
  *,
21
23
 
24
+ # Disable usage of caches
25
+ no_cache: bool = False,
26
+
22
27
  # Output file path
23
28
  output_filepath: str,
24
29
 
@@ -67,6 +72,9 @@ def oci_to_bootable(
67
72
  # Are we using a specific kernel that is already installed?
68
73
  kernel_from_name: Optional[str] = None,
69
74
 
75
+ # Are we using a kernel from fedora?
76
+ kernel_from_fedora: bool = False,
77
+
70
78
  # Are we using a kernel from ubuntu?
71
79
  kernel_from_ubuntu: bool = False,
72
80
 
@@ -87,6 +95,7 @@ def oci_to_bootable(
87
95
 
88
96
  # Internal options
89
97
  internal_kernel_url: str = INTERNAL_KERNEL_URL,
98
+ internal_fedora_image: str = INTERNAL_FEDORA_IMAGE,
90
99
  internal_ubuntu_image: str = INTERNAL_UBUNTU_IMAGE,
91
100
  internal_debian_image: str = INTERNAL_DEBIAN_IMAGE,
92
101
  internal_busybox_image: str = INTERNAL_BUSYBOX_IMAGE,
@@ -102,6 +111,13 @@ def oci_to_bootable(
102
111
  # We are using podman as our backend
103
112
  backend = ["podman"]
104
113
 
114
+ # Cache options for image build
115
+ cache = []
116
+
117
+ if no_cache:
118
+ # We don't want to use the cache
119
+ cache = ["--no-cache"]
120
+
105
121
  # Let's build the base image
106
122
  if rootfs_from_dockerfile:
107
123
  # Generate tag if required
@@ -109,7 +125,7 @@ def oci_to_bootable(
109
125
  rootfs_from_tag = "rootfs-" + hashlib.md5(rootfs_from_dockerfile.encode("utf-8", errors="ignore")).hexdigest()
110
126
 
111
127
  # Build the dockerfile
112
- subprocess.run(backend + ["buildx", "build", "--file", rootfs_from_dockerfile, "--tag", rootfs_from_tag, os.path.dirname(rootfs_from_dockerfile)], check=True)
128
+ subprocess.run(backend + ["buildx", "build", "--file", rootfs_from_dockerfile, "--tag", rootfs_from_tag] + cache + [os.path.dirname(rootfs_from_dockerfile)], check=True)
113
129
  else:
114
130
  # Check whether the image exists
115
131
  if not subprocess.run(backend + ["image", "ls", "--quiet", rootfs_from_tag], capture_output=True, check=True).stdout:
@@ -119,9 +135,15 @@ def oci_to_bootable(
119
135
  # We need to extract the rootfs information from the tag
120
136
  rootfs_configuration = json.loads(subprocess.run(backend + ["inspect", "--format", "{{json .Config}}", rootfs_from_tag], capture_output=True, text=True, check=True).stdout)
121
137
 
138
+ # Create jinja2 environment
139
+ environment = jinja2.Environment()
140
+
141
+ # Add the shlex quote filter
142
+ environment.filters["shlex"] = shlex.quote
143
+
122
144
  # Create jinja2 template
123
145
  with open(os.path.join(os.path.dirname(__file__), "templates", "Dockerfile"), "r", encoding="utf-8") as dockerfile:
124
- template = jinja2.Environment().from_string(dockerfile.read())
146
+ template = environment.from_string(dockerfile.read())
125
147
 
126
148
  # Render the template
127
149
  rendered_template = template.render(
@@ -140,6 +162,7 @@ def oci_to_bootable(
140
162
 
141
163
  # Kernel source selection
142
164
  kernel_from_name=kernel_from_name,
165
+ kernel_from_fedora=kernel_from_fedora,
143
166
  kernel_from_ubuntu=kernel_from_ubuntu,
144
167
  kernel_from_debian=kernel_from_debian,
145
168
  kernel_from_source=kernel_from_source,
@@ -166,6 +189,7 @@ def oci_to_bootable(
166
189
 
167
190
  # Internal options
168
191
  internal_kernel_url=internal_kernel_url,
192
+ internal_fedora_image=internal_fedora_image,
169
193
  internal_ubuntu_image=internal_ubuntu_image,
170
194
  internal_debian_image=internal_debian_image,
171
195
  internal_busybox_image=internal_busybox_image,
@@ -181,4 +205,4 @@ def oci_to_bootable(
181
205
  return
182
206
 
183
207
  # Now let's build the image
184
- subprocess.run(backend + ["buildx", "build", "--file", "-", "--target", "output", "--output", os.path.abspath(os.path.dirname(output_filepath)), "."], input=rendered_template, check=True, text=True)
208
+ subprocess.run(backend + ["buildx", "build", "--file", "-", "--target", "output", "--output", os.path.abspath(os.path.dirname(output_filepath))] + cache + ["."], input=rendered_template, check=True, text=True)
@@ -62,6 +62,7 @@ RUN <<'EOF'
62
62
  # Exit on failure
63
63
  set -e
64
64
 
65
+ # Install kernel
65
66
  apt --option='Acquire::Check-Valid-Until=false' update
66
67
  apt install --yes linux-image-amd64 --no-install-suggests --no-install-recommends
67
68
  rm -r /var/lib/apt/lists
@@ -76,12 +77,33 @@ RUN <<'EOF'
76
77
  # Exit on failure
77
78
  set -e
78
79
 
80
+ # Install kernel
79
81
  apt --option='Acquire::Check-Valid-Until=false' update
80
82
  apt install --yes linux-image-generic --no-install-suggests --no-install-recommends
81
83
  rm -r /var/lib/apt/lists
82
84
  EOF
83
85
  {% endif %}
84
86
 
87
+ {% if kernel_from_fedora %}
88
+ FROM {{internal_fedora_image}} AS kernel-from-fedora
89
+
90
+ # Download the latest linux image
91
+ RUN <<'EOF'
92
+ # Exit on failure
93
+ set -e
94
+
95
+ # Install kernel
96
+ dnf install -y --setopt=install_weak_deps=False kernel
97
+ dnf clean all
98
+
99
+ # Decide kernel name
100
+ kernel_name="$(basename -a /lib/modules/* | sort | tail -1)"
101
+
102
+ # Move kernel image
103
+ mv "/lib/modules/${kernel_name}/vmlinuz" "/boot/vmlinuz-${kernel_name}"
104
+ EOF
105
+ {% endif %}
106
+
85
107
  # Actually generate the rootfs
86
108
  FROM {{rootfs_from_tag}} AS rootfs
87
109
 
@@ -106,6 +128,12 @@ COPY --from=kernel-from-ubuntu /boot /boot
106
128
  COPY --from=kernel-from-ubuntu /lib/modules /lib/modules
107
129
  {% endif %}
108
130
 
131
+ {% if kernel_from_fedora %}
132
+ # Install kernel artifacts from fetch stage
133
+ COPY --from=kernel-from-fedora /boot /boot
134
+ COPY --from=kernel-from-fedora /lib/modules /lib/modules
135
+ {% endif %}
136
+
109
137
  {% if rootfs_password %}
110
138
  {% for password in rootfs_password %}
111
139
  # Use busybox from external image to change password
@@ -156,7 +184,7 @@ EOF
156
184
 
157
185
  {% if init_is_entrypoint %}
158
186
  # Create workdir marker for entrypoint
159
- RUN /bootoci/busybox ln -s $(/bootoci/busybox pwd) /bootoci/workdir
187
+ RUN /bootoci/busybox ln -s "$(/bootoci/busybox pwd)" /bootoci/workdir
160
188
 
161
189
  # Delete original /sbin/init file
162
190
  RUN /bootoci/busybox rm -f /sbin/init
@@ -171,11 +199,13 @@ set -e
171
199
  # Enter original working directory
172
200
  cd -P /bootoci/workdir
173
201
 
202
+ {% if Env %}
174
203
  # Add environment variables
175
- export {{Env | join(" ")}}
204
+ export {{Env | map("shlex") | join(" ")}}
205
+ {% endif %}
176
206
 
177
207
  # Execute entrypoint with cmd
178
- {{Entrypoint | join(" ")}} {{Cmd | join(" ")}}
208
+ exec {{((Entrypoint or []) + (Cmd or [])) | map("shlex") | join(" ")}}
179
209
  EOF
180
210
  {% endif %}
181
211
 
@@ -256,7 +286,7 @@ RUN --mount=type=bind,from=rootfs,source=/,destination=/rootfs <<'EOF'
256
286
  set -e
257
287
 
258
288
  # Decide kernel name
259
- kernel_name=$(basename -a /rootfs/lib/modules/{{kernel_from_name or '*'}} | sort | tail -1)
289
+ kernel_name="$(basename -a /rootfs/lib/modules/{{kernel_from_name or '*'}} | sort | tail -1)"
260
290
 
261
291
  # Copy kernel into EFI partition
262
292
  mcopy -i efi "/rootfs/boot/vmlinuz-${kernel_name}" ::/boot/vmlinuz
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bootoci
3
- Version: 0.3.0
3
+ Version: 0.4.0
4
4
  Summary: Convert OCI images to bootable disk images
5
5
  Maintainer-email: Nadav Tasher <hey@nadav.app>
6
6
  License-Expression: MIT
@@ -80,6 +80,9 @@ bootoci -o ./bin/disk.img --docker --kernel-from-debian --tag postgres --dockerf
80
80
  ```bash
81
81
  # Build a fully-fledged ubuntu desktop machine
82
82
  python3 -m src.bootoci.cli --docker --kernel-from-debian -f ./examples/ubuntu-desktop.Dockerfile --size 4096 --serial --password "root:12345678" --password "user:12345678"
83
+
84
+ # Build a test image
85
+ python3 -m src.bootoci.cli --docker --kernel-from-debian -f ./examples/entrypoint.Dockerfile --size 1024 --password "root:12345678" --entrypoint
83
86
  ```
84
87
 
85
88
  ## Testing images
File without changes
File without changes