diff --git a/pkg/build/build_phase.go b/pkg/build/build_phase.go index 3e45719dbd..bb0997ac63 100644 --- a/pkg/build/build_phase.go +++ b/pkg/build/build_phase.go @@ -23,6 +23,7 @@ import ( "github.com/werf/werf/pkg/container_backend" backend_instruction "github.com/werf/werf/pkg/container_backend/instruction" "github.com/werf/werf/pkg/docker_registry" + dockerfile_instruction "github.com/werf/werf/pkg/dockerfile/instruction" "github.com/werf/werf/pkg/git_repo" imagePkg "github.com/werf/werf/pkg/image" "github.com/werf/werf/pkg/stapel" @@ -677,7 +678,7 @@ func (phase *BuildPhase) prepareStageInstructions(ctx context.Context, img *imag return stageImage.Builder.DockerfileBuilder().Cleanup(ctx) }) } else { - stageImage.Builder.DockerfileStageBuilder().AppendPostInstruction(backend_instruction.NewLabel(serviceLabels)) + stageImage.Builder.DockerfileStageBuilder().AppendPostInstruction(backend_instruction.NewLabel(*dockerfile_instruction.NewLabel(serviceLabels))) } err := stg.PrepareImage(ctx, phase.Conveyor, phase.Conveyor.ContainerBackend, phase.StagesIterator.GetPrevBuiltImage(img, stg), stageImage) diff --git a/pkg/build/image/dockerfile.go b/pkg/build/image/dockerfile.go index 1e0e24e69f..0c4695fedb 100644 --- a/pkg/build/image/dockerfile.go +++ b/pkg/build/image/dockerfile.go @@ -16,6 +16,7 @@ import ( "github.com/werf/werf/pkg/config" backend_instruction "github.com/werf/werf/pkg/container_backend/instruction" "github.com/werf/werf/pkg/dockerfile" + dockerfile_instruction "github.com/werf/werf/pkg/dockerfile/instruction" "github.com/werf/werf/pkg/path_matcher" "github.com/werf/werf/pkg/util" ) @@ -82,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([]string{"ls", "/"}), nil, false, &stage.BaseStageOptions{ + img.stages = append(img.stages, stage_instruction.NewRun(backend_instruction.NewRun(*dockerfile_instruction.NewRun([]string{"ls", "/"})), nil, false, &stage.BaseStageOptions{ ImageName: img.Name, ImageTmpDir: img.TmpDir, ContainerWerfDir: img.ContainerWerfDir, diff --git a/pkg/container_backend/instruction/add.go b/pkg/container_backend/instruction/add.go index 07812176c9..14eb431ffd 100644 --- a/pkg/container_backend/instruction/add.go +++ b/pkg/container_backend/instruction/add.go @@ -6,25 +6,21 @@ import ( "github.com/werf/werf/pkg/buildah" "github.com/werf/werf/pkg/container_backend/build_context" + dockerfile_instruction "github.com/werf/werf/pkg/dockerfile/instruction" ) type Add struct { - Src []string - Dst string + dockerfile_instruction.Add } -func NewAdd(src []string, dst string) *Add { - return &Add{Src: src, Dst: dst} +func NewAdd(i dockerfile_instruction.Add) *Add { + return &Add{Add: i} } func (i *Add) UsesBuildContext() bool { return true } -func (i *Add) Name() string { - return "ADD" -} - func (i *Add) Apply(ctx context.Context, containerName string, drv buildah.Buildah, drvOpts buildah.CommonOpts, buildContext *build_context.BuildContext) error { contextDir, err := buildContext.GetContextDir(ctx) if err != nil { diff --git a/pkg/container_backend/instruction/cmd.go b/pkg/container_backend/instruction/cmd.go index cc8752b895..bfe096d873 100644 --- a/pkg/container_backend/instruction/cmd.go +++ b/pkg/container_backend/instruction/cmd.go @@ -6,26 +6,23 @@ import ( "github.com/werf/werf/pkg/buildah" "github.com/werf/werf/pkg/container_backend/build_context" + dockerfile_instruction "github.com/werf/werf/pkg/dockerfile/instruction" ) type Cmd struct { - Cmd []string + dockerfile_instruction.Cmd } -func NewCmd(cmd []string) *Cmd { - return &Cmd{Cmd: cmd} +func NewCmd(i dockerfile_instruction.Cmd) *Cmd { + return &Cmd{Cmd: i} } func (i *Cmd) UsesBuildContext() bool { return false } -func (i *Cmd) Name() string { - return "CMD" -} - func (i *Cmd) Apply(ctx context.Context, containerName string, drv buildah.Buildah, drvOpts buildah.CommonOpts, buildContext *build_context.BuildContext) error { - if err := drv.Config(ctx, containerName, buildah.ConfigOpts{CommonOpts: drvOpts, Cmd: i.Cmd}); err != nil { + if err := drv.Config(ctx, containerName, buildah.ConfigOpts{CommonOpts: drvOpts, Cmd: i.Cmd.Cmd}); err != nil { return fmt.Errorf("error setting cmd %v for container %s: %w", i.Cmd, containerName, err) } return nil diff --git a/pkg/container_backend/instruction/copy.go b/pkg/container_backend/instruction/copy.go index 145b7b9d4c..b6f6eabc9e 100644 --- a/pkg/container_backend/instruction/copy.go +++ b/pkg/container_backend/instruction/copy.go @@ -6,26 +6,21 @@ import ( "github.com/werf/werf/pkg/buildah" "github.com/werf/werf/pkg/container_backend/build_context" + dockerfile_instruction "github.com/werf/werf/pkg/dockerfile/instruction" ) type Copy struct { - From string - Src []string - Dst string + dockerfile_instruction.Copy } -func NewCopy(from string, src []string, dst string) *Copy { - return &Copy{From: from, Src: src, Dst: dst} +func NewCopy(i dockerfile_instruction.Copy) *Copy { + return &Copy{Copy: i} } func (i *Copy) UsesBuildContext() bool { return true } -func (i *Copy) Name() string { - return "COPY" -} - func (i *Copy) Apply(ctx context.Context, containerName string, drv buildah.Buildah, drvOpts buildah.CommonOpts, buildContext *build_context.BuildContext) error { contextDir, err := buildContext.GetContextDir(ctx) if err != nil { diff --git a/pkg/container_backend/instruction/entrypoint.go b/pkg/container_backend/instruction/entrypoint.go index 7fce77cec8..0e5e238534 100644 --- a/pkg/container_backend/instruction/entrypoint.go +++ b/pkg/container_backend/instruction/entrypoint.go @@ -6,26 +6,23 @@ import ( "github.com/werf/werf/pkg/buildah" "github.com/werf/werf/pkg/container_backend/build_context" + dockerfile_instruction "github.com/werf/werf/pkg/dockerfile/instruction" ) type Entrypoint struct { - Entrypoint []string + dockerfile_instruction.Entrypoint } -func NewEntrypoint(entrypoint []string) *Entrypoint { - return &Entrypoint{Entrypoint: entrypoint} +func NewEntrypoint(i dockerfile_instruction.Entrypoint) *Entrypoint { + return &Entrypoint{Entrypoint: i} } func (i *Entrypoint) UsesBuildContext() bool { return false } -func (i *Entrypoint) Name() string { - return "ENTRYPOINT" -} - func (i *Entrypoint) Apply(ctx context.Context, containerName string, drv buildah.Buildah, drvOpts buildah.CommonOpts, buildContext *build_context.BuildContext) error { - if err := drv.Config(ctx, containerName, buildah.ConfigOpts{CommonOpts: drvOpts, Entrypoint: i.Entrypoint}); err != nil { + if err := drv.Config(ctx, containerName, buildah.ConfigOpts{CommonOpts: drvOpts, Entrypoint: i.Entrypoint.Entrypoint}); err != nil { return fmt.Errorf("error setting entrypoint %v for container %s: %w", i.Entrypoint, containerName, err) } return nil diff --git a/pkg/container_backend/instruction/env.go b/pkg/container_backend/instruction/env.go index e4bd29ef60..ced5fda77f 100644 --- a/pkg/container_backend/instruction/env.go +++ b/pkg/container_backend/instruction/env.go @@ -6,24 +6,21 @@ import ( "github.com/werf/werf/pkg/buildah" "github.com/werf/werf/pkg/container_backend/build_context" + dockerfile_instruction "github.com/werf/werf/pkg/dockerfile/instruction" ) type Env struct { - Envs map[string]string + dockerfile_instruction.Env } -func NewEnv(envs map[string]string) *Env { - return &Env{Envs: envs} +func NewEnv(i dockerfile_instruction.Env) *Env { + return &Env{Env: i} } func (i *Env) UsesBuildContext() bool { return false } -func (i *Env) Name() string { - return "ENV" -} - func (i *Env) Apply(ctx context.Context, containerName string, drv buildah.Buildah, drvOpts buildah.CommonOpts, buildContext *build_context.BuildContext) error { if err := drv.Config(ctx, containerName, buildah.ConfigOpts{CommonOpts: drvOpts, Envs: i.Envs}); err != nil { return fmt.Errorf("error setting envs %v for container %s: %w", i.Envs, containerName, err) diff --git a/pkg/container_backend/instruction/expose.go b/pkg/container_backend/instruction/expose.go index 1cf52cc9f4..f35a8afdf3 100644 --- a/pkg/container_backend/instruction/expose.go +++ b/pkg/container_backend/instruction/expose.go @@ -6,29 +6,23 @@ import ( "github.com/werf/werf/pkg/buildah" "github.com/werf/werf/pkg/container_backend/build_context" + dockerfile_instruction "github.com/werf/werf/pkg/dockerfile/instruction" ) type Expose struct { - Ports []string + dockerfile_instruction.Expose } -func NewExpose(ports []string) *Expose { - return &Expose{Ports: ports} +func NewExpose(i dockerfile_instruction.Expose) *Expose { + return &Expose{Expose: i} } func (i *Expose) UsesBuildContext() bool { return false } -func (i *Expose) Name() string { - return "EXPOSE" -} - func (i *Expose) Apply(ctx context.Context, containerName string, drv buildah.Buildah, drvOpts buildah.CommonOpts, buildContext *build_context.BuildContext) error { - if err := drv.Config(ctx, containerName, buildah.ConfigOpts{ - CommonOpts: drvOpts, - Expose: i.Ports, - }); err != nil { + if err := drv.Config(ctx, containerName, buildah.ConfigOpts{CommonOpts: drvOpts, Expose: i.Ports}); err != nil { return fmt.Errorf("error setting exposed ports %v for container %s: %w", i.Ports, containerName, err) } return nil diff --git a/pkg/container_backend/instruction/healthcheck.go b/pkg/container_backend/instruction/healthcheck.go index d49794ed1c..b816543a30 100644 --- a/pkg/container_backend/instruction/healthcheck.go +++ b/pkg/container_backend/instruction/healthcheck.go @@ -1,8 +1,11 @@ package instruction +import ( + dockerfile_instruction "github.com/werf/werf/pkg/dockerfile/instruction" +) + type Healthcheck struct { - Type HealthcheckType - Command string + dockerfile_instruction.Healthcheck } type HealthcheckType string @@ -12,3 +15,5 @@ var ( HealthcheckTypeCmd HealthcheckType = "CMD" HealthcheckTypeCmdShell HealthcheckType = "CMD-SHELL" ) + +// TODO diff --git a/pkg/container_backend/instruction/label.go b/pkg/container_backend/instruction/label.go index 7cd617622f..697116a0f1 100644 --- a/pkg/container_backend/instruction/label.go +++ b/pkg/container_backend/instruction/label.go @@ -6,24 +6,21 @@ import ( "github.com/werf/werf/pkg/buildah" "github.com/werf/werf/pkg/container_backend/build_context" + dockerfile_instruction "github.com/werf/werf/pkg/dockerfile/instruction" ) type Label struct { - Labels map[string]string + dockerfile_instruction.Label } -func NewLabel(labels map[string]string) *Label { - return &Label{Labels: labels} +func NewLabel(i dockerfile_instruction.Label) *Label { + return &Label{Label: i} } func (i *Label) UsesBuildContext() bool { return false } -func (i *Label) Name() string { - return "LABEL" -} - func (i *Label) LabelsAsList() []string { var labels []string for k, v := range i.Labels { diff --git a/pkg/container_backend/instruction/on_build.go b/pkg/container_backend/instruction/on_build.go index d5d6c4852e..b10d7a732c 100644 --- a/pkg/container_backend/instruction/on_build.go +++ b/pkg/container_backend/instruction/on_build.go @@ -6,24 +6,21 @@ import ( "github.com/werf/werf/pkg/buildah" "github.com/werf/werf/pkg/container_backend/build_context" + dockerfile_instruction "github.com/werf/werf/pkg/dockerfile/instruction" ) type OnBuild struct { - Instruction string + dockerfile_instruction.OnBuild } -func NewOnBuild(instruction string) *OnBuild { - return &OnBuild{Instruction: instruction} +func NewOnBuild(i dockerfile_instruction.OnBuild) *OnBuild { + return &OnBuild{OnBuild: i} } func (i *OnBuild) UsesBuildContext() bool { return false } -func (i *OnBuild) Name() string { - return "ONBUILD" -} - func (i *OnBuild) Apply(ctx context.Context, containerName string, drv buildah.Buildah, drvOpts buildah.CommonOpts, buildContext *build_context.BuildContext) error { if err := drv.Config(ctx, containerName, buildah.ConfigOpts{CommonOpts: drvOpts, OnBuild: i.Instruction}); err != nil { return fmt.Errorf("error setting onbuild %v for container %s: %w", i.Instruction, containerName, err) diff --git a/pkg/container_backend/instruction/run.go b/pkg/container_backend/instruction/run.go index fa54e2d142..59832a1774 100644 --- a/pkg/container_backend/instruction/run.go +++ b/pkg/container_backend/instruction/run.go @@ -6,24 +6,21 @@ import ( "github.com/werf/werf/pkg/buildah" "github.com/werf/werf/pkg/container_backend/build_context" + dockerfile_instruction "github.com/werf/werf/pkg/dockerfile/instruction" ) type Run struct { - Command []string + dockerfile_instruction.Run } -func NewRun(command []string) *Run { - return &Run{Command: command} +func NewRun(i dockerfile_instruction.Run) *Run { + return &Run{Run: i} } func (i *Run) UsesBuildContext() bool { return false } -func (i *Run) Name() string { - return "RUN" -} - func (i *Run) Apply(ctx context.Context, containerName string, drv buildah.Buildah, drvOpts buildah.CommonOpts, buildContext *build_context.BuildContext) error { if err := drv.RunCommand(ctx, containerName, i.Command, buildah.RunCommandOpts{ // FIXME(ilya-lesikov): should we suppress or not? diff --git a/pkg/container_backend/instruction/shell.go b/pkg/container_backend/instruction/shell.go index e687e18495..839ee09d3d 100644 --- a/pkg/container_backend/instruction/shell.go +++ b/pkg/container_backend/instruction/shell.go @@ -6,26 +6,23 @@ import ( "github.com/werf/werf/pkg/buildah" "github.com/werf/werf/pkg/container_backend/build_context" + dockerfile_instruction "github.com/werf/werf/pkg/dockerfile/instruction" ) type Shell struct { - Shell []string + dockerfile_instruction.Shell } -func NewShell(shell []string) *Shell { - return &Shell{Shell: shell} +func NewShell(i dockerfile_instruction.Shell) *Shell { + return &Shell{Shell: i} } func (i *Shell) UsesBuildContext() bool { return false } -func (i *Shell) Name() string { - return "SHELL" -} - func (i *Shell) Apply(ctx context.Context, containerName string, drv buildah.Buildah, drvOpts buildah.CommonOpts, buildContext *build_context.BuildContext) error { - if err := drv.Config(ctx, containerName, buildah.ConfigOpts{CommonOpts: drvOpts, Shell: i.Shell}); err != nil { + if err := drv.Config(ctx, containerName, buildah.ConfigOpts{CommonOpts: drvOpts, Shell: i.Shell.Shell}); err != nil { return fmt.Errorf("error setting shell %v for container %s: %w", i.Shell, containerName, err) } return nil diff --git a/pkg/container_backend/instruction/stop_signal.go b/pkg/container_backend/instruction/stop_signal.go index 5ebbcb8b39..3e10f4bb59 100644 --- a/pkg/container_backend/instruction/stop_signal.go +++ b/pkg/container_backend/instruction/stop_signal.go @@ -6,24 +6,21 @@ import ( "github.com/werf/werf/pkg/buildah" "github.com/werf/werf/pkg/container_backend/build_context" + dockerfile_instruction "github.com/werf/werf/pkg/dockerfile/instruction" ) type StopSignal struct { - Signal string + dockerfile_instruction.StopSignal } -func NewStopSignal(signal string) *StopSignal { - return &StopSignal{Signal: signal} +func NewStopSignal(i dockerfile_instruction.StopSignal) *StopSignal { + return &StopSignal{StopSignal: i} } func (i *StopSignal) UsesBuildContext() bool { return false } -func (i *StopSignal) Name() string { - return "STOPSIGNAL" -} - func (i *StopSignal) Apply(ctx context.Context, containerName string, drv buildah.Buildah, drvOpts buildah.CommonOpts, buildContext *build_context.BuildContext) error { if err := drv.Config(ctx, containerName, buildah.ConfigOpts{CommonOpts: drvOpts, StopSignal: i.Signal}); err != nil { return fmt.Errorf("error setting stop signal %v for container %s: %w", i.Signal, containerName, err) diff --git a/pkg/container_backend/instruction/user.go b/pkg/container_backend/instruction/user.go index b227d05771..e5a3dcaeed 100644 --- a/pkg/container_backend/instruction/user.go +++ b/pkg/container_backend/instruction/user.go @@ -6,26 +6,23 @@ import ( "github.com/werf/werf/pkg/buildah" "github.com/werf/werf/pkg/container_backend/build_context" + dockerfile_instruction "github.com/werf/werf/pkg/dockerfile/instruction" ) type User struct { - User string + dockerfile_instruction.User } -func NewUser(user string) *User { - return &User{User: user} +func NewUser(i dockerfile_instruction.User) *User { + return &User{User: i} } func (i *User) UsesBuildContext() bool { return false } -func (i *User) Name() string { - return "USER" -} - func (i *User) Apply(ctx context.Context, containerName string, drv buildah.Buildah, drvOpts buildah.CommonOpts, buildContext *build_context.BuildContext) error { - if err := drv.Config(ctx, containerName, buildah.ConfigOpts{CommonOpts: drvOpts, User: i.User}); err != nil { + if err := drv.Config(ctx, containerName, buildah.ConfigOpts{CommonOpts: drvOpts, User: i.User.User}); err != nil { return fmt.Errorf("error setting user %s for container %s: %w", i.User, containerName, err) } return nil diff --git a/pkg/container_backend/instruction/volume.go b/pkg/container_backend/instruction/volume.go index d083cc71f6..7ee8b924f4 100644 --- a/pkg/container_backend/instruction/volume.go +++ b/pkg/container_backend/instruction/volume.go @@ -6,24 +6,21 @@ import ( "github.com/werf/werf/pkg/buildah" "github.com/werf/werf/pkg/container_backend/build_context" + dockerfile_instruction "github.com/werf/werf/pkg/dockerfile/instruction" ) type Volume struct { - Volumes []string + dockerfile_instruction.Volume } -func NewVolume(volumes []string) *Volume { - return &Volume{Volumes: volumes} +func NewVolume(i dockerfile_instruction.Volume) *Volume { + return &Volume{Volume: i} } func (i *Volume) UsesBuildContext() bool { return false } -func (i *Volume) Name() string { - return "VOLUME" -} - func (i *Volume) Apply(ctx context.Context, containerName string, drv buildah.Buildah, drvOpts buildah.CommonOpts, buildContext *build_context.BuildContext) error { if err := drv.Config(ctx, containerName, buildah.ConfigOpts{CommonOpts: drvOpts, Volumes: i.Volumes}); err != nil { return fmt.Errorf("error setting volumes %v for container %s: %w", i.Volumes, containerName, err) diff --git a/pkg/container_backend/instruction/workdir.go b/pkg/container_backend/instruction/workdir.go index 4d3657c7ae..580ae6f6bc 100644 --- a/pkg/container_backend/instruction/workdir.go +++ b/pkg/container_backend/instruction/workdir.go @@ -6,26 +6,23 @@ import ( "github.com/werf/werf/pkg/buildah" "github.com/werf/werf/pkg/container_backend/build_context" + dockerfile_instruction "github.com/werf/werf/pkg/dockerfile/instruction" ) type Workdir struct { - Workdir string + dockerfile_instruction.Workdir } -func NewWorkdir(workdir string) *Workdir { - return &Workdir{Workdir: workdir} +func NewWorkdir(i dockerfile_instruction.Workdir) *Workdir { + return &Workdir{Workdir: i} } func (i *Workdir) UsesBuildContext() bool { return false } -func (i *Workdir) Name() string { - return "WORKDIR" -} - func (i *Workdir) Apply(ctx context.Context, containerName string, drv buildah.Buildah, drvOpts buildah.CommonOpts, buildContext *build_context.BuildContext) error { - if err := drv.Config(ctx, containerName, buildah.ConfigOpts{CommonOpts: drvOpts, Workdir: i.Workdir}); err != nil { + if err := drv.Config(ctx, containerName, buildah.ConfigOpts{CommonOpts: drvOpts, Workdir: i.Workdir.Workdir}); err != nil { return fmt.Errorf("error setting workdir %s for container %s: %w", i.Workdir, containerName, err) } return nil diff --git a/pkg/dockerfile/dockerfile.go b/pkg/dockerfile/dockerfile.go index a99afa93e6..9e7f228b74 100644 --- a/pkg/dockerfile/dockerfile.go +++ b/pkg/dockerfile/dockerfile.go @@ -46,6 +46,7 @@ func newDockerfile(dockerStages []instructions.Stage, dockerMetaArgs []instructi dockerStages: dockerStages, dockerMetaArgs: dockerMetaArgs, dockerTargetStageIndex: dockerTargetStageIndex, + nameToIndex: GetDockerStagesNameToIndexMap(dockerStages), } } @@ -55,6 +56,7 @@ type Dockerfile struct { dockerStages []instructions.Stage dockerMetaArgs []instructions.ArgCommand dockerTargetStageIndex int + nameToIndex map[string]string } func (dockerfile *Dockerfile) GroupStagesByIndependentSets(ctx context.Context) ([][]*DockerfileStage, error) { diff --git a/pkg/dockerfile/dockerfile_stage.go b/pkg/dockerfile/dockerfile_stage.go index edaedcc818..e4019caf79 100644 --- a/pkg/dockerfile/dockerfile_stage.go +++ b/pkg/dockerfile/dockerfile_stage.go @@ -1,10 +1,25 @@ package dockerfile -func NewDockerfileStage() *DockerfileStage { - return &DockerfileStage{} +import "github.com/moby/buildkit/frontend/dockerfile/instructions" + +func NewDockerfileStage(dockerStage instructions.Stage) *DockerfileStage { + return &DockerfileStage{dockerStage: dockerStage} } type DockerfileStage struct { Dockerfile *Dockerfile DependenciesStages []*DockerfileStage + + dockerStage instructions.Stage +} + +func (stage *DockerfileStage) GetInstructions() []InstructionInterface { + // TODO(staged-dockerfile) + // for _, cmd := range stage.dockerStage.Commands { + // switch typedCmd := cmd.(type) { + // case *instructions.ArgCommand: + // } + // } + + return nil } diff --git a/pkg/dockerfile/helpers.go b/pkg/dockerfile/helpers.go index 7cdfcf9242..ad1b38ae5b 100644 --- a/pkg/dockerfile/helpers.go +++ b/pkg/dockerfile/helpers.go @@ -8,7 +8,7 @@ import ( "github.com/moby/buildkit/frontend/dockerfile/instructions" ) -func ResolveDockerStagesFromValue(stages []instructions.Stage) { +func GetDockerStagesNameToIndexMap(stages []instructions.Stage) map[string]string { nameToIndex := make(map[string]string) for i, s := range stages { name := strings.ToLower(s.Name) @@ -16,7 +16,14 @@ func ResolveDockerStagesFromValue(stages []instructions.Stage) { if name != index { nameToIndex[name] = index } + } + return nameToIndex +} + +func ResolveDockerStagesFromValue(stages []instructions.Stage) { + nameToIndex := GetDockerStagesNameToIndexMap(stages) + for _, s := range stages { for _, cmd := range s.Commands { switch typedCmd := cmd.(type) { case *instructions.CopyCommand: diff --git a/pkg/dockerfile/instruction.go b/pkg/dockerfile/instruction.go new file mode 100644 index 0000000000..6105e2ff7d --- /dev/null +++ b/pkg/dockerfile/instruction.go @@ -0,0 +1,5 @@ +package dockerfile + +type InstructionInterface interface { + Name() string +} diff --git a/pkg/dockerfile/instruction/add.go b/pkg/dockerfile/instruction/add.go new file mode 100644 index 0000000000..68a6dc3b84 --- /dev/null +++ b/pkg/dockerfile/instruction/add.go @@ -0,0 +1,14 @@ +package instruction + +type Add struct { + Src []string + Dst string +} + +func NewAdd(src []string, dst string) *Add { + return &Add{Src: src, Dst: dst} +} + +func (i *Add) Name() string { + return "ADD" +} diff --git a/pkg/dockerfile/instruction/cmd.go b/pkg/dockerfile/instruction/cmd.go new file mode 100644 index 0000000000..e78818c354 --- /dev/null +++ b/pkg/dockerfile/instruction/cmd.go @@ -0,0 +1,13 @@ +package instruction + +type Cmd struct { + Cmd []string +} + +func NewCmd(cmd []string) *Cmd { + return &Cmd{Cmd: cmd} +} + +func (i *Cmd) Name() string { + return "CMD" +} diff --git a/pkg/dockerfile/instruction/copy.go b/pkg/dockerfile/instruction/copy.go new file mode 100644 index 0000000000..fd7863f77d --- /dev/null +++ b/pkg/dockerfile/instruction/copy.go @@ -0,0 +1,15 @@ +package instruction + +type Copy struct { + From string + Src []string + Dst string +} + +func NewCopy(from string, src []string, dst string) *Copy { + return &Copy{From: from, Src: src, Dst: dst} +} + +func (i *Copy) Name() string { + return "COPY" +} diff --git a/pkg/dockerfile/instruction/entrypoint.go b/pkg/dockerfile/instruction/entrypoint.go new file mode 100644 index 0000000000..9744e056b9 --- /dev/null +++ b/pkg/dockerfile/instruction/entrypoint.go @@ -0,0 +1,13 @@ +package instruction + +type Entrypoint struct { + Entrypoint []string +} + +func NewEntrypoint(entrypoint []string) *Entrypoint { + return &Entrypoint{Entrypoint: entrypoint} +} + +func (i *Entrypoint) Name() string { + return "ENTRYPOINT" +} diff --git a/pkg/dockerfile/instruction/env.go b/pkg/dockerfile/instruction/env.go new file mode 100644 index 0000000000..ebd4daa819 --- /dev/null +++ b/pkg/dockerfile/instruction/env.go @@ -0,0 +1,13 @@ +package instruction + +type Env struct { + Envs map[string]string +} + +func NewEnv(envs map[string]string) *Env { + return &Env{Envs: envs} +} + +func (i *Env) Name() string { + return "ENV" +} diff --git a/pkg/dockerfile/instruction/expose.go b/pkg/dockerfile/instruction/expose.go new file mode 100644 index 0000000000..8d452eda08 --- /dev/null +++ b/pkg/dockerfile/instruction/expose.go @@ -0,0 +1,13 @@ +package instruction + +type Expose struct { + Ports []string +} + +func NewExpose(ports []string) *Expose { + return &Expose{Ports: ports} +} + +func (i *Expose) Name() string { + return "EXPOSE" +} diff --git a/pkg/dockerfile/instruction/healthcheck.go b/pkg/dockerfile/instruction/healthcheck.go new file mode 100644 index 0000000000..d49794ed1c --- /dev/null +++ b/pkg/dockerfile/instruction/healthcheck.go @@ -0,0 +1,14 @@ +package instruction + +type Healthcheck struct { + Type HealthcheckType + Command string +} + +type HealthcheckType string + +var ( + HealthcheckTypeNone HealthcheckType = "NONE" + HealthcheckTypeCmd HealthcheckType = "CMD" + HealthcheckTypeCmdShell HealthcheckType = "CMD-SHELL" +) diff --git a/pkg/dockerfile/instruction/label.go b/pkg/dockerfile/instruction/label.go new file mode 100644 index 0000000000..375fedfaa3 --- /dev/null +++ b/pkg/dockerfile/instruction/label.go @@ -0,0 +1,13 @@ +package instruction + +type Label struct { + Labels map[string]string +} + +func NewLabel(labels map[string]string) *Label { + return &Label{Labels: labels} +} + +func (i *Label) Name() string { + return "LABEL" +} diff --git a/pkg/dockerfile/instruction/on_build.go b/pkg/dockerfile/instruction/on_build.go new file mode 100644 index 0000000000..cf674938ca --- /dev/null +++ b/pkg/dockerfile/instruction/on_build.go @@ -0,0 +1,13 @@ +package instruction + +type OnBuild struct { + Instruction string +} + +func NewOnBuild(instruction string) *OnBuild { + return &OnBuild{Instruction: instruction} +} + +func (i *OnBuild) Name() string { + return "ONBUILD" +} diff --git a/pkg/dockerfile/instruction/run.go b/pkg/dockerfile/instruction/run.go new file mode 100644 index 0000000000..04b1ae09c8 --- /dev/null +++ b/pkg/dockerfile/instruction/run.go @@ -0,0 +1,13 @@ +package instruction + +type Run struct { + Command []string +} + +func NewRun(command []string) *Run { + return &Run{Command: command} +} + +func (i *Run) Name() string { + return "RUN" +} diff --git a/pkg/dockerfile/instruction/shell.go b/pkg/dockerfile/instruction/shell.go new file mode 100644 index 0000000000..4283120582 --- /dev/null +++ b/pkg/dockerfile/instruction/shell.go @@ -0,0 +1,13 @@ +package instruction + +type Shell struct { + Shell []string +} + +func NewShell(shell []string) *Shell { + return &Shell{Shell: shell} +} + +func (i *Shell) Name() string { + return "SHELL" +} diff --git a/pkg/dockerfile/instruction/stop_signal.go b/pkg/dockerfile/instruction/stop_signal.go new file mode 100644 index 0000000000..00c2dc40b6 --- /dev/null +++ b/pkg/dockerfile/instruction/stop_signal.go @@ -0,0 +1,13 @@ +package instruction + +type StopSignal struct { + Signal string +} + +func NewStopSignal(signal string) *StopSignal { + return &StopSignal{Signal: signal} +} + +func (i *StopSignal) Name() string { + return "STOPSIGNAL" +} diff --git a/pkg/dockerfile/instruction/user.go b/pkg/dockerfile/instruction/user.go new file mode 100644 index 0000000000..225dabf65b --- /dev/null +++ b/pkg/dockerfile/instruction/user.go @@ -0,0 +1,13 @@ +package instruction + +type User struct { + User string +} + +func NewUser(user string) *User { + return &User{User: user} +} + +func (i *User) Name() string { + return "USER" +} diff --git a/pkg/dockerfile/instruction/volume.go b/pkg/dockerfile/instruction/volume.go new file mode 100644 index 0000000000..ae20ef4d78 --- /dev/null +++ b/pkg/dockerfile/instruction/volume.go @@ -0,0 +1,13 @@ +package instruction + +type Volume struct { + Volumes []string +} + +func NewVolume(volumes []string) *Volume { + return &Volume{Volumes: volumes} +} + +func (i *Volume) Name() string { + return "VOLUME" +} diff --git a/pkg/dockerfile/instruction/workdir.go b/pkg/dockerfile/instruction/workdir.go new file mode 100644 index 0000000000..a6dfed494f --- /dev/null +++ b/pkg/dockerfile/instruction/workdir.go @@ -0,0 +1,13 @@ +package instruction + +type Workdir struct { + Workdir string +} + +func NewWorkdir(workdir string) *Workdir { + return &Workdir{Workdir: workdir} +} + +func (i *Workdir) Name() string { + return "WORKDIR" +}