Skip to content

Commit

Permalink
feat(staged-dockerfile): complete instructions set with all params in…
Browse files Browse the repository at this point in the history
… the dockerfile parser pkg

Signed-off-by: Timofey Kirillov <timofey.kirillov@flant.com>
  • Loading branch information
distorhead committed Oct 12, 2022
1 parent 9500967 commit 06f122b
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 21 deletions.
2 changes: 1 addition & 1 deletion pkg/build/image/dockerfile.go
Expand Up @@ -83,7 +83,7 @@ func mapDockerfileToImagesSets(ctx context.Context, cfg *dockerfile.Dockerfile,
return nil, fmt.Errorf("unable to create image %q: %w", "test", err)
}

img.stages = append(img.stages, stage_instruction.NewRun(backend_instruction.NewRun(*dockerfile_instruction.NewRun([]string{"ls", "/"})), nil, false, &stage.BaseStageOptions{
img.stages = append(img.stages, stage_instruction.NewRun(backend_instruction.NewRun(*dockerfile_instruction.NewRun([]string{"ls", "/"}, nil, nil, false)), nil, false, &stage.BaseStageOptions{
ImageName: img.Name,
ImageTmpDir: img.TmpDir,
ContainerWerfDir: img.ContainerWerfDir,
Expand Down
10 changes: 6 additions & 4 deletions pkg/dockerfile/instruction/add.go
@@ -1,12 +1,14 @@
package instruction

type Add struct {
Src []string
Dst string
Src []string
Dst string
Chown string
Chmod string
}

func NewAdd(src []string, dst string) *Add {
return &Add{Src: src, Dst: dst}
func NewAdd(src []string, dst, chown, chmod string) *Add {
return &Add{Src: src, Dst: dst, Chown: chown, Chmod: chmod}
}

func (i *Add) Name() string {
Expand Down
15 changes: 15 additions & 0 deletions pkg/dockerfile/instruction/arg.go
@@ -0,0 +1,15 @@
package instruction

import "github.com/moby/buildkit/frontend/dockerfile/instructions"

type Arg struct {
Args []instructions.KeyValuePairOptional
}

func NewArg(args []instructions.KeyValuePairOptional) *Arg {
return &Arg{Args: args}
}

func (i *Arg) Name() string {
return "ARG"
}
7 changes: 4 additions & 3 deletions pkg/dockerfile/instruction/cmd.go
@@ -1,11 +1,12 @@
package instruction

type Cmd struct {
Cmd []string
Cmd []string
PrependShell bool
}

func NewCmd(cmd []string) *Cmd {
return &Cmd{Cmd: cmd}
func NewCmd(cmd []string, prependShell bool) *Cmd {
return &Cmd{Cmd: cmd, PrependShell: prependShell}
}

func (i *Cmd) Name() string {
Expand Down
12 changes: 7 additions & 5 deletions pkg/dockerfile/instruction/copy.go
@@ -1,13 +1,15 @@
package instruction

type Copy struct {
From string
Src []string
Dst string
From string
Src []string
Dst string
Chown string
Chmod string
}

func NewCopy(from string, src []string, dst string) *Copy {
return &Copy{From: from, Src: src, Dst: dst}
func NewCopy(from string, src []string, dst, chown, chmod string) *Copy {
return &Copy{From: from, Src: src, Dst: dst, Chown: chown, Chmod: chmod}
}

func (i *Copy) Name() string {
Expand Down
7 changes: 4 additions & 3 deletions pkg/dockerfile/instruction/entrypoint.go
@@ -1,11 +1,12 @@
package instruction

type Entrypoint struct {
Entrypoint []string
Entrypoint []string
PrependShell bool
}

func NewEntrypoint(entrypoint []string) *Entrypoint {
return &Entrypoint{Entrypoint: entrypoint}
func NewEntrypoint(entrypoint []string, prependShell bool) *Entrypoint {
return &Entrypoint{Entrypoint: entrypoint, PrependShell: prependShell}
}

func (i *Entrypoint) Name() string {
Expand Down
14 changes: 12 additions & 2 deletions pkg/dockerfile/instruction/healthcheck.go
@@ -1,8 +1,10 @@
package instruction

import "github.com/docker/docker/api/types/container"

type Healthcheck struct {
Type HealthcheckType
Command string
Type HealthcheckType
Config *container.HealthConfig
}

type HealthcheckType string
Expand All @@ -12,3 +14,11 @@ var (
HealthcheckTypeCmd HealthcheckType = "CMD"
HealthcheckTypeCmdShell HealthcheckType = "CMD-SHELL"
)

func NewHealthcheck(t HealthcheckType, cfg *container.HealthConfig) *Healthcheck {
return &Healthcheck{Type: t, Config: cfg}
}

func (i *Healthcheck) Name() string {
return "HEALTHCHECK"
}
9 changes: 9 additions & 0 deletions pkg/dockerfile/instruction/maintainer.go
@@ -0,0 +1,9 @@
package instruction

type Maintainer struct {
Maintainer string
}

func (i *Maintainer) Name() string {
return "MAINTAINER"
}
11 changes: 8 additions & 3 deletions pkg/dockerfile/instruction/run.go
@@ -1,11 +1,16 @@
package instruction

import "github.com/opencontainers/runtime-spec/specs-go"

type Run struct {
Command []string
Command []string
Args []string // runtime args like --security and --network
Mounts []specs.Mount // structured --mount args
PrependShell bool
}

func NewRun(command []string) *Run {
return &Run{Command: command}
func NewRun(command, args []string, mounts []specs.Mount, prependShell bool) *Run {
return &Run{Command: command, Args: args, Mounts: mounts, PrependShell: prependShell}
}

func (i *Run) Name() string {
Expand Down

0 comments on commit 06f122b

Please sign in to comment.