Skip to content

Commit

Permalink
feat: custom registry draft commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mojtaba-esk committed Dec 6, 2024
1 parent ad86999 commit 1ccc809
Show file tree
Hide file tree
Showing 20 changed files with 671 additions and 261 deletions.
78 changes: 78 additions & 0 deletions e2e/registry/build_image_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package system

import (
"context"
"strings"
"time"

"github.com/celestiaorg/knuu/pkg/builder"
"github.com/celestiaorg/knuu/pkg/instance"
)

const (
gitRepo = "https://github.com/celestiaorg/knuu.git"
gitBranch = "test/build-from-git" // This branch has a Dockerfile and is protected as to not be deleted
)

func (s *Suite) TestBuildFromGit() {
const namePrefix = "registry-build-from-git"

// Setup
ctx := context.Background()

target, err := s.createAndStartBuildFromGitInstance(ctx, namePrefix)
s.Require().NoError(err)

s.T().Log("Getting file bytes")
// The file is created by the dockerfile in the repo,
// so to make sure it is built correctly, we check the file
data, err := target.Storage().GetFileBytes(ctx, "/test.txt")
s.Require().NoError(err)

data = []byte(strings.TrimSpace(string(data)))
s.Assert().Equal([]byte("Hello, World!"), data, "file bytes do not match.")
}

func (s *Suite) TestRegistryCacheWithBuildFromGit() {
const namePrefix = "cache-registry-build-from-git"

// Setup
ctx := context.Background()

_, err := s.createAndStartBuildFromGitInstance(ctx, namePrefix)
s.Require().NoError(err)

startTime := time.Now()

_, err = s.createAndStartBuildFromGitInstance(ctx, "2nd-"+namePrefix)
s.Require().NoError(err)

duration := time.Since(startTime)
s.T().Logf("Time taken: %s", duration)
}

func (s *Suite) createAndStartBuildFromGitInstance(ctx context.Context, namePrefix string) (*instance.Instance, error) {
s.T().Logf("Creating new instance %s", namePrefix)
target, err := s.Knuu.NewInstance(namePrefix)
s.Require().NoError(err)

s.T().Log("Building the image")

// This is a blocking call which builds the image from git repo
err = target.Build().SetGitRepo(ctx, builder.GitContext{
Repo: gitRepo,
Branch: gitBranch,
Username: "",
Password: "",
})
s.Require().NoError(err)
s.T().Log("Image built")

s.Require().NoError(target.Build().Commit(ctx))

s.T().Logf("Starting instance %s", namePrefix)
s.Require().NoError(target.Execution().Start(ctx))

s.T().Log("Instance started")
return target, nil
}
56 changes: 56 additions & 0 deletions e2e/registry/suite_setup_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package system

import (
"context"
"testing"
"time"

"github.com/sirupsen/logrus"
"github.com/stretchr/testify/suite"

"github.com/celestiaorg/knuu/e2e"
"github.com/celestiaorg/knuu/pkg/k8s"
"github.com/celestiaorg/knuu/pkg/knuu"
"github.com/celestiaorg/knuu/pkg/minio"
)

const (
testTimeout = time.Minute * 100 // the same time that is used in the ci/cd pipeline
alpineImage = "alpine:latest"
)

type Suite struct {
e2e.Suite
}

func TestRunSuite(t *testing.T) {
suite.Run(t, new(Suite))
}

func (s *Suite) SetupSuite() {
var (
ctx = context.Background()
logger = logrus.New()
)

logger.SetLevel(logrus.DebugLevel)

k8sClient, err := k8s.NewClient(ctx, knuu.DefaultScope(), logger)
s.Require().NoError(err, "Error creating k8s client")

minioClient, err := minio.New(ctx, k8sClient, logger)
s.Require().NoError(err, "Error creating minio client")

s.Knuu, err = knuu.New(ctx, knuu.Options{
LocalRegistryEnabled: true,
K8sClient: k8sClient,
MinioClient: minioClient, // needed for build from git tests
Timeout: testTimeout,
})
s.Require().NoError(err)

s.T().Logf("Scope: %s", s.Knuu.Scope)
s.Knuu.HandleStopSignal(ctx)

s.Executor.Kn = s.Knuu
}
1 change: 1 addition & 0 deletions e2e/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func (s *Suite) TearDownTest() {
}

func (s *Suite) cleanupSuite() {
return
s.T().Logf("Cleaning up knuu...")
if err := s.Knuu.CleanUp(context.Background()); err != nil {
s.T().Logf("Error cleaning up test suite: %v", err)
Expand Down
30 changes: 0 additions & 30 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ go 1.22.5

require (
github.com/celestiaorg/bittwister v0.0.0-20231213180407-65cdbaf5b8c7
github.com/docker/docker v26.1.4+incompatible
github.com/google/uuid v1.6.0
github.com/minio/minio-go/v7 v7.0.74
github.com/sirupsen/logrus v1.9.3
Expand All @@ -17,23 +16,15 @@ require (
)

require (
github.com/Azure/go-ansiterm v0.0.0-20230124172434-306776ec8161 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/acroca/go-symbols v0.1.1 // indirect
github.com/cilium/ebpf v0.12.3 // indirect
github.com/containerd/log v0.1.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/distribution/reference v0.5.0 // indirect
github.com/docker/go-connections v0.4.1-0.20210727194412-58542c764a11 // indirect
github.com/docker/go-units v0.5.0 // indirect
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/frankban/quicktest v1.14.6 // indirect
github.com/go-ini/ini v1.67.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.3 // indirect
Expand All @@ -49,56 +40,35 @@ require (
github.com/imdario/mergo v0.3.16 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/karrick/godirwalk v1.17.0 // indirect
github.com/klauspost/compress v1.17.9 // indirect
github.com/klauspost/cpuid/v2 v2.2.8 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/minio/md5-simd v1.1.2 // indirect
github.com/moby/docker-image-spec v1.3.1 // indirect
github.com/moby/spdystream v0.2.0 // indirect
github.com/moby/term v0.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
github.com/nsf/gocode v0.0.0-20230322162601-b672b49f3818 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/ramya-rao-a/go-outline v0.0.0-20210608161538-9736a4bde949 // indirect
github.com/rs/xid v1.5.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/uudashr/gopkgs v1.3.2 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect
go.opentelemetry.io/otel v1.26.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.26.0 // indirect
go.opentelemetry.io/otel/metric v1.26.0 // indirect
go.opentelemetry.io/otel/sdk v1.26.0 // indirect
go.opentelemetry.io/otel/trace v1.26.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/crypto v0.29.0 // indirect
golang.org/x/exp v0.0.0-20240213143201-ec583247a57a // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/net v0.31.0 // indirect
golang.org/x/oauth2 v0.17.0 // indirect
golang.org/x/sync v0.9.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/term v0.26.0 // indirect
golang.org/x/text v0.20.0 // indirect
golang.org/x/time v0.5.0 // indirect
golang.org/x/tools v0.27.0 // indirect
golang.org/x/tools/cmd/guru v0.1.1-deprecated // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gotest.tools/v3 v3.5.1 // indirect
k8s.io/klog/v2 v2.120.1 // indirect
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
Expand Down
Loading

0 comments on commit 1ccc809

Please sign in to comment.