Skip to content

Commit

Permalink
feat: add support for multiple adds like copy
Browse files Browse the repository at this point in the history
  • Loading branch information
lambdaclan committed Jun 25, 2024
1 parent 7b38954 commit f4cd7fa
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 21 deletions.
2 changes: 1 addition & 1 deletion api/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Stage struct {
Copy []Copy `json:"copy"`
Labels map[string]string `json:"labels"`
Env map[string]string `json:"env"`
Adds Add `json:"adds"`
Adds []Add `json:"adds"`
Args map[string]string `json:"args"`
Runs Run `json:"runs"`
Expose map[string]string `json:"expose"`
Expand Down
36 changes: 21 additions & 15 deletions core/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,21 +179,27 @@ func BuildContainerfile(recipe *api.Recipe) error {
}

// ADDS
if stage.Adds.Workdir != "" && stage.Adds.Workdir != recipe.Cwd {
_, err = containerfile.WriteString(
fmt.Sprintf("WORKDIR %s\n", stage.Adds.Workdir),
)
recipe.Cwd = stage.Adds.Workdir
if err != nil {
return err
}
}
for key, value := range stage.Adds.SrcDst {
_, err = containerfile.WriteString(
fmt.Sprintf("ADD %s %s\n", key, value),
)
if err != nil {
return err
if len(stage.Adds) > 0 {
for _, add := range stage.Adds {
if len(add.SrcDst) > 0 {
if add.Workdir != "" && add.Workdir != recipe.Cwd {
_, err = containerfile.WriteString(
fmt.Sprintf("WORKDIR %s\n", add.Workdir),
)
recipe.Cwd = add.Workdir
if err != nil {
return err
}
}
for key, value := range add.SrcDst {
_, err = containerfile.WriteString(
fmt.Sprintf("ADD %s %s\n", key, value),
)
if err != nil {
return err
}
}
}
}
}

Expand Down
12 changes: 7 additions & 5 deletions core/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,13 @@ func LoadRecipe(path string) (*api.Recipe, error) {

for i, stage := range recipe.Stages {
// here we check if the extra Adds path exists
for src := range stage.Adds.SrcDst {
fullPath := filepath.Join(filepath.Dir(recipePath), src)
_, err = os.Stat(fullPath)
if os.IsNotExist(err) {
return nil, err
for _, add := range stage.Adds {
for src := range add.SrcDst {
fullPath := filepath.Join(filepath.Dir(recipePath), src)
_, err = os.Stat(fullPath)
if os.IsNotExist(err) {
return nil, err
}
}
}

Expand Down

0 comments on commit f4cd7fa

Please sign in to comment.