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: added option to override CA certificates #905

Merged
merged 1 commit into from
Aug 29, 2024
Merged
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
25 changes: 23 additions & 2 deletions cmd/dev/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const (
flagConfigserverImage = "configserver-image"
flagRunService = "run-service"
flagDownOnError = "down-on-error"
flagCACertificates = "ca-certificates"
)

const (
Expand Down Expand Up @@ -128,6 +129,11 @@ func CommandUp() *cli.Command { //nolint:funlen
Usage: "Skip confirmation",
EnvVars: []string{"NHOST_YES"},
},
&cli.StringFlag{ //nolint:exhaustruct
Name: flagCACertificates,
Usage: "Mounts and everrides path to CA certificates in the containers",
EnvVars: []string{"NHOST_CA_CERTIFICATES"},
},
},
}
}
Expand Down Expand Up @@ -171,6 +177,7 @@ func commandUp(cCtx *cli.Context) error {
},
cCtx.String(flagDashboardVersion),
configserverImage,
cCtx.String(flagCACertificates),
cCtx.StringSlice(flagRunService),
cCtx.Bool(flagDownOnError),
)
Expand Down Expand Up @@ -311,6 +318,7 @@ func up( //nolint:funlen,cyclop
ports dockercompose.ExposePorts,
dashboardVersion string,
configserverImage string,
caCertificatesPath string,
runServices []string,
) error {
ctx, cancel := context.WithCancel(ctx)
Expand Down Expand Up @@ -364,6 +372,7 @@ func up( //nolint:funlen,cyclop
dashboardVersion,
configserverImage,
clienv.PathExists(ce.Path.Functions()),
caCertificatesPath,
runServicesCfg...,
)
if err != nil {
Expand Down Expand Up @@ -513,14 +522,26 @@ func Up(
ports dockercompose.ExposePorts,
dashboardVersion string,
configserverImage string,
caCertificatesPath string,
runServices []string,
downOnError bool,
) error {
dc := dockercompose.New(ce.Path.WorkingDir(), ce.Path.DockerCompose(), ce.ProjectName())

if err := up(
ctx, ce, appVersion, dc, httpPort, useTLS, postgresPort,
applySeeds, ports, dashboardVersion, configserverImage, runServices,
ctx,
ce,
appVersion,
dc,
httpPort,
useTLS,
postgresPort,
applySeeds,
ports,
dashboardVersion,
configserverImage,
caCertificatesPath,
runServices,
); err != nil {
return upErr(ce, dc, downOnError, err) //nolint:contextcheck
}
Expand Down
21 changes: 20 additions & 1 deletion dockercompose/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,21 @@ type RunService struct {
Path string
}

func ComposeFileFromConfig(
func mountCACertificates(
path string,
services map[string]*Service,
) {
for _, service := range services {
service.Volumes = append(service.Volumes, Volume{
Type: "bind",
Source: path,
Target: "/etc/ssl/certs/ca-certificates.crt",
ReadOnly: ptr(true),
})
}
}

func ComposeFileFromConfig( //nolint:funlen
cfg *model.ConfigConfig,
subdomain string,
projectName string,
Expand All @@ -618,6 +632,7 @@ func ComposeFileFromConfig(
dashboardVersion string,
configserverImage string,
startFunctions bool,
caCertificatesPath string,
runServices ...*RunService,
) (*ComposeFile, error) {
services, err := getServices(
Expand Down Expand Up @@ -658,6 +673,10 @@ func ComposeFileFromConfig(
}
}

if caCertificatesPath != "" {
mountCACertificates(caCertificatesPath, services)
}

return &ComposeFile{
Services: services,
Volumes: volumes,
Expand Down
Loading