Skip to content

Commit

Permalink
fix: Fix build script context paths (#565)
Browse files Browse the repository at this point in the history
Signed-off-by: Ashok Pon Kumar <[email protected]>
Co-authored-by: Akash Nayak <[email protected]>
  • Loading branch information
ashokponkumar and Akash-Nayak authored Jul 19, 2021
1 parent f5eefee commit e4253ff
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@

{{range $buildscript := . }}
pushd {{ $buildscript.PathWindows }}
{{ $buildscript.BuildScriptName }}
{{ $buildscript.BuildScript }}
popd
{{end}}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@

{{range $buildscript := . }}
cd {{ $buildscript.PathUnix }}
./{{ $buildscript.BuildScriptName }}
./{{ $buildscript.BuildScript }}
cd -
{{end}}
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ type ContainerImagesBuildScript struct {

// ImageBuildTemplateConfig represents template config used by ImagePush script
type ImageBuildTemplateConfig struct {
BuildScriptName string
PathUnix string
PathWindows string
BuildScript string
PathUnix string
PathWindows string
}

// Init Initializes the transformer
Expand Down Expand Up @@ -69,27 +69,43 @@ func (t *ContainerImagesBuildScript) Transform(newArtifacts []transformertypes.A
for _, a := range newArtifacts {
if a.Artifact == artifacts.ContainerImageBuildScriptArtifactType {
for _, shScript := range a.Paths[artifacts.ContainerImageBuildShScriptPathType] {
relPath, err := filepath.Rel(t.Env.GetEnvironmentOutput(), filepath.Dir(shScript))
contextPath := filepath.Dir(shScript)
if ctxPath, ok := a.Paths[artifacts.ContainerImageBuildShScriptContextPathType]; ok {
contextPath = ctxPath[0]
}
relPath, err := filepath.Rel(t.Env.GetEnvironmentOutput(), contextPath)
if err != nil {
logrus.Errorf("Unable to make path relative : %s", err)
continue
}
scriptPath, err := filepath.Rel(contextPath, shScript)
if err != nil {
logrus.Errorf("Unable to make path relative : %s", err)
continue
}
shScripts = append(shScripts, ImageBuildTemplateConfig{
BuildScriptName: filepath.Base(shScript),
PathUnix: common.GetUnixPath(relPath),
PathWindows: common.GetWindowsPath(relPath),
BuildScript: scriptPath,
PathUnix: common.GetUnixPath(relPath),
})
}
for _, batScript := range a.Paths[artifacts.ContainerImageBuildBatScriptPathType] {
relPath, err := filepath.Rel(t.Env.GetEnvironmentOutput(), filepath.Dir(batScript))
contextPath := filepath.Dir(batScript)
if ctxPath, ok := a.Paths[artifacts.ContainerImageBuildShScriptContextPathType]; ok {
contextPath = ctxPath[0]
}
relPath, err := filepath.Rel(t.Env.GetEnvironmentOutput(), contextPath)
if err != nil {
logrus.Errorf("Unable to make path relative : %s", err)
continue
}
scriptPath, err := filepath.Rel(contextPath, batScript)
if err != nil {
logrus.Errorf("Unable to make path relative : %s", err)
continue
}
batScripts = append(batScripts, ImageBuildTemplateConfig{
BuildScriptName: filepath.Base(batScript),
PathUnix: common.GetUnixPath(relPath),
PathWindows: common.GetWindowsPath(relPath),
BuildScript: scriptPath,
PathWindows: common.GetWindowsPath(relPath),
})
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ func (t *DockerfileImageBuildScript) Transform(newArtifacts []transformertypes.A
Name: artifacts.ContainerImageBuildScriptArtifactType,
Artifact: artifacts.ContainerImageBuildScriptArtifactType,
Paths: map[string][]string{artifacts.ContainerImageBuildShScriptPathType: {filepath.Join(common.ScriptsDir, "builddockerimages.sh")},
artifacts.ContainerImageBuildBatScriptPathType: {filepath.Join(common.ScriptsDir, "builddockerimages.bat")}},
artifacts.ContainerImageBuildShScriptContextPathType: {"."},
artifacts.ContainerImageBuildBatScriptPathType: {filepath.Join(common.ScriptsDir, "builddockerimages.bat")},
artifacts.ContainerImageBuildBatScriptContextPathType: {"."},
},
})
return pathMappings, nartifacts, nil
}
10 changes: 7 additions & 3 deletions types/transformer/artifacts/containerimagebuildscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@ import (
)

const (
// ContainerImageBuildScriptArtifactType represents the image push script artifact type
// ContainerImageBuildScriptArtifactType represents the image build script artifact type
ContainerImageBuildScriptArtifactType transformertypes.ArtifactType = "ContainerImageBuildScript"
)

const (
// ContainerImageBuildShScriptPathType represents the image push script path type
// ContainerImageBuildShScriptPathType represents the image build script path type
ContainerImageBuildShScriptPathType transformertypes.PathType = "ContainerImageBuildShScript"
// ContainerImageBuildBatScriptPathType represents the image push script path type
// ContainerImageBuildBatScriptPathType represents the image build script path type
ContainerImageBuildBatScriptPathType transformertypes.PathType = "ContainerImageBuildBatScript"
// ContainerImageBuildShScriptContextPathType represents the image build script path type
ContainerImageBuildShScriptContextPathType transformertypes.PathType = "ContainerImageBuildShScriptContextScript"
// ContainerImageBuildBatScriptContextPathType represents the image build script path type
ContainerImageBuildBatScriptContextPathType transformertypes.PathType = "ContainerImageBuildBatScriptContextScript"
)

0 comments on commit e4253ff

Please sign in to comment.