Skip to content

Commit

Permalink
refactor: docker registry package
Browse files Browse the repository at this point in the history
- move push image options
- move and rename docker registry interface
- rename docker registry api interface

Signed-off-by: Alexey Igrychev <alexey.igrychev@flant.com>
  • Loading branch information
alexey-igrychev committed Mar 17, 2022
1 parent b2908a2 commit 8533997
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 37 deletions.
2 changes: 1 addition & 1 deletion integration/suites/cleanup/suite_test.go
Expand Up @@ -33,7 +33,7 @@ var SuiteData struct {
suite_init.SuiteData
TestImplementation string
StagesStorage storage.StagesStorage
ContainerRegistry docker_registry.DockerRegistry
ContainerRegistry docker_registry.Interface
}

var (
Expand Down
2 changes: 1 addition & 1 deletion integration/suites/cleanup_after_converge/suite_test.go
Expand Up @@ -32,7 +32,7 @@ func TestSuite(t *testing.T) {
var SuiteData = struct {
suite_init.SuiteData
StagesStorage storage.StagesStorage
ContainerRegistry docker_registry.DockerRegistry
ContainerRegistry docker_registry.Interface
}{}

var (
Expand Down
2 changes: 1 addition & 1 deletion pkg/build/stage/base.go
Expand Up @@ -122,7 +122,7 @@ func (s *BaseStage) Name() StageName {
panic("name must be defined!")
}

func (s *BaseStage) FetchDependencies(_ context.Context, _ Conveyor, _ container_runtime.ContainerRuntime, _ docker_registry.DockerRegistryInterface) error {
func (s *BaseStage) FetchDependencies(_ context.Context, _ Conveyor, _ container_runtime.ContainerRuntime, _ docker_registry.ApiInterface) error {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/build/stage/dockerfile.go
Expand Up @@ -318,7 +318,7 @@ type dockerfileInstructionInterface interface {
Name() string
}

func (s *DockerfileStage) FetchDependencies(ctx context.Context, c Conveyor, containerRuntime container_runtime.ContainerRuntime, dockerRegistry docker_registry.DockerRegistryInterface) error {
func (s *DockerfileStage) FetchDependencies(ctx context.Context, c Conveyor, containerRuntime container_runtime.ContainerRuntime, dockerRegistry docker_registry.ApiInterface) error {
resolvedDependenciesArgsHash := resolveDependenciesArgsHash(s.dependencies, c)

resolvedDockerMetaArgsHash, err := s.resolveDockerMetaArgs(resolvedDependenciesArgsHash)
Expand Down
2 changes: 1 addition & 1 deletion pkg/build/stage/dockerfile_test.go
Expand Up @@ -290,7 +290,7 @@ RUN echo hello

containerRuntime := NewContainerRuntimeMock()

dockerRegistry := NewDockerRegistryStub()
dockerRegistry := NewDockerRegistryApiStub()

err := stage.FetchDependencies(ctx, conveyor, containerRuntime, dockerRegistry)
Expect(IsErrInvalidBaseImage(err)).To(BeTrue())
Expand Down
2 changes: 1 addition & 1 deletion pkg/build/stage/interface.go
Expand Up @@ -14,7 +14,7 @@ type Interface interface {

IsEmpty(ctx context.Context, c Conveyor, prevBuiltImage container_runtime.LegacyImageInterface) (bool, error)

FetchDependencies(ctx context.Context, c Conveyor, cr container_runtime.ContainerRuntime, dockerRegistry docker_registry.DockerRegistryInterface) error
FetchDependencies(ctx context.Context, c Conveyor, cr container_runtime.ContainerRuntime, dockerRegistry docker_registry.ApiInterface) error
GetDependencies(ctx context.Context, c Conveyor, prevImage container_runtime.LegacyImageInterface, prevBuiltImage container_runtime.LegacyImageInterface) (string, error)
GetNextStageDependencies(ctx context.Context, c Conveyor) (string, error)

Expand Down
10 changes: 5 additions & 5 deletions pkg/build/stage/stubs_test.go
Expand Up @@ -192,15 +192,15 @@ func (containerRuntime *ContainerRuntimeMock) Pull(ctx context.Context, ref stri
return nil
}

type DockerRegistryStub struct {
docker_registry.DockerRegistryInterface
type DockerRegistryApiStub struct {
docker_registry.ApiInterface
}

func NewDockerRegistryStub() *DockerRegistryStub {
return &DockerRegistryStub{}
func NewDockerRegistryApiStub() *DockerRegistryApiStub {
return &DockerRegistryApiStub{}
}

func (dockerRegistry *DockerRegistryStub) GetRepoImageConfigFile(ctx context.Context, reference string) (*v1.ConfigFile, error) {
func (dockerRegistry *DockerRegistryApiStub) GetRepoImageConfigFile(ctx context.Context, reference string) (*v1.ConfigFile, error) {
return &v1.ConfigFile{
Config: v1.Config{},
}, nil
Expand Down
4 changes: 4 additions & 0 deletions pkg/docker_registry/api.go
Expand Up @@ -219,6 +219,10 @@ func (api *api) MutateAndPushImage(_ context.Context, sourceReference, destinati
return nil
}

type PushImageOptions struct {
Labels map[string]string
}

func (api *api) PushImage(ctx context.Context, reference string, opts *PushImageOptions) error {
retriesLimit := 5

Expand Down
25 changes: 1 addition & 24 deletions pkg/docker_registry/docker_registry.go
@@ -1,37 +1,14 @@
package docker_registry

import (
"context"
"fmt"
"regexp"
"strings"

"github.com/google/go-containerregistry/pkg/authn"
"github.com/google/go-containerregistry/pkg/name"
v1 "github.com/google/go-containerregistry/pkg/v1"

"github.com/werf/werf/pkg/image"
)

type DockerRegistry interface {
CreateRepo(ctx context.Context, reference string) error
DeleteRepo(ctx context.Context, reference string) error
Tags(ctx context.Context, reference string) ([]string, error)
TagRepoImage(ctx context.Context, repoImage *image.Info, tag string) error
GetRepoImage(ctx context.Context, reference string) (*image.Info, error)
TryGetRepoImage(ctx context.Context, reference string) (*image.Info, error)
IsRepoImageExists(ctx context.Context, reference string) (bool, error)
DeleteRepoImage(ctx context.Context, repoImage *image.Info) error
PushImage(ctx context.Context, reference string, opts *PushImageOptions) error
MutateAndPushImage(ctx context.Context, sourceReference, destinationReference string, mutateConfigFunc func(v1.Config) (v1.Config, error)) error

String() string
}

type PushImageOptions struct {
Labels map[string]string
}

type DockerRegistryOptions struct {
InsecureRegistry bool
SkipTlsVerifyRegistry bool
Expand Down Expand Up @@ -114,7 +91,7 @@ func (o *DockerRegistryOptions) defaultOptions() defaultImplementationOptions {
}}
}

func NewDockerRegistry(repositoryAddress string, implementation string, options DockerRegistryOptions) (DockerRegistry, error) {
func NewDockerRegistry(repositoryAddress string, implementation string, options DockerRegistryOptions) (Interface, error) {
switch implementation {
case AwsEcrImplementationName:
return newAwsEcr(options.awsEcrOptions())
Expand Down
19 changes: 18 additions & 1 deletion pkg/docker_registry/interface.go
Expand Up @@ -4,8 +4,25 @@ import (
"context"

v1 "github.com/google/go-containerregistry/pkg/v1"

"github.com/werf/werf/pkg/image"
)

type DockerRegistryInterface interface {
type Interface interface {
CreateRepo(ctx context.Context, reference string) error
DeleteRepo(ctx context.Context, reference string) error
Tags(ctx context.Context, reference string) ([]string, error)
TagRepoImage(ctx context.Context, repoImage *image.Info, tag string) error
GetRepoImage(ctx context.Context, reference string) (*image.Info, error)
TryGetRepoImage(ctx context.Context, reference string) (*image.Info, error)
IsRepoImageExists(ctx context.Context, reference string) (bool, error)
DeleteRepoImage(ctx context.Context, repoImage *image.Info) error
PushImage(ctx context.Context, reference string, opts *PushImageOptions) error
MutateAndPushImage(ctx context.Context, sourceReference, destinationReference string, mutateConfigFunc func(v1.Config) (v1.Config, error)) error

String() string
}

type ApiInterface interface {
GetRepoImageConfigFile(ctx context.Context, reference string) (*v1.ConfigFile, error)
}
2 changes: 1 addition & 1 deletion pkg/storage/repo_stages_storage.go
Expand Up @@ -60,7 +60,7 @@ func isUnexpectedTagFormatError(err error) bool {

type RepoStagesStorage struct {
RepoAddress string
DockerRegistry docker_registry.DockerRegistry
DockerRegistry docker_registry.Interface
ContainerRuntime container_runtime.ContainerRuntime
}

Expand Down

0 comments on commit 8533997

Please sign in to comment.