Merge pull request #23 from kairos-io/514-produce-loadable-tar

Always produce an importable tar from the image
This commit is contained in:
Dimitris Karakasilis 2023-01-09 17:10:06 +02:00 committed by GitHub
commit 724a8903fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 11 deletions

View File

@ -49,7 +49,8 @@ type OSArtifactSpec struct {
Bundles []string `json:"bundles,omitempty"`
PullOptions Pull `json:"pull,omitempty"`
OSRelease string `json:"osRelease,omitempty"`
PushOptions Push `json:"push,omitempty"`
// TODO: Currently not used. Reserved to be used when we have a way to push to registries.
PushOptions Push `json:"push,omitempty"`
}
type Push struct {

View File

@ -65,7 +65,17 @@ func unpackContainer(id, containerImage, pullImage string, pullOptions buildv1al
}
}
func createImageContainer(containerImage string, pushOptions buildv1alpha1.Push) v1.Container {
func pushImageName(artifact buildv1alpha1.OSArtifact) string {
pushName := artifact.Spec.PushOptions.ImageName
if pushName != "" {
return pushName
}
return artifact.Name
}
func createImageContainer(containerImage string, artifact buildv1alpha1.OSArtifact) v1.Container {
imageName := pushImageName(artifact)
return v1.Container{
ImagePullPolicy: v1.PullAlways,
Name: "create-image",
@ -73,8 +83,9 @@ func createImageContainer(containerImage string, pushOptions buildv1alpha1.Push)
Command: []string{"/bin/bash", "-cxe"},
Args: []string{
fmt.Sprintf(
"tar -czvpf test.tar -C /rootfs . && luet util pack %s test.tar image.tar && mv image.tar /artifacts",
pushOptions.ImageName,
"tar -czvpf test.tar -C /rootfs . && luet util pack %[1]s test.tar %[2]s.tar && chmod +r %[2]s.tar && mv %[2]s.tar /artifacts",
imageName,
artifact.Name,
),
},
VolumeMounts: []v1.VolumeMount{
@ -139,8 +150,6 @@ func osReleaseContainer(containerImage string) v1.Container {
func (r *OSArtifactReconciler) genJob(artifact buildv1alpha1.OSArtifact) *batchv1.Job {
objMeta := genObjectMeta(artifact)
pushImage := artifact.Spec.PushOptions.Push
privileged := false
serviceAccount := true
@ -326,11 +335,7 @@ func (r *OSArtifactReconciler) genJob(artifact buildv1alpha1.OSArtifact) *batchv
pod.InitContainers = append(pod.InitContainers, buildGCECloudImageContainer)
}
// TODO: Does it make sense to build the image and not push it? Maybe remove
// this flag?
if pushImage {
pod.InitContainers = append(pod.InitContainers, createImageContainer(r.ToolImage, artifact.Spec.PushOptions))
}
pod.InitContainers = append(pod.InitContainers, createImageContainer(r.ToolImage, artifact))
pod.Containers = []v1.Container{
createPushToServerImageContainer(r.CopierImage, r.ArtifactPodInfo),