Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always produce an importable tar from the image #23

Merged
merged 3 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion api/v1alpha1/osartifact_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
19 changes: 9 additions & 10 deletions controllers/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,21 @@ func unpackContainer(id, containerImage, pullImage string, pullOptions buildv1al
}
}

func createImageContainer(containerImage string, pushOptions buildv1alpha1.Push) v1.Container {
func createImageContainer(containerImage string, artifact buildv1alpha1.OSArtifact) v1.Container {
imageName := "dontpush" // No image was defined, use a dummy one to let luet work
if artifact.Spec.PushOptions.ImageName != "" {
imageName = artifact.Spec.PushOptions.ImageName
}
return v1.Container{
ImagePullPolicy: v1.PullAlways,
Name: "create-image",
Image: containerImage,
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{
Expand Down Expand Up @@ -139,8 +144,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

Expand Down Expand Up @@ -326,11 +329,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),
Expand Down