Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

cli: pass raw string of server run flags to install command #2328

Merged
merged 10 commits into from
Sep 22, 2021
3 changes: 3 additions & 0 deletions .changelog/2328.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:feature
cli: Allow raw string of `server run` flags to be provided to `install` cmd
krantzinator marked this conversation as resolved.
Show resolved Hide resolved
```
24 changes: 21 additions & 3 deletions internal/cli/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,19 @@ func (c *InstallCommand) Run(args []string) int {
return 1
}

// collect any args after a `--` break to pass forward as secondary flags
var secondaryArgs []string
for i, f := range args {
if f == "--" {
secondaryArgs = args[(i + 1):]
break
}
}
krantzinator marked this conversation as resolved.
Show resolved Hide resolved

result, err := p.Install(ctx, &serverinstall.InstallOpts{
Log: log,
UI: c.ui,
Log: log,
UI: c.ui,
ServerRunFlags: secondaryArgs,
})
if err != nil {
c.ui.Output(
Expand Down Expand Up @@ -333,7 +343,7 @@ func (c *InstallCommand) Flags() *flag.Sets {
f.BoolVar(&flag.BoolVar{
Name: "runner",
Target: &c.flagRunner,
Usage: "Install a runner in addition to the server",
Usage: "Install a runner in addition to the server.",
Default: true,
Hidden: true,
})
Expand Down Expand Up @@ -389,6 +399,14 @@ Alias: waypoint install
URL service by manually running the server. If you disable the URL service,
you do not need to accept any terms.

To further customize the server installation, you may pass advanced flag options
specified in the documentation for the 'server run' command. To set these values,
include a '--' after the full argument list for 'install', followed by these
advanced flag options. As an example, to set the server log level to trace
and disable the UI, the command would be:

waypoint install -platform=docker -accept-tos -- -vvv -disable-ui

` + c.Flags().Help())
}

