/
add.go
45 lines (36 loc) · 1.08 KB
/
add.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package instruction
import (
"context"
"fmt"
"github.com/moby/buildkit/frontend/dockerfile/instructions"
"github.com/werf/werf/pkg/buildah"
"github.com/werf/werf/pkg/container_backend"
)
type Add struct {
instructions.AddCommand
}
func NewAdd(i instructions.AddCommand) *Add {
return &Add{AddCommand: i}
}
func (i *Add) UsesBuildContext() bool {
return true
}
func (i *Add) Apply(ctx context.Context, containerName string, drv buildah.Buildah, drvOpts buildah.CommonOpts, buildContextArchive container_backend.BuildContextArchiver) error {
var contextDir string
if i.UsesBuildContext() {
var err error
contextDir, err = buildContextArchive.ExtractOrGetExtractedDir(ctx)
if err != nil {
return fmt.Errorf("unable to extract build context: %w", err)
}
}
if err := drv.Add(ctx, containerName, i.Sources(), i.Dest(), buildah.AddOpts{
CommonOpts: drvOpts,
ContextDir: contextDir,
Chown: i.Chown,
Chmod: i.Chmod,
}); err != nil {
return fmt.Errorf("error adding %v to %s for container %s: %w", i.Sources(), i.Dest(), containerName, err)
}
return nil
}