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: add registry-secret param / envvar #94

Closed
wants to merge 10 commits into from
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 .ImagePullSecrets "" }}
imagePullSecrets:
- name: {{ .ImagePullSecrets }}
{{ 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)
imagePullSecrets := cCtx.String(imagePullSecretsFlag)
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,
imagePullSecrets,
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"
imagePullSecretsFlag string = "image-pull-secrets"
stopOnBuildFlag string = "stop-on-build"
stopOnPushFlag string = "stop-on-push"
envVarFileFlag string = "env-var-file"
Expand Down Expand Up @@ -101,6 +102,12 @@ func InitFlags() flags {
Required: true,
Category: "deploy",
},
&cli.StringFlag{
Name: imagePullSecretsFlag,
EnvVars: []string{"INITIUM_REGISTRY_SECRET"},
This conversation was marked as resolved.
Show resolved Hide resolved
Required: false,
Category: "deploy",
},
&cli.StringFlag{
Name: envVarFileFlag,
Value: defaults.EnvVarFile,
Expand Down
1 change: 1 addition & 0 deletions src/cli/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ container-registry: %s
default-branch: main
dockerfile-name: null
env-var-file: .env.initium
image-pull-secrets: null
registry-user: null
runtime-version: null
`,
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 @@ -53,9 +53,15 @@ func loadManifest(namespace string, commitSha string, project *project.Project,
return nil, fmt.Errorf("error reading the knative service yaml: %v", err)
}

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

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 {
This conversation was marked as resolved.
Show resolved Hide resolved
return nil, err
}

Expand Down
14 changes: 8 additions & 6 deletions 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
ImagePullSecrets string
Resources fs.FS
}

Expand All @@ -43,13 +44,14 @@ 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, imagePullSecrets string, resources fs.FS) Project {
return Project{
Name: name,
Directory: directory,
RuntimeVersion: runtimeVersion,
Resources: resources,
Version: version,
Name: name,
Directory: directory,
RuntimeVersion: runtimeVersion,
ImagePullSecrets: imagePullSecrets,
Resources: resources,
Version: version,
}
}

Expand Down