Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(staged-dockerfile): basic support of all dockerfile stages at co…
…nveyor level Signed-off-by: Timofey Kirillov <timofey.kirillov@flant.com>
- Loading branch information
1 parent
f5f200e
commit 306ed6c
Showing
18 changed files
with
559 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package instruction | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/werf/werf/pkg/build/stage" | ||
"github.com/werf/werf/pkg/config" | ||
"github.com/werf/werf/pkg/container_backend" | ||
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/util" | ||
) | ||
|
||
type Add struct { | ||
*Base[*dockerfile_instruction.Add] | ||
} | ||
|
||
func NewAdd(name stage.StageName, i *dockerfile.DockerfileStageInstruction[*dockerfile_instruction.Add], dependencies []*config.Dependency, hasPrevStage bool, opts *stage.BaseStageOptions) *Add { | ||
return &Add{Base: NewBase(name, i, dependencies, hasPrevStage, opts)} | ||
} | ||
|
||
func (stage *Add) GetDependencies(ctx context.Context, c stage.Conveyor, cb container_backend.ContainerBackend, prevImage, prevBuiltImage *stage.StageImage, buildContextArchive container_backend.BuildContextArchiver) (string, error) { | ||
var args []string | ||
args = append(args, stage.instruction.Data.Name()) | ||
args = append(args, stage.instruction.Data.Src...) | ||
args = append(args, stage.instruction.Data.Dst) | ||
args = append(args, stage.instruction.Data.Chown) | ||
args = append(args, stage.instruction.Data.Chmod) | ||
return util.Sha256Hash(args...), nil | ||
} | ||
|
||
func (stage *Add) PrepareImage(ctx context.Context, c stage.Conveyor, cb container_backend.ContainerBackend, prevBuiltImage, stageImage *stage.StageImage, buildContextArchive container_backend.BuildContextArchiver) error { | ||
return stage.Base.prepareInstruction(ctx, stageImage, buildContextArchive, backend_instruction.NewAdd(*stage.instruction.Data)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package instruction | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/werf/werf/pkg/build/stage" | ||
"github.com/werf/werf/pkg/config" | ||
"github.com/werf/werf/pkg/container_backend" | ||
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/util" | ||
) | ||
|
||
type Cmd struct { | ||
*Base[*dockerfile_instruction.Cmd] | ||
} | ||
|
||
func NewCmd(name stage.StageName, i *dockerfile.DockerfileStageInstruction[*dockerfile_instruction.Cmd], dependencies []*config.Dependency, hasPrevStage bool, opts *stage.BaseStageOptions) *Cmd { | ||
return &Cmd{Base: NewBase(name, i, dependencies, hasPrevStage, opts)} | ||
} | ||
|
||
func (stage *Cmd) GetDependencies(ctx context.Context, c stage.Conveyor, cb container_backend.ContainerBackend, prevImage, prevBuiltImage *stage.StageImage, buildContextArchive container_backend.BuildContextArchiver) (string, error) { | ||
var args []string | ||
args = append(args, stage.instruction.Data.Name()) | ||
args = append(args, stage.instruction.Data.Cmd...) | ||
args = append(args, fmt.Sprintf("%v", stage.instruction.Data.PrependShell)) | ||
return util.Sha256Hash(args...), nil | ||
} | ||
|
||
func (stage *Cmd) PrepareImage(ctx context.Context, c stage.Conveyor, cb container_backend.ContainerBackend, prevBuiltImage, stageImage *stage.StageImage, buildContextArchive container_backend.BuildContextArchiver) error { | ||
return stage.Base.prepareInstruction(ctx, stageImage, buildContextArchive, backend_instruction.NewCmd(*stage.instruction.Data)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package instruction | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/werf/werf/pkg/build/stage" | ||
"github.com/werf/werf/pkg/config" | ||
"github.com/werf/werf/pkg/container_backend" | ||
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/util" | ||
) | ||
|
||
type Copy struct { | ||
*Base[*dockerfile_instruction.Copy] | ||
} | ||
|
||
func NewCopy(name stage.StageName, i *dockerfile.DockerfileStageInstruction[*dockerfile_instruction.Copy], dependencies []*config.Dependency, hasPrevStage bool, opts *stage.BaseStageOptions) *Copy { | ||
return &Copy{Base: NewBase(name, i, dependencies, hasPrevStage, opts)} | ||
} | ||
|
||
func (stage *Copy) GetDependencies(ctx context.Context, c stage.Conveyor, cb container_backend.ContainerBackend, prevImage, prevBuiltImage *stage.StageImage, buildContextArchive container_backend.BuildContextArchiver) (string, error) { | ||
var args []string | ||
args = append(args, stage.instruction.Data.Name()) | ||
args = append(args, stage.instruction.Data.From) | ||
args = append(args, stage.instruction.Data.Src...) | ||
args = append(args, stage.instruction.Data.Dst) | ||
args = append(args, stage.instruction.Data.Chown) | ||
args = append(args, stage.instruction.Data.Chmod) | ||
return util.Sha256Hash(args...), nil | ||
} | ||
|
||
func (stage *Copy) PrepareImage(ctx context.Context, c stage.Conveyor, cb container_backend.ContainerBackend, prevBuiltImage, stageImage *stage.StageImage, buildContextArchive container_backend.BuildContextArchiver) error { | ||
return stage.Base.prepareInstruction(ctx, stageImage, buildContextArchive, backend_instruction.NewCopy(*stage.instruction.Data)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package instruction | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/werf/werf/pkg/build/stage" | ||
"github.com/werf/werf/pkg/config" | ||
"github.com/werf/werf/pkg/container_backend" | ||
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/util" | ||
) | ||
|
||
type Entrypoint struct { | ||
*Base[*dockerfile_instruction.Entrypoint] | ||
} | ||
|
||
func NewEntrypoint(name stage.StageName, i *dockerfile.DockerfileStageInstruction[*dockerfile_instruction.Entrypoint], dependencies []*config.Dependency, hasPrevStage bool, opts *stage.BaseStageOptions) *Entrypoint { | ||
return &Entrypoint{Base: NewBase(name, i, dependencies, hasPrevStage, opts)} | ||
} | ||
|
||
func (stage *Entrypoint) GetDependencies(ctx context.Context, c stage.Conveyor, cb container_backend.ContainerBackend, prevImage, prevBuiltImage *stage.StageImage, buildContextArchive container_backend.BuildContextArchiver) (string, error) { | ||
var args []string | ||
args = append(args, stage.instruction.Data.Name()) | ||
args = append(args, stage.instruction.Data.Entrypoint...) | ||
args = append(args, fmt.Sprintf("%v", stage.instruction.Data.PrependShell)) | ||
return util.Sha256Hash(args...), nil | ||
} | ||
|
||
func (stage *Entrypoint) PrepareImage(ctx context.Context, c stage.Conveyor, cb container_backend.ContainerBackend, prevBuiltImage, stageImage *stage.StageImage, buildContextArchive container_backend.BuildContextArchiver) error { | ||
return stage.Base.prepareInstruction(ctx, stageImage, buildContextArchive, backend_instruction.NewEntrypoint(*stage.instruction.Data)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package instruction | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/werf/werf/pkg/build/stage" | ||
"github.com/werf/werf/pkg/config" | ||
"github.com/werf/werf/pkg/container_backend" | ||
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/util" | ||
) | ||
|
||
type Env struct { | ||
*Base[*dockerfile_instruction.Env] | ||
} | ||
|
||
func NewEnv(name stage.StageName, i *dockerfile.DockerfileStageInstruction[*dockerfile_instruction.Env], dependencies []*config.Dependency, hasPrevStage bool, opts *stage.BaseStageOptions) *Env { | ||
return &Env{Base: NewBase(name, i, dependencies, hasPrevStage, opts)} | ||
} | ||
|
||
func (stage *Env) GetDependencies(ctx context.Context, c stage.Conveyor, cb container_backend.ContainerBackend, prevImage, prevBuiltImage *stage.StageImage, buildContextArchive container_backend.BuildContextArchiver) (string, error) { | ||
var args []string | ||
args = append(args, stage.instruction.Data.Name()) | ||
// FIXME(staged-dockerfile): sort envs | ||
for k, v := range stage.instruction.Data.Envs { | ||
args = append(args, k, v) | ||
} | ||
return util.Sha256Hash(args...), nil | ||
} | ||
|
||
func (stage *Env) PrepareImage(ctx context.Context, c stage.Conveyor, cb container_backend.ContainerBackend, prevBuiltImage, stageImage *stage.StageImage, buildContextArchive container_backend.BuildContextArchiver) error { | ||
return stage.Base.prepareInstruction(ctx, stageImage, buildContextArchive, backend_instruction.NewEnv(*stage.instruction.Data)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package instruction | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/werf/werf/pkg/build/stage" | ||
"github.com/werf/werf/pkg/config" | ||
"github.com/werf/werf/pkg/container_backend" | ||
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/util" | ||
) | ||
|
||
type Expose struct { | ||
*Base[*dockerfile_instruction.Expose] | ||
} | ||
|
||
func NewExpose(name stage.StageName, i *dockerfile.DockerfileStageInstruction[*dockerfile_instruction.Expose], dependencies []*config.Dependency, hasPrevStage bool, opts *stage.BaseStageOptions) *Expose { | ||
return &Expose{Base: NewBase(name, i, dependencies, hasPrevStage, opts)} | ||
} | ||
|
||
func (stage *Expose) GetDependencies(ctx context.Context, c stage.Conveyor, cb container_backend.ContainerBackend, prevImage, prevBuiltImage *stage.StageImage, buildContextArchive container_backend.BuildContextArchiver) (string, error) { | ||
var args []string | ||
args = append(args, stage.instruction.Data.Name()) | ||
args = append(args, stage.instruction.Data.Ports...) | ||
return util.Sha256Hash(args...), nil | ||
} | ||
|
||
func (stage *Expose) PrepareImage(ctx context.Context, c stage.Conveyor, cb container_backend.ContainerBackend, prevBuiltImage, stageImage *stage.StageImage, buildContextArchive container_backend.BuildContextArchiver) error { | ||
return stage.Base.prepareInstruction(ctx, stageImage, buildContextArchive, backend_instruction.NewExpose(*stage.instruction.Data)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package instruction | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/werf/werf/pkg/build/stage" | ||
"github.com/werf/werf/pkg/config" | ||
"github.com/werf/werf/pkg/container_backend" | ||
"github.com/werf/werf/pkg/dockerfile" | ||
dockerfile_instruction "github.com/werf/werf/pkg/dockerfile/instruction" | ||
"github.com/werf/werf/pkg/util" | ||
) | ||
|
||
type Healthcheck struct { | ||
*Base[*dockerfile_instruction.Healthcheck] | ||
} | ||
|
||
func NewHealthcheck(name stage.StageName, i *dockerfile.DockerfileStageInstruction[*dockerfile_instruction.Healthcheck], dependencies []*config.Dependency, hasPrevStage bool, opts *stage.BaseStageOptions) *Healthcheck { | ||
return &Healthcheck{Base: NewBase(name, i, dependencies, hasPrevStage, opts)} | ||
} | ||
|
||
func (stage *Healthcheck) GetDependencies(ctx context.Context, c stage.Conveyor, cb container_backend.ContainerBackend, prevImage, prevBuiltImage *stage.StageImage, buildContextArchive container_backend.BuildContextArchiver) (string, error) { | ||
var args []string | ||
args = append(args, stage.instruction.Data.Name()) | ||
args = append(args, string(stage.instruction.Data.Type)) | ||
args = append(args, stage.instruction.Data.Config.Test...) | ||
args = append(args, stage.instruction.Data.Config.Interval.String()) | ||
args = append(args, stage.instruction.Data.Config.Timeout.String()) | ||
args = append(args, stage.instruction.Data.Config.StartPeriod.String()) | ||
args = append(args, fmt.Sprintf("%d", stage.instruction.Data.Config.Retries)) | ||
return util.Sha256Hash(args...), nil | ||
} | ||
|
||
func (stage *Healthcheck) PrepareImage(ctx context.Context, c stage.Conveyor, cb container_backend.ContainerBackend, prevBuiltImage, stageImage *stage.StageImage, buildContextArchive container_backend.BuildContextArchiver) error { | ||
// FIXME(staged-dockerfile): construct backend instruction | ||
return stage.Base.prepareInstruction(ctx, stageImage, buildContextArchive, nil) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package instruction | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/werf/werf/pkg/build/stage" | ||
"github.com/werf/werf/pkg/config" | ||
"github.com/werf/werf/pkg/container_backend" | ||
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/util" | ||
) | ||
|
||
type Label struct { | ||
*Base[*dockerfile_instruction.Label] | ||
} | ||
|
||
func NewLabel(name stage.StageName, i *dockerfile.DockerfileStageInstruction[*dockerfile_instruction.Label], dependencies []*config.Dependency, hasPrevStage bool, opts *stage.BaseStageOptions) *Label { | ||
return &Label{Base: NewBase(name, i, dependencies, hasPrevStage, opts)} | ||
} | ||
|
||
func (stage *Label) GetDependencies(ctx context.Context, c stage.Conveyor, cb container_backend.ContainerBackend, prevImage, prevBuiltImage *stage.StageImage, buildContextArchive container_backend.BuildContextArchiver) (string, error) { | ||
var args []string | ||
args = append(args, stage.instruction.Data.Name()) | ||
// FIXME(staged-dockerfile): sort labels map | ||
for k, v := range stage.instruction.Data.Labels { | ||
args = append(args, k, v) | ||
} | ||
return util.Sha256Hash(args...), nil | ||
} | ||
|
||
func (stage *Label) PrepareImage(ctx context.Context, c stage.Conveyor, cb container_backend.ContainerBackend, prevBuiltImage, stageImage *stage.StageImage, buildContextArchive container_backend.BuildContextArchiver) error { | ||
return stage.Base.prepareInstruction(ctx, stageImage, buildContextArchive, backend_instruction.NewLabel(*stage.instruction.Data)) | ||
} |
Oops, something went wrong.