Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Bring your own registry #837

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ func serverCommunication(
var imageBuildRequest dx.ImageBuildRequest
_ = json.Unmarshal(requestString, &imageBuildRequest)

if imageBuildRequest.Dockerfile != "" {
if imageBuildRequest.Strategy == "dockerfile" {
go dockerfileImageBuild(kubeEnv, gimletHost, buildId, imageBuildRequest, messages)
} else {
go buildImage(gimletHost, agentKey, buildId, imageBuildRequest, messages, config.ImageBuilderHost)
Expand Down
45 changes: 43 additions & 2 deletions cmd/agent/imagebuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ func dockerfileImageBuild(
reqUrl := fmt.Sprintf("%s/agent/imagebuild/%s", gimletHost, buildId)
jobName := fmt.Sprintf("kaniko-%d", rand.Uint32())
job := generateJob(trigger, jobName, reqUrl)
job = mountPushSecret(job, trigger.Registry)
_, err := kubeEnv.Client.BatchV1().Jobs("infrastructure").Create(context.TODO(), job, meta_v1.CreateOptions{})
if err != nil {
logrus.Errorf("cannot apply job: %s", err)
Expand Down Expand Up @@ -353,6 +354,46 @@ func generateJob(trigger dx.ImageBuildRequest, name, sourceUrl string) *batchv1.
}
}

func mountPushSecret(job *batchv1.Job, registry string) *batchv1.Job {
optional := true
if registry == "ghcrRegistry" {
job.Spec.Template.Spec.Containers[0].VolumeMounts = append(job.Spec.Template.Spec.Containers[0].VolumeMounts, corev1.VolumeMount{
MountPath: "/kaniko/.docker",
Name: "ghcr-registry-pushsecret",
})

job.Spec.Template.Spec.Volumes = append(job.Spec.Template.Spec.Volumes, corev1.Volume{
Name: "ghcr-registry-pushsecret",
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: "ghcr-registry-pushsecret",
Optional: &optional,
},
},
})
return job
}

if registry == "dockerhubRegistry" {
job.Spec.Template.Spec.Containers[0].VolumeMounts = append(job.Spec.Template.Spec.Containers[0].VolumeMounts, corev1.VolumeMount{
MountPath: "/kaniko/.docker",
Name: "dockerhub-registry-pushsecret",
})

job.Spec.Template.Spec.Volumes = append(job.Spec.Template.Spec.Volumes, corev1.Volume{
Name: "dockerhub-registry-pushsecret",
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: "dockerhub-registry-pushsecret",
Optional: &optional,
},
},
})
return job
}
return job
}

