Skip to content

Commit 5fe3f51

Browse files
committed
Add initial support to interact with a local podman installation
Signed-off-by: Tobias Wolf <wolf@b1-systems.de>
1 parent 2c7c395 commit 5fe3f51

File tree

9 files changed

+674
-81
lines changed

9 files changed

+674
-81
lines changed

poetry.lock

Lines changed: 112 additions & 63 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ packages = [{ include = "gardenlinux", from = "src" }]
1010
[tool.poetry.dependencies]
1111
python = "^3.13"
1212
apt-repo = "^0.5"
13-
boto3 = "^1.40.30"
13+
boto3 = "^1.40.43"
1414
click = "^8.2.1"
15-
cryptography = "^46.0.1"
15+
cryptography = "^46.0.2"
1616
jsonschema = "^4.25.1"
1717
networkx = "^3.5"
1818
oras = "^0.2.38"
19+
podman = "^5.6.0"
1920
pygit2 = "^1.18.2"
2021
pygments = "^2.19.2"
2122
PyYAML = "^6.0.2"
@@ -24,13 +25,13 @@ gitpython = "^3.1.45"
2425
[tool.poetry.group.dev.dependencies]
2526
bandit = "^1.8.6"
2627
black = "^25.1.0"
28+
isort = "^7.0.0"
2729
moto = "^5.1.12"
30+
pyright = "^1.1.406"
2831
python-dotenv = "^1.1.1"
2932
pytest = "^8.4.1"
3033
pytest-cov = "^7.0.0"
31-
isort = "^7.0.0"
3234
requests-mock = "^1.12.1"
33-
pyright = "^1.1.403"
3435

3536
[tool.poetry.group.docs.dependencies]
3637
sphinx-rtd-theme = "^3.0.2"

src/gardenlinux/constants.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,15 @@
159159

160160
S3_DOWNLOADS_DIR = Path(os.path.dirname(__file__)) / ".." / "s3_downloads"
161161

162+
GL_DEB_REPO_BASE_URL = "https://packages.gardenlinux.io/gardenlinux"
162163
GLVD_BASE_URL = (
163164
"https://glvd.ingress.glvd.gardnlinux.shoot.canary.k8s-hana.ondemand.com/v1"
164165
)
165-
GL_DEB_REPO_BASE_URL = "https://packages.gardenlinux.io/gardenlinux"
166166

167167
GARDENLINUX_GITHUB_RELEASE_BUCKET_NAME = "gardenlinux-github-releases"
168168

169+
PODMAN_CONNECTION_MAX_IDLE_SECONDS = 3
170+
169171
# https://github.com/gardenlinux/gardenlinux/issues/3044
170172
# Empty string is the 'legacy' variant with traditional root fs and still needed/supported
171173
IMAGE_VARIANTS = ["", "_usi", "_tpm2_trustedboot"]

src/gardenlinux/oci/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
from .index import Index
1010
from .layer import Layer
1111
from .manifest import Manifest
12+
from .podman import Podman
1213

13-
__all__ = ["Container", "ImageManifest", "Index", "Layer", "Manifest"]
14+
__all__ = ["Container", "ImageManifest", "Index", "Layer", "Manifest", "Podman"]

src/gardenlinux/oci/__main__.py

Lines changed: 92 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from pygments.lexer import default
1111

1212
from .container import Container
13+
from .podman import Podman
1314

1415

