Override bootstrapper

Is there any way to override boot.yaml or values in boot.yaml at start time?

Overview

Bootstrapper support two kinds of ways to override bootstrapper configs.

  • Override config file (by --rkboot)
  • Override values in config file (by --rkset)

Quick start

1.Override bootstrapper config file

In order to override bootstrapper file path, --rkboot needs to be passed.

boot.yaml

---
grpc:
  - name: greeter
    port: 1949
    enabled: true
    enableReflection: true
    commonService:
      enabled: true

boot-override.yaml

---
grpc:
  - name: greeter
    port: 2008
    enabled: true
    enableReflection: true
    commonService:
      enabled: true

main.go

package main

import (
	"context"
	"github.com/rookie-ninja/rk-boot"
)

// Application entrance.
func main() {
	// Create a new boot instance.
	boot := rkboot.NewBoot()

	// Bootstrap
	boot.Bootstrap(context.Background())

	// Wait for shutdown sig
	boot.WaitForShutdownSig(context.Background())
}

Start server with --rkboot args

$ go build main.go
$ ./main --rkboot boot-override.yaml

Send request to 1949

$ grpcurl -plaintext localhost:1949 rk.api.v1.RkCommonService.Healthy
Failed to dial target host "localhost:1949": dial tcp [::1]:1949: connect: connection refused

Send request to 2008

$ grpcurl -plaintext localhost:2008 rk.api.v1.RkCommonService.Healthy
{
    "healthy": true
}

Cheers

2.Override values in boot.yaml

In order to override bootstrapper file path, --rkset needs to be passed.

Use comma to separate multiple overrides.

Type Example
Map app.description=“This is description”
List grpc[0].name=“alice”,grpc[0].port=8081

boot.yaml

---
grpc:
  - name: greeter
    port: 1949
    enabled: true
    enableReflection: true
    commonService:
      enabled: true

main.go

package main

import (
	"context"
	"github.com/rookie-ninja/rk-boot"
)

// Application entrance.
func main() {
	// Create a new boot instance.
	boot := rkboot.NewBoot()

	// Bootstrap
	boot.Bootstrap(context.Background())

	// Wait for shutdown sig
	boot.WaitForShutdownSig(context.Background())
}

Start server with --rkset args

$ go build main.go
$ ./main --rkset "grpc[0].port=2008"

Send request to 1949

$ grpcurl -plaintext localhost:1949 rk.api.v1.RkCommonService.Healthy
Failed to dial target host "localhost:1949": dial tcp [::1]:1949: connect: connection refused

Send request to 2008

$ grpcurl -plaintext localhost:2008 rk.api.v1.RkCommonService.Healthy
{
    "healthy": true
}

Cheers

Last modified September 24, 2021 : Update based on rk-boot:v1.2.4 (357cf4c)