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

feat:[CI-15236]: Added IMAGE_TAR_PATH as output variable for the plugin. #132

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 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
14 changes: 13 additions & 1 deletion kaniko.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,14 +407,26 @@ func (p Plugin) Exec() error {
}

if p.Output.OutputFile != "" {
if err = output.WritePluginOutputFile(p.Output.OutputFile, getDigest(p.Build.DigestFile)); err != nil {
if err = output.WritePluginOutputFile(p.Output.OutputFile, getDigest(p.Build.DigestFile), getTarPath(p.Build.TarPath)); err != nil {
fmt.Fprintf(os.Stderr, "failed to write plugin output file at path: %s with error: %s\n", p.Output.OutputFile, err)
}
}

return nil
}

func getTarPath(tarPath string) string {
if tarPath == "" {
fmt.Fprintf(os.Stderr, "Warning: tar_path is empty\n")
return ""
}
if _, err := os.Stat(tarPath); err != nil && os.IsNotExist(err) {
fmt.Fprintf(os.Stderr, "Warning: tar path does not exist: %s\n", tarPath)
return ""
}
return tarPath
}

func getDigest(digestFile string) string {
content, err := ioutil.ReadFile(digestFile)
if err != nil {
Expand Down
17 changes: 14 additions & 3 deletions pkg/output/output.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
package output

import (
"fmt"
"github.com/joho/godotenv"
)

func WritePluginOutputFile(outputFilePath, digest string) error {
output := map[string]string{
"digest": digest,
func WritePluginOutputFile(outputFilePath, digest string, pluginTarPath string) error {
output := make(map[string]string)
if digest != "" {
output["digest"] = digest
}

if pluginTarPath != "" {
output["IMAGE_TAR_PATH"] = pluginTarPath
}

if len(output) == 0 {
return fmt.Errorf("no values to write to output file")
}
Anshika2203 marked this conversation as resolved.
Show resolved Hide resolved
Ompragash marked this conversation as resolved.
Show resolved Hide resolved

return godotenv.Write(output, outputFilePath)
}