func streamInitContainerLogs(kubeEnv *agent.KubeEnv,
messages chan *streaming.WSMessage,
pod, container string,
Expand Down Expand Up @@ -426,8 +467,7 @@ func streamLogs(kubeEnv *agent.KubeEnv,
go func() {
for {
line, err := reader.ReadBytes('\n')
lastLine = string(line)
logCh <- lastLine
logCh <- string(line)
if err != nil {
if err == io.EOF {
close(logCh)
Expand All @@ -438,6 +478,7 @@ func streamLogs(kubeEnv *agent.KubeEnv,
streamImageBuildEvent(messages, userLogin, imageBuildId, "error", "")
break
}
lastLine = string(line)
}
}()

Expand Down
31 changes: 13 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ require (
cuelang.org/go v0.4.0
github.com/Masterminds/sprig/v3 v3.2.3
github.com/MichaelMure/go-term-markdown v0.1.4
github.com/bitnami-labs/sealed-secrets v0.13.1
github.com/bitnami-labs/sealed-secrets v0.26.1
github.com/blang/semver/v4 v4.0.0
github.com/btubbs/datetime v0.1.1
github.com/bwmarrin/discordgo v0.27.1
Expand Down Expand Up @@ -72,7 +72,7 @@ require (
github.com/xeipuuv/gojsonschema v1.2.0
github.com/zclconf/go-cty v1.13.0
golang.org/x/crypto v0.21.0
golang.org/x/oauth2 v0.17.0
golang.org/x/oauth2 v0.18.0
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
gotest.tools v2.2.0+incompatible
Expand Down Expand Up @@ -114,15 +114,14 @@ require (
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/lestrrat-go/httprc v1.0.5 // indirect
github.com/lestrrat-go/jwx/v2 v2.0.21 // indirect
github.com/lithammer/fuzzysearch v1.1.8 // indirect
github.com/mattn/go-sqlite3 v2.0.3+incompatible // indirect
github.com/miekg/dns v1.1.43 // indirect
github.com/mkmik/multierror v0.4.0 // indirect
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
github.com/ncruces/go-strftime v0.1.9 // indirect
github.com/onsi/ginkgo/v2 v2.15.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/segmentio/asm v1.2.0 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
Expand All @@ -132,19 +131,15 @@ require (
go.opentelemetry.io/otel/metric v1.24.0 // indirect
go.opentelemetry.io/otel/trace v1.24.0 // indirect
golang.org/x/mod v0.15.0 // indirect
golang.org/x/net v0.21.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/tools v0.18.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240228224816-df926f6c8641 // indirect
gopkg.in/evanphx/json-patch.v5 v5.9.0 // indirect
gotest.tools/v3 v3.5.0 // indirect
lukechampine.com/uint128 v1.2.0 // indirect
modernc.org/cc/v3 v3.41.0 // indirect
modernc.org/ccgo/v3 v3.16.15 // indirect
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 // indirect
modernc.org/libc v1.41.0 // indirect
modernc.org/mathutil v1.6.0 // indirect
modernc.org/memory v1.7.2 // indirect
modernc.org/opt v0.1.3 // indirect
modernc.org/strutil v1.2.0 // indirect
modernc.org/token v1.1.0 // indirect
)
Expand Down Expand Up @@ -185,7 +180,7 @@ require (
github.com/docker/go-units v0.5.0 // indirect
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 // indirect
github.com/eliukblau/pixterm/pkg/ansimage v0.0.0-20191210081756-9fb6cf8c2f75 // indirect
github.com/emicklei/go-restful/v3 v3.11.3 // indirect
github.com/emicklei/go-restful/v3 v3.12.0 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/evanphx/json-patch v5.9.0+incompatible // indirect
github.com/exponent-io/jsonpath v0.0.0-20210407135951-1de76d718b3f // indirect
Expand All @@ -198,13 +193,13 @@ require (
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-gorp/gorp/v3 v3.1.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-openapi/jsonpointer v0.20.2 // indirect
github.com/go-openapi/jsonreference v0.20.4 // indirect
github.com/go-openapi/swag v0.22.9 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/gofrs/uuid v4.4.0+incompatible // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/gomarkdown/markdown v0.0.0-20191123064959-2c17d62f5098 // indirect
github.com/google/btree v1.1.2 // indirect
github.com/google/go-cmp v0.6.0 // indirect
Expand Down Expand Up @@ -260,8 +255,8 @@ require (
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_model v0.6.0 // indirect
github.com/prometheus/common v0.49.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/prometheus/common v0.50.0 // indirect
github.com/prometheus/procfs v0.13.0 // indirect
github.com/pterm/pterm v0.12.62
github.com/rivo/uniseg v0.4.7 // indirect
github.com/rubenv/sql-migrate v1.6.1 // indirect
Expand All @@ -288,7 +283,7 @@ require (
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/grpc v1.62.0 // indirect
google.golang.org/protobuf v1.32.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
k8s.io/apiextensions-apiserver v0.29.2
Expand All @@ -298,7 +293,7 @@ require (
k8s.io/klog/v2 v2.120.1 // indirect
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340
k8s.io/kubectl v0.29.2
k8s.io/utils v0.0.0-20240102154912-e7106e64919e // indirect
k8s.io/utils v0.0.0-20240310230437-4693a0247e57 // indirect
oras.land/oras-go v1.2.5 // indirect
sigs.k8s.io/cli-utils v0.35.0 // indirect
sigs.k8s.io/controller-runtime v0.17.2 // indirect
Expand Down
Loading
Loading