Expand Down
10 changes: 9 additions & 1 deletion internal/cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,12 +632,20 @@ func logger(args []string) ([]string, hclog.Logger, io.Writer, error) {
// Process arguments looking for `-v` flags to control the log level.
// This overrides whatever the env var set.
var outArgs []string
for _, arg := range args {
for i, arg := range args {
if len(arg) != 0 && arg[0] != '-' {
outArgs = append(outArgs, arg)
continue
}

// If we hit a break indicating pass-through flags, we add them all to
// outArgs and just exit, since we don't want to process any secondary
// `-v` flags at this time.
if arg == "--" {
outArgs = append(outArgs, args[i:]...)
break
}

switch arg {
case "-v":
if level == hclog.NoLevel || level > hclog.Info {
Expand Down
6 changes: 3 additions & 3 deletions internal/cli/server_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,21 +367,21 @@ func (c *ServerRunCommand) Flags() *flag.Sets {
f.StringVar(&flag.StringVar{
Name: "url-api-addr",
Target: &c.config.URL.APIAddress,
Usage: "Address to Waypoint URL service API",
Usage: "Address to Waypoint URL service API.",
Default: "api.waypoint.run:443",
})

f.BoolVar(&flag.BoolVar{
Name: "url-api-insecure",
Target: &c.config.URL.APIInsecure,
Usage: "True if TLS is not enabled for the Waypoint URL service API",
Usage: "True if TLS is not enabled for the Waypoint URL service API.",
Default: false,
})

f.StringVar(&flag.StringVar{
Name: "url-control-addr",
Target: &c.config.URL.ControlAddress,
Usage: "Address to Waypoint URL service control API",
Usage: "Address to Waypoint URL service control API.",
Default: DefaultURLControlAddress,
})

Expand Down
5 changes: 3 additions & 2 deletions internal/cli/server_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,9 @@ func (c *ServerUpgradeCommand) Run(args []string) int {
initServerVersion, terminal.WithInfoStyle())

installOpts := &serverinstall.InstallOpts{
Log: log,
UI: c.ui,
Log: log,
UI: c.ui,
ServerRunFlags: c.args,
}

// Upgrade in place
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,7 @@ waypoint status -app=APP-NAME %[1]s
`)

wpProjectNotFound = strings.TrimSpace(`
No project name %q was found for the server context %q. To see a list of
No project named %q was found for the server context %q. To see a list of
currently configured projects, run “waypoint project list”.

If you want more information for a specific application, use the '-app' flag
Expand Down
9 changes: 7 additions & 2 deletions internal/serverinstall/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ func (i *DockerInstaller) Install(

s.Update("Installing Waypoint server to docker")

cmd := []string{"server", "run", "-accept-tos", "-vv", "-db=/data/data.db", fmt.Sprintf("-listen-grpc=0.0.0.0:%s", grpcPort), fmt.Sprintf("-listen-http=0.0.0.0:%s", httpPort)}
cmd = append(cmd, opts.ServerRunFlags...)
cfg := container.Config{
AttachStdout: true,
AttachStderr: true,
Expand All @@ -226,7 +228,7 @@ func (i *DockerInstaller) Install(
Image: i.config.serverImage,
ExposedPorts: nat.PortSet{npGRPC: struct{}{}, npHTTP: struct{}{}},
Env: []string{"PORT=" + grpcPort},
Cmd: []string{"server", "run", "-accept-tos", "-vv", "-db=/data/data.db", fmt.Sprintf("-listen-grpc=0.0.0.0:%s", grpcPort), fmt.Sprintf("-listen-http=0.0.0.0:%s", httpPort)},
Cmd: cmd,
}

bindings := nat.PortMap{}
Expand Down Expand Up @@ -425,6 +427,9 @@ func (i *DockerInstaller) Upgrade(
if err != nil {
return nil, err
}

cmd := []string{"server", "run", "-accept-tos", "-vv", "-db=/data/data.db", fmt.Sprintf("-listen-grpc=0.0.0.0:%s", grpcPort), fmt.Sprintf("-listen-http=0.0.0.0:%s", httpPort)}
cmd = append(cmd, opts.ServerRunFlags...)
cfg := container.Config{
AttachStdout: true,
AttachStderr: true,
Expand All @@ -434,7 +439,7 @@ func (i *DockerInstaller) Upgrade(
Image: i.config.serverImage,
ExposedPorts: nat.PortSet{npGRPC: struct{}{}, npHTTP: struct{}{}},
Env: []string{"PORT=" + grpcPort},
Cmd: []string{"server", "run", "-accept-tos", "-vv", "-db=/data/data.db", fmt.Sprintf("-listen-grpc=0.0.0.0:%s", grpcPort), fmt.Sprintf("-listen-http=0.0.0.0:%s", httpPort)},
Cmd: cmd,
}

bindings := nat.PortMap{}
Expand Down
7 changes: 5 additions & 2 deletions internal/serverinstall/ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (i *ECSInstaller) Install(
},

Run: func(ui terminal.UI) error {
server, err = i.Launch(ctx, log, ui, sess, efsInfo, netInfo, executionRole, cluster, serverLogGroup)
server, err = i.Launch(ctx, log, ui, sess, efsInfo, netInfo, executionRole, cluster, serverLogGroup, opts.ServerRunFlags)
return err
},

Expand Down Expand Up @@ -224,7 +224,7 @@ func (i *ECSInstaller) Launch(
sess *session.Session,
efsInfo *efsInformation,
netInfo *networkInformation,
executionRoleArn, clusterName, logGroup string,
executionRoleArn, clusterName, logGroup string, rawRunFlags []string,
) (*ecsServer, error) {

sg := ui.StepGroup()
Expand Down Expand Up @@ -266,6 +266,9 @@ func (i *ECSInstaller) Launch(
aws.String(fmt.Sprintf("-listen-grpc=0.0.0.0:%d", grpcPort)),
aws.String(fmt.Sprintf("-listen-http=0.0.0.0:%d", httpPort)),
}
for _, f := range rawRunFlags {
cmd = append(cmd, aws.String(f))
}

def := ecs.ContainerDefinition{
Essential: aws.Bool(true),
Expand Down
24 changes: 13 additions & 11 deletions internal/serverinstall/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (i *K8sInstaller) Install(
}

// Decode our configuration
statefulset, err := newStatefulSet(i.config)
statefulset, err := newStatefulSet(i.config, opts.ServerRunFlags)
if err != nil {
ui.Output(
"Error generating statefulset configuration: %s", clierrors.Humanize(err),
Expand Down Expand Up @@ -1181,7 +1181,7 @@ func newDeployment(c k8sConfig, opts *InstallRunnerOpts) (*appsv1.Deployment, er

// newStatefulSet takes in a k8sConfig and creates a new Waypoint Statefulset
// for deployment in Kubernetes.
func newStatefulSet(c k8sConfig) (*appsv1.StatefulSet, error) {
func newStatefulSet(c k8sConfig, rawRunFlags []string) (*appsv1.StatefulSet, error) {
cpuRequest, err := resource.ParseQuantity(c.cpuRequest)
if err != nil {
return nil, fmt.Errorf("could not parse cpu request resource %s: %s", c.cpuRequest, err)
Expand Down Expand Up @@ -1222,6 +1222,16 @@ func newStatefulSet(c k8sConfig) (*appsv1.StatefulSet, error) {
volumeClaimTemplates[0].Spec.StorageClassName = &c.storageClassName
}

ras := []string{
"server",
"run",
"-accept-tos",
"-vv",
"-db=/data/data.db",
"-listen-grpc=0.0.0.0:9701",
"-listen-http=0.0.0.0:9702",
}
ras = append(ras, rawRunFlags...)
return &appsv1.StatefulSet{
ObjectMeta: metav1.ObjectMeta{
Name: serverName,
Expand Down Expand Up @@ -1263,15 +1273,7 @@ func newStatefulSet(c k8sConfig) (*appsv1.StatefulSet, error) {
},
},
Command: []string{serviceName},
Args: []string{
"server",
"run",
"-accept-tos",
"-vv",
"-db=/data/data.db",
"-listen-grpc=0.0.0.0:9701",
"-listen-http=0.0.0.0:9702",
},
Args: ras,
Ports: []apiv1.ContainerPort{
{
Name: "grpc",
Expand Down
10 changes: 6 additions & 4 deletions internal/serverinstall/nomad.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (i *NomadInstaller) Install(
}

s.Update("Installing Waypoint server to Nomad")
allocID, err := i.runJob(ctx, s, client, waypointNomadJob(i.config))
allocID, err := i.runJob(ctx, s, client, waypointNomadJob(i.config, opts.ServerRunFlags))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -246,7 +246,7 @@ func (i *NomadInstaller) Upgrade(
}

s = sg.Add("Upgrading Waypoint server on Nomad to %q", i.config.serverImage)
job := waypointNomadJob(i.config)
job := waypointNomadJob(i.config, opts.ServerRunFlags)
jobOpts := &api.RegisterOptions{
PolicyOverride: i.config.policyOverride,
}
Expand Down Expand Up @@ -615,7 +615,7 @@ EVAL:

// waypointNomadJob takes in a nomadConfig and returns a Nomad Job per the
// Nomad API
func waypointNomadJob(c nomadConfig) *api.Job {
func waypointNomadJob(c nomadConfig, rawRunFlags []string) *api.Job {
job := api.NewServiceJob(serverName, serverName, c.region, 50)
job.Namespace = &c.namespace
job.Datacenters = c.datacenters
Expand Down Expand Up @@ -669,11 +669,13 @@ func waypointNomadJob(c nomadConfig) *api.Job {
}
job.AddTaskGroup(tg)

ras := []string{"server", "run", "-accept-tos", "-vv", "-db=/alloc/data/data.db", fmt.Sprintf("-listen-grpc=0.0.0.0:%s", defaultGrpcPort), fmt.Sprintf("-listen-http=0.0.0.0:%s", defaultHttpPort)}
ras = append(ras, rawRunFlags...)
task := api.NewTask("server", "docker")
task.Config = map[string]interface{}{
"image": c.serverImage,
"ports": []string{"server", "ui"},
"args": []string{"server", "run", "-accept-tos", "-vv", "-db=/alloc/data/data.db", fmt.Sprintf("-listen-grpc=0.0.0.0:%s", defaultGrpcPort), fmt.Sprintf("-listen-http=0.0.0.0:%s", defaultHttpPort)},
"args": ras,
"auth_soft_fail": c.authSoftFail,
}
task.Env = map[string]string{
Expand Down
5 changes: 3 additions & 2 deletions internal/serverinstall/serverinstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ type Installer interface {

// InstallOpts are the options sent to Installer.Install.
type InstallOpts struct {
Log hclog.Logger
UI terminal.UI
Log hclog.Logger
UI terminal.UI
ServerRunFlags []string
}

// InstallResults are the results expected for a successful Installer.Install.
Expand Down
8 changes: 8 additions & 0 deletions website/content/commands/install.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ flag. This only applies to the Waypoint URL service. You may disable the
URL service by manually running the server. If you disable the URL service,
you do not need to accept any terms.

To further customize the server installation, you may pass advanced flag options
specified in the documentation for the 'server run' command. To set these values,
include a '--' after the full argument list for 'install', followed by these
advanced flag options. As an example, to set the server log level to trace
and disable the UI, the command would be:

waypoint install -platform=docker -accept-tos -- -vvv -disable-ui

#### Global Options

- `-plain` - Plain output: no colors, no animation.
Expand Down
8 changes: 8 additions & 0 deletions website/content/commands/server-install.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ flag. This only applies to the Waypoint URL service. You may disable the
URL service by manually running the server. If you disable the URL service,
you do not need to accept any terms.

To further customize the server installation, you may pass advanced flag options
specified in the documentation for the 'server run' command. To set these values,
include a '--' after the full argument list for 'install', followed by these
advanced flag options. As an example, to set the server log level to trace
and disable the UI, the command would be:

waypoint install -platform=docker -accept-tos -- -vvv -disable-ui

#### Global Options

- `-plain` - Plain output: no colors, no animation.
Expand Down
6 changes: 3 additions & 3 deletions website/content/commands/server-run.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ environment.
- `-tls-key-file=<string>` - Path to a PEM-encoded private key file for the TLS certificate specified with -tls-cert-file. This is required if -tls-cert-file is set.
- `-disable-ui` - Disable the embedded web interface
- `-url-enabled` - Enable the URL service.
- `-url-api-addr=<string>` - Address to Waypoint URL service API
- `-url-api-insecure` - True if TLS is not enabled for the Waypoint URL service API
- `-url-control-addr=<string>` - Address to Waypoint URL service control API
- `-url-api-addr=<string>` - Address to Waypoint URL service API.
- `-url-api-insecure` - True if TLS is not enabled for the Waypoint URL service API.
- `-url-control-addr=<string>` - Address to Waypoint URL service control API.
- `-url-control-token=<string>` - Token for the Waypoint URL server control API.
- `-url-auto-app-hostname` - Whether apps automatically get a hostname on deploy.
- `-advertise-addr=<string>` - Address to advertise for the server. This is used by the entrypoints
Expand Down
14 changes: 12 additions & 2 deletions website/content/docs/server/run/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,18 @@ It is a single command to get up and running with Waypoint.

You can also run and configure the server manually using the
[`waypoint server run`](/commands/server-run) command. This is meant for more advanced
users who want to run Waypoint in a platform that the `install` command doesn't support
or to fine-tune the configuration of the server.
users who want to run Waypoint in a platform that the `install` command doesn't support.

It is possible to fine-tune the configuration of the server when using the `waypoint install` command.
To further customize the server installation, you may pass advanced flag options
specified in the documentation for the [`waypoint server run`](/commands/server-run)
command. To set these values, include a `--` after the full argument list for
`install`, followed by these advanced flag options. As an example, to set the
server log level to trace and disable the UI, you can use the below command.

```shell-session
waypoint install -platform=docker -accept-tos -- -vvv -disable-ui
```

-> **Note:** Only _one_ Waypoint server needs to be installed and run
for any group of people using Waypoint together. If you are a day-to-day
Expand Down
1 change: 1 addition & 0 deletions website/content/docs/server/run/maintenance.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ The Waypoint server stores data into a single `data.db` file.
For `waypoint install`-based servers:

- **Docker** - `/data/data.db`
- **ECS** - `/waypoint-data/data.db`
- **Kubernetes** - `/data/data.db`
- **Nomad** - `/alloc/data.db`

Expand Down
2 changes: 1 addition & 1 deletion website/content/plugins/aws-ec2.mdx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
layout: plugins
page_title: 'Plugin: AWS EC2'
description: 'Build, Deploy, and Release on Kubernetes'
description: 'Build, Deploy, and Release on AWS EC2'
---

# AWS EC2
Expand Down