Skip to content

Commit

Permalink
support macro substitution of app
Browse files Browse the repository at this point in the history
  • Loading branch information
xiejingru authored and ludanfeng committed Sep 28, 2020
1 parent e4e953d commit 61a376c
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 39 deletions.
24 changes: 8 additions & 16 deletions ami/native/native.go
Expand Up @@ -24,7 +24,6 @@ import (

"github.com/baetyl/baetyl/v2/ami"
"github.com/baetyl/baetyl/v2/config"
"github.com/baetyl/baetyl/v2/engine"
"github.com/baetyl/baetyl/v2/program"
)

Expand All @@ -33,24 +32,17 @@ func init() {
}

type nativeImpl struct {
logHostPath string
runHostPath string
mapping *native.ServiceMapping
portAllocator *native.PortAllocator
hostPathLibRun string
log *log.Logger
logHostPath string
runHostPath string
mapping *native.ServiceMapping
portAllocator *native.PortAllocator
log *log.Logger
}

func newNativeImpl(cfg config.AmiConfig) (ami.AMI, error) {
var hostPathLib string
if val := os.Getenv(context.KeyBaetylHostPathLib); val == "" {
err := os.Setenv(context.KeyBaetylHostPathLib, engine.DefaultHostPathLib)
if err != nil {
return nil, errors.Trace(err)
}
hostPathLib = engine.DefaultHostPathLib
} else {
hostPathLib = val
hostPathLib, err := context.HostPathLib()
if err != nil {
return nil, errors.Trace(err)
}
portAllocator, err := native.NewPortAllocator(cfg.Native.PortsRange.Start, cfg.Native.PortsRange.End)
if err != nil {
Expand Down
12 changes: 3 additions & 9 deletions cmd/apply.go
Expand Up @@ -72,15 +72,9 @@ func apply() {
if err != nil {
return
}
var hostPathLib string
if val := os.Getenv(context.KeyBaetylHostPathLib); val == "" {
err := os.Setenv(context.KeyBaetylHostPathLib, "/var/lib/baetyl")
if err != nil {
return
}
hostPathLib = "/var/lib/baetyl"
} else {
hostPathLib = val
hostPathLib, err := context.HostPathLib()
if err != nil {
return
}

// download data
Expand Down
14 changes: 3 additions & 11 deletions engine/engine.go
Expand Up @@ -4,7 +4,6 @@ import (
"crypto/md5"
"fmt"
"net"
"os"
"path/filepath"
"strconv"
gosync "sync"
Expand Down Expand Up @@ -32,7 +31,6 @@ const (
SystemCertVolumePrefix = "baetyl-cert-volume-"
SystemCertSecretPrefix = "baetyl-cert-secret-"
SystemCertPath = "/var/lib/baetyl/system/certs"
DefaultHostPathLib = "/var/lib/baetyl"
)

//go:generate mockgen -destination=../mock/engine.go -package=mock -source=engine.go Engine
Expand Down Expand Up @@ -66,15 +64,9 @@ func NewEngine(cfg config.Config, sto *bh.Store, nod *node.Node, syn sync.Sync,
mode := context.RunMode()
log.L().Info("app running mode", log.Any("mode", mode))

var hostPathLib string
if val := os.Getenv(context.KeyBaetylHostPathLib); val == "" {
err := os.Setenv(context.KeyBaetylHostPathLib, DefaultHostPathLib)
if err != nil {
return nil, errors.Trace(err)
}
hostPathLib = DefaultHostPathLib
} else {
hostPathLib = val
hostPathLib, err := context.HostPathLib()
if err != nil {
return nil, errors.Trace(err)
}
am, err := ami.NewAMI(mode, cfg.AMI)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -6,7 +6,7 @@ replace github.com/kardianos/service => github.com/baetyl/service v0.0.0-2020091

require (
github.com/StackExchange/wmi v0.0.0-20190523213315-cbe66965904d // indirect
github.com/baetyl/baetyl-go/v2 v2.0.51
github.com/baetyl/baetyl-go/v2 v2.0.54
github.com/go-ole/go-ole v1.2.4 // indirect
github.com/golang/mock v1.3.1
github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Expand Up @@ -31,8 +31,8 @@ github.com/abiosoft/readline v0.0.0-20180607040430-155bce2042db/go.mod h1:rB3B4r
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/baetyl/baetyl-go/v2 v2.0.51 h1:IizOAR5+PbOp9qeuxtPjgxwPIlxhWN6AxmjcHI0XtZM=
github.com/baetyl/baetyl-go/v2 v2.0.51/go.mod h1:ETX1SbGqT1I4miZoCVb7wwa6HCH639xat8j+4lVabtQ=
github.com/baetyl/baetyl-go/v2 v2.0.54 h1:53zpASFms/HWaWNBkyH4zmJYs3/GBJIfHRviMmqQpT8=
github.com/baetyl/baetyl-go/v2 v2.0.54/go.mod h1:ETX1SbGqT1I4miZoCVb7wwa6HCH639xat8j+4lVabtQ=
github.com/baetyl/service v0.0.0-20200910124134-20fdd363fbd5 h1:xuq1KQEwE5xP3gWTvo2gYJKuu7uM2OtRAZmnG3LqtHI=
github.com/baetyl/service v0.0.0-20200910124134-20fdd363fbd5/go.mod h1:RrJI2xn5vve/r32U5suTbeaSGoMU6GbNPoj36CVYcHc=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
Expand Down

0 comments on commit 61a376c

Please sign in to comment.