Skip to content

Commit

Permalink
rename
Browse files Browse the repository at this point in the history
  • Loading branch information
dskiff committed Apr 25, 2024
1 parent e6b3f27 commit 4af5922
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 22 deletions.
4 changes: 2 additions & 2 deletions pkg/build/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/google/go-containerregistry/pkg/v1/remote"
)

func GetBaseImage(ctx RunCtx, baseRef string, platform Platform, keychain authn.Keychain) (v1.Image, error) {
func GetBaseImage(ctx BuildContext, baseRef string, platform Platform, keychain authn.Keychain) (v1.Image, error) {
if baseRef == "scratch" {
return empty.Image, nil
}
Expand All @@ -29,7 +29,7 @@ func GetBaseImage(ctx RunCtx, baseRef string, platform Platform, keychain authn.
return getImageForPlatform(index, platform)
}

func fetchImageIndex(ctx RunCtx, src string, keychain authn.Keychain) (name.Reference, v1.ImageIndex, error) {
func fetchImageIndex(ctx BuildContext, src string, keychain authn.Keychain) (name.Reference, v1.ImageIndex, error) {
ref, err := name.ParseReference(src)
if err != nil {
return nil, nil, err
Expand Down
4 changes: 2 additions & 2 deletions pkg/build/layers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/google/go-containerregistry/pkg/v1/tarball"
)

func createLayerFromFolder(ctx RunCtx, srcPath, dstPath string, opts ...tarball.LayerOption) (v1.Layer, error) {
func createLayerFromFolder(ctx BuildContext, srcPath, dstPath string, opts ...tarball.LayerOption) (v1.Layer, error) {
tarPath, err := createTarFromFolder(ctx, srcPath, dstPath)
if err != nil {
return nil, err
Expand All @@ -21,7 +21,7 @@ func createLayerFromFolder(ctx RunCtx, srcPath, dstPath string, opts ...tarball.
return tarball.LayerFromFile(tarPath, opts...)
}

func createTarFromFolder(ctx RunCtx, srcPath, dstPath string) (string, error) {
func createTarFromFolder(ctx BuildContext, srcPath, dstPath string) (string, error) {
tarFile, err := CreateTempFile(ctx)
if err != nil {
return "", err
Expand Down
2 changes: 1 addition & 1 deletion pkg/build/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/google/go-containerregistry/pkg/v1/remote"
)

func Publish(ctx RunCtx, tag name.Tag, image v1.Image, target RunConfigTarget) error {
func Publish(ctx BuildContext, tag name.Tag, image v1.Image, target BuildSpecTarget) error {
digest, err := image.Digest()
if err != nil {
return fmt.Errorf("failed to retrieve new image digest: %w", err)
Expand Down
20 changes: 8 additions & 12 deletions pkg/build/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,38 +26,34 @@ func (p Platform) String() string {
return p.OS + "/" + p.Arch
}

type RunConfigBase struct {
SourceUrl string
}

type RunConfigInjectLayer struct {
type BuildSpecInjectLayer struct {
Platform Platform

SourcePath string
DestinationPath string
Entrypoint string
}

type RunConfigTarget struct {
type BuildSpecTarget struct {
Repo string
Type TargetType
}

type RunConfig struct {
type BuildSpec struct {
BaseRef string
InjectLayer RunConfigInjectLayer
Target RunConfigTarget
InjectLayer BuildSpecInjectLayer
Target BuildSpecTarget
}

type RunCtx struct {
type BuildContext struct {
Ctx context.Context
ExitCleanupWatcher *ExitCleanupWatcher
Keychain authn.Keychain

TempPath string
}

func Build(ctx RunCtx, cfg RunConfig) error {
func Build(ctx BuildContext, cfg BuildSpec) error {
tag, err := name.NewTag(cfg.Target.Repo)
if err != nil {
return fmt.Errorf("failed to parse target repo: %w", err)
Expand Down Expand Up @@ -86,7 +82,7 @@ func Build(ctx RunCtx, cfg RunConfig) error {
return Publish(ctx, tag, newImage, cfg.Target)
}

func mutateConfig(img v1.Image, runCfg RunConfig) (v1.Image, error) {
func mutateConfig(img v1.Image, runCfg BuildSpec) (v1.Image, error) {
cfg, err := img.ConfigFile()
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/build/temp.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"os"
)

func CreateTempFile(ctx RunCtx) (*os.File, error) {
func CreateTempFile(ctx BuildContext) (*os.File, error) {
fp, err := os.CreateTemp(ctx.TempPath, "tko-temp-*.tar")
if err != nil {
return nil, err
Expand Down
8 changes: 4 additions & 4 deletions pkg/cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ func (b *BuildCmd) Run(cliCtx *CliCtx) error {
github.Keychain,
)

cfg := build.RunConfig{
cfg := build.BuildSpec{
BaseRef: os.Getenv("TKO_BASE_IMAGE"),
InjectLayer: build.RunConfigInjectLayer{
InjectLayer: build.BuildSpecInjectLayer{
Platform: build.Platform{
OS: "linux",
Arch: "amd64",
Expand All @@ -43,7 +43,7 @@ func (b *BuildCmd) Run(cliCtx *CliCtx) error {
DestinationPath: os.Getenv("TKO_DEST_PATH"),
Entrypoint: os.Getenv("TKO_ENTRYPOINT"),
},
Target: build.RunConfigTarget{
Target: build.BuildSpecTarget{
Repo: os.Getenv("TKO_TARGET_REPO"),
Type: targetType,
},
Expand Down Expand Up @@ -80,7 +80,7 @@ func (b *BuildCmd) Run(cliCtx *CliCtx) error {
logs.Debug.SetOutput(os.Stderr)
}

return build.Build(build.RunCtx{
return build.Build(build.BuildContext{
Ctx: cliCtx.Ctx,
ExitCleanupWatcher: cliCtx.ExitCleanWatcher,
Keychain: keychain,
Expand Down

0 comments on commit 4af5922

Please sign in to comment.