-
Notifications
You must be signed in to change notification settings - Fork 202
/
env.go
35 lines (27 loc) · 871 Bytes
/
env.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
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 Env struct {
instructions.EnvCommand
}
func NewEnv(i instructions.EnvCommand) *Env {
return &Env{EnvCommand: i}
}
func (i *Env) UsesBuildContext() bool {
return false
}
func (i *Env) Apply(ctx context.Context, containerName string, drv buildah.Buildah, drvOpts buildah.CommonOpts, buildContextArchive container_backend.BuildContextArchiver) error {
envs := make(map[string]string)
for _, item := range i.Env {
envs[item.Key] = item.Value
}
if err := drv.Config(ctx, containerName, buildah.ConfigOpts{CommonOpts: drvOpts, Envs: envs}); err != nil {
return fmt.Errorf("error setting envs %v for container %s: %w", envs, containerName, err)
}
return nil
}