Skip to content

Commit

Permalink
fix(docker/k8s): Fix image naming
Browse files Browse the repository at this point in the history
We had previously hack with hardcoding ghcr.io.
Now we make it more flexible, so people can set their own
image url, and our staging instance automatically add staging-
prefix in appropriate place.

Signed-off-by: Denys Fedoryshchenko <[email protected]>
  • Loading branch information
nuclearcat committed Oct 11, 2024
1 parent ed2c354 commit 87c89fd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
2 changes: 1 addition & 1 deletion config/runtime/base/kubernetes.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ spec:

containers:
- name: kernelci
image: ghcr.io/{{ runtime_image }}
image: {{ runtime_image }}
imagePullPolicy: Always

volumeMounts:
Expand Down
24 changes: 23 additions & 1 deletion kernelci/runtime/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,25 @@ def match(self, filter_data):
"""Apply filters and return True if they match, False otherwise."""
return self.config.match(filter_data)

def get_docker_name(self, param):

Check warning on line 126 in kernelci/runtime/__init__.py

View workflow job for this annotation

GitHub Actions / Lint

Method could be a function
"""Get the docker image name with the correct prefix"""
instance = os.getenv('KCI_INSTANCE', 'prod')
if instance != 'prod':
# if we dont have '/' in the image name, we add the ghcr.io/ prefix
if '/' not in param:
imageurl = f'ghcr.io/kernelci/staging-{param}'
else:
# we need split image name and path
prefix = param.rsplit('/', 1)[0]
imagename = param.rsplit('/', 1)[1]
imageurl = f'{prefix}/staging-{imagename}'
else:
if '/' not in param:
imageurl = f'ghcr.io/kernelci/{param}'
else:
imageurl = param
return imageurl

def get_params(self, job, api_config=None):
"""Get job template parameters"""
instanceid = os.environ.get('KCI_INSTANCE')
Expand All @@ -147,6 +166,9 @@ def get_params(self, job, api_config=None):
if not device_dtb:
print(f"dtb file {job.platform_config.dtb} not found!")
return None

imageurl = self.get_docker_name(job.config.params.get('image'))

params = {
'api_config': api_config or {},
'storage_config': job.storage_config or {},
Expand All @@ -156,7 +178,7 @@ def get_params(self, job, api_config=None):
'name': job.name,
'node': job.node,
'runtime': self.config.lab_type,
'runtime_image': job.config.image,
'runtime_image': imageurl,
}
if job.platform_config.params:
params.update(job.platform_config.params)
Expand Down

0 comments on commit 87c89fd

Please sign in to comment.