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

Revert changes to CloudStack output glob #2567

Merged
merged 1 commit into from
Oct 17, 2023
Merged
Changes from all 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
28 changes: 11 additions & 17 deletions projects/aws/image-builder/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func (b *BuildOptions) BuildImage() {

commandEnvVars = append(commandEnvVars, fmt.Sprintf("%s=%s", packerAdditionalFilesConfigFileEnvVar, additionalFilesConfigFile))
}
var outputImageGlobPattern string
if b.Hypervisor == VSphere {
// Set proxy on RHSM if available
if b.Os == RedHat && b.VsphereConfig.HttpProxy != "" {
Expand Down Expand Up @@ -128,11 +129,7 @@ func (b *BuildOptions) BuildImage() {
log.Fatalf("Error executing image-builder for vsphere hypervisor: %v", err)
}

// Move the output ova to cwd
outputImageGlob, err = filepath.Glob(filepath.Join(upstreamImageBuilderProjectPath, "output/*.ova"))
if err != nil {
log.Fatalf("Error getting glob for output files: %v", err)
}
outputImageGlobPattern = "output/*.ova"
outputArtifactPath = filepath.Join(cwd, fmt.Sprintf("%s.ova", b.Os))

log.Printf("Image Build Successful\n Please find the output artifact at %s\n", outputArtifactPath)
Expand Down Expand Up @@ -178,12 +175,10 @@ func (b *BuildOptions) BuildImage() {
log.Fatalf("Error executing image-builder for raw hypervisor: %v", err)
}

outputImageGlob, err = filepath.Glob(filepath.Join(upstreamImageBuilderProjectPath, "output/*.gz"))
if err != nil {
log.Fatalf("Error getting glob for output files: %v", err)
}

outputImageGlobPattern = "output/*.gz"
outputArtifactPath = filepath.Join(cwd, fmt.Sprintf("%s.gz", b.Os))

log.Printf("Image Build Successful\n Please find the output artifact at %s\n", outputArtifactPath)
} else if b.Hypervisor == Nutanix {
// Patch firmware config for tool
upstreamPatchCommand := fmt.Sprintf("make -C %s patch-repo", imageBuilderProjectPath)
Expand Down Expand Up @@ -233,10 +228,9 @@ func (b *BuildOptions) BuildImage() {
}

var buildCommand string
var outputImageGlobPattern string
switch b.Os {
case RedHat:
outputImageGlobPattern = "output/rhel-*"
outputImageGlobPattern = "output/rhel-*/rhel-*"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the fix, rest is just a minor refactor.

buildCommand = fmt.Sprintf("make -C %s local-build-cloudstack-redhat-%s", imageBuilderProjectPath, b.OsVersion)
commandEnvVars = append(commandEnvVars,
fmt.Sprintf("%s=%s", rhelUsernameEnvVar, b.CloudstackConfig.RhelUsername),
Expand All @@ -254,11 +248,6 @@ func (b *BuildOptions) BuildImage() {
log.Fatalf("Error executing image-builder for raw hypervisor: %v", err)
}

outputImageGlob, err = filepath.Glob(filepath.Join(upstreamImageBuilderProjectPath, outputImageGlobPattern))
if err != nil {
log.Fatalf("Error getting glob for output files: %v", err)
}

outputArtifactPath = filepath.Join(cwd, fmt.Sprintf("%s.qcow2", b.Os))

log.Printf("Image Build Successful\n Please find the output artifact at %s\n", outputArtifactPath)
Expand Down Expand Up @@ -293,6 +282,11 @@ func (b *BuildOptions) BuildImage() {
}

if outputArtifactPath != "" {
outputImageGlob, err = filepath.Glob(filepath.Join(upstreamImageBuilderProjectPath, outputImageGlobPattern))
if err != nil {
log.Fatalf("Error getting glob for output files: %v", err)
}

// Moving artifacts from upstream directory to cwd
log.Println("Moving artifacts from build directory to current working directory")
err = os.Rename(outputImageGlob[0], outputArtifactPath)
Expand Down