Skip to content

Commit

Permalink
feature: added registry-secret param / envvar to allow setting custom…
Browse files Browse the repository at this point in the history
… private registry credentials in knative service manifest
  • Loading branch information
Kristof Havasi committed Aug 30, 2023
1 parent feeefe0 commit 6b04b0e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
4 changes: 4 additions & 0 deletions assets/knative/service.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ metadata:
spec:
template:
spec:
{{ if ne .RegistrySecret "" }}
imagePullSecrets:
- name: {{ .RegistrySecret }}
{{ end }}
containers:
- image: {{ .RemoteTag }}
imagePullPolicy: Always
2 changes: 2 additions & 0 deletions src/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func (c *icli) init(cCtx *cli.Context) error {
projectDirectory := cCtx.String(projectDirectoryFlag)
absProjectDirectory, err := filepath.Abs(cCtx.String(projectDirectoryFlag))
registry := cCtx.String(repoNameFlag)
registrySecret := cCtx.String(registrySecretFlag)
dockerFileName := cCtx.String(dockerFileNameFlag)

if dockerFileName == "" {
Expand All @@ -83,6 +84,7 @@ func (c *icli) init(cCtx *cli.Context) error {
projectDirectory,
cCtx.String(runtimeVersionFlag),
version,
registrySecret,
c.Resources,
)

Expand Down
7 changes: 7 additions & 0 deletions src/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const (
dockerFileNameFlag string = "dockerfile-name"
configFileFlag string = "config-file"
namespaceFlag string = "namespace"
registrySecretFlag string = "registry-secret"
stopOnBuildFlag string = "stop-on-build"
stopOnPushFlag string = "stop-on-push"
)
Expand Down Expand Up @@ -100,6 +101,12 @@ func InitFlags() flags {
Required: true,
Category: "deploy",
},
&cli.StringFlag{
Name: registrySecretFlag,
EnvVars: []string{"INITIUM_REGISTRY_SECRET"},
Required: false,
Category: "deploy",
},
},
Registry: []cli.Flag{
&cli.StringFlag{
Expand Down
8 changes: 7 additions & 1 deletion src/services/k8s/knative.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,15 @@ func loadManifest(project *project.Project, dockerImage docker.DockerImage) (*se
return nil, fmt.Errorf("error reading the knative service yaml: %v", err)
}

templateParams := map[string]interface{}{
"Name": dockerImage.Name,
"RemoteTag": dockerImage.RemoteTag(),
"RegistrySecret": project.RegistrySecret,
}

output := &bytes.Buffer{}
// TODO replace map[string]string{} with proper values
if err = template.Execute(output, dockerImage); err != nil {
if err = template.Execute(output, templateParams); err != nil {
return nil, err
}

Expand Down
4 changes: 3 additions & 1 deletion src/services/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Project struct {
Directory string
RuntimeVersion string
DefaultRuntimeVersion string
RegistrySecret string
Resources fs.FS
}

Expand All @@ -46,11 +47,12 @@ func GuessAppName() *string {
return &name
}

func New(name string, directory string, runtimeVersion string, version string, resources fs.FS) Project {
func New(name string, directory string, runtimeVersion string, version string, registrySecret string, resources fs.FS) Project {
return Project{
Name: name,
Directory: directory,
RuntimeVersion: runtimeVersion,
RegistrySecret: registrySecret,
Resources: resources,
Version: version,
}
Expand Down

0 comments on commit 6b04b0e

Please sign in to comment.