1516
@click.group()
@@ -27,41 +28,126 @@ def cli():
2728
@click.option(
2829
"--container",
2930
required=True,
31+
help="Container Name",
32+
)
33+
@click.option(
34+
"--tag",
35+
required=True,
36+
help="OCI tag of image",
37+
)
38+
@click.option(
39+
"--dir",
40+
"directory",
41+
required=True,
3042
type=click.Path(),
43+
help="Path to the build Containerfile",
44+
)
45+
@click.option(
46+
"--additional_tag",
47+
required=False,
48+
multiple=True,
49+
help="Additional tag to push the manifest with",
50+
)
51+
@click.option(
52+
"--build_arg",
53+
required=False,
54+
default=[],
55+
multiple=True,
56+
help="Additional build args for Containerfile",
57+
)
58+
def build_container(
59+
container,
60+
tag,
61+
directory,
62+
additional_tag,
63+
build_arg,
64+
):
65+
"""
66+
Build an OCI container based on the defined `Containerfile`.
67+
68+
:since: 0.11.0
69+
"""
70+
71+
podman = Podman()
72+
73+
image_id = podman.build(
74+
directory,
75+
oci_tag=f"{container}:{tag}",
76+
build_args=Podman.parse_build_args_list(build_arg),
77+
)
78+
79+
if additional_tag is not None:
80+
podman.tag_list(
81+
image_id, Podman.get_container_tag_list(container, additional_tag)
82+
)
83+
84+
print(image_id)
85+
86+
87+
@cli.command()
88+
@click.option(
89+
"--container",
90+
required=True,
3191
help="Container Name",
3292
)
3393
@click.option(
34-
"--cname", required=True, type=click.Path(), help="Canonical Name of Image"
94+
"--tag",
95+
required=False,
96+
help="OCI tag of image",
3597
)
98+
def push_container(
99+
container,
100+
tag,
101+
):
102+
"""
103+
Push to an OCI registry.
104+
105+
:since: 0.11.0
106+
"""
107+
108+
Podman().push(container, oci_tag=tag)
109+
110+
111+
@cli.command()
112+
@click.option(
113+
"--container",
114+
required=True,
115+
help="Container Name",
116+
)
117+
@click.option("--cname", required=True, help="Canonical Name of Image")
36118
@click.option(
37119
"--arch",
38120
required=False,
39-
type=click.Path(),
40121
default=None,
41122
help="Target Image CPU Architecture",
42123
)
43124
@click.option(
44125
"--version",
45126
required=False,
46-
type=click.Path(),
47127
default=None,
48128
help="Version of image",
49129
)
50130
@click.option(
51131
"--commit",
52132
required=False,
53-
type=click.Path(),
54133
default=None,
55134
help="Commit of image",
56135
)
57-
@click.option("--dir", "directory", required=True, help="path to the build artifacts")
136+
@click.option(
137+
"--dir",
138+
"directory",
139+
required=True,
140+
type=click.Path(),
141+
help="path to the build artifacts",
142+
)
58143
@click.option(
59144
"--cosign_file",
60145
required=False,
61146
help="A file where the pushed manifests digests is written to. The content can be used by an external tool (e.g. cosign) to sign the manifests contents",
62147
)
63148
@click.option(
64149
"--manifest_file",
150+
type=click.Path(),
65151
default="manifests/manifest.json",
66152
help="A file where the index entry for the pushed manifest is written to.",
67153
)
@@ -113,34 +199,29 @@ def push_manifest(
113199
@click.option(
114200
"--container",
115201
required=True,
116-
type=click.Path(),
117202
help="Container Name",
118203
)
119204
@click.option(
120205
"--cname",
121206
required=False,
122-
type=click.Path(),
123207
default=None,
124208
help="Canonical Name of Image",
125209
)
126210
@click.option(
127211
"--arch",
128212
required=False,
129-
type=click.Path(),
130213
default=None,
131214
help="Target Image CPU Architecture",
132215
)
133216
@click.option(
134217
"--version",
135218
required=False,
136-
type=click.Path(),
137219
default=None,
138220
help="Version of image",
139221
)
140222
@click.option(
141223
"--commit",
142224
required=False,
143-
type=click.Path(),
144225
default=None,
145226
help="Commit of image",
146227
)
@@ -184,18 +265,17 @@ def push_manifest_tags(
184265
"--container",
185266
"container",
186267
required=True,
187-
type=click.Path(),
188268
help="Container Name",
189269
)
190270
@click.option(
191271
"--version",
192272
"version",
193273
required=True,
194-
type=click.Path(),
195274
help="Version of image",
196275
)
197276
@click.option(
198277
"--manifest_folder",
278+
type=click.Path(),
199279
default="manifests",
200280
help="A folder where the index entries are read from.",
201281
)

0 commit comments

Comments
 (0)