faster builds in tilt
parent
b637b9ed84
commit
6608130298
32
Tiltfile
32
Tiltfile
|
|
@ -40,25 +40,41 @@ helm_resource(
|
|||
|
||||
|
||||
|
||||
def bh_service(service="", port_forwards=[], devMode=True, labels=['2-services'], deps=['postgres']):
|
||||
def bh_service(service="", port_forwards=[], migrateDB=False, devMode=True, labels=['2-services'], deps=['postgres']):
|
||||
local_resource(
|
||||
'{}-go-compile'.format(service),
|
||||
'CGO_ENABELD=0 GOOS=linux GOARCH=amd64 go build -gcflags=\'-N -l\' -o .bin/{}-debug ./src/{}'.format(service, service),
|
||||
'CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -gcflags=\'-N -l\' -o .bin/{}-debug ./src/{}'.format(service, service),
|
||||
deps=['./src/{}'.format(service), './src/lib'],
|
||||
resource_deps=deps
|
||||
)
|
||||
|
||||
entry_cmd = [
|
||||
'/go/bin/dlv',
|
||||
'--headless',
|
||||
'--listen=0.0.0.0:2345',
|
||||
'--api-version=2',
|
||||
'--log',
|
||||
'--accept-multiclient',
|
||||
'--log-output=rpc',
|
||||
'exec',
|
||||
'/opt/{}-debug'.format(service),
|
||||
'--continue'
|
||||
]
|
||||
|
||||
if migrateDB:
|
||||
entry_cmd += ['--', '-migrate']
|
||||
|
||||
|
||||
docker_build_with_restart(
|
||||
ref="barretthousen/service-{}".format(service),
|
||||
dockerfile="./src/Dockerfile.dev-service",
|
||||
dockerfile="./src/Dockerfile.dev",
|
||||
context=".",
|
||||
entrypoint=['/go/bin/dlv', '--headless', '--listen=0.0.0.0:2345', '--api-version=2', '--log', '--accept-multiclient', '--log-output=rpc', 'exec', '/opt/{}-debug'.format(service), '--continue', '--' ],
|
||||
entrypoint=entry_cmd,
|
||||
build_args={
|
||||
"service": service
|
||||
},
|
||||
only = [
|
||||
'./.bin/{}-debug'.format(service),
|
||||
'./src/Dockerfile.dev-service'
|
||||
'./.bin/{}-debug'.format(service)
|
||||
],
|
||||
live_update=[
|
||||
sync('./.bin', '/opt')
|
||||
|
|
@ -74,8 +90,8 @@ def bh_service(service="", port_forwards=[], devMode=True, labels=['2-services']
|
|||
|
||||
|
||||
|
||||
bh_service(service="catalog", port_forwards=["5002:5001", "2346:2345"])
|
||||
bh_service(service="runner", port_forwards=[5001, 2345])
|
||||
bh_service(service="catalog", migrateDB=True, port_forwards=["5002:5001", "2346:2345"])
|
||||
bh_service(service="runner", migrateDB=True, port_forwards=[5001, 2345])
|
||||
|
||||
# bh_service(service="proxy-web", port_forwards=["8081:80"], deps=['ingress', 'local-catalog'])
|
||||
bh_service(service="proxy-admin", port_forwards=[
|
||||
|
|
|
|||
|
|
@ -12,20 +12,6 @@ spec:
|
|||
labels:
|
||||
service: catalog
|
||||
spec:
|
||||
initContainers:
|
||||
- name: catalog-db-migrate
|
||||
image: barretthousen/service-catalog
|
||||
command:
|
||||
- /opt/catalog
|
||||
args:
|
||||
- -migrate
|
||||
resources:
|
||||
limits:
|
||||
cpu: "250m"
|
||||
memory: "64Mi"
|
||||
volumeMounts:
|
||||
- mountPath: /config/
|
||||
name: catalog-config
|
||||
containers:
|
||||
- name: catalog
|
||||
image: barretthousen/service-catalog
|
||||
|
|
@ -34,6 +20,8 @@ spec:
|
|||
name: grpc
|
||||
command:
|
||||
- /opt/catalog
|
||||
args:
|
||||
- -migrate
|
||||
resources:
|
||||
limits:
|
||||
cpu: "250m"
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ spec:
|
|||
- /opt/proxy-admin
|
||||
resources:
|
||||
limits:
|
||||
memory: "64Mi"
|
||||
memory: "128Mi"
|
||||
cpu: "250m"
|
||||
volumeMounts:
|
||||
- name: proxy-admin-config
|
||||
|
|
@ -54,7 +54,7 @@ spec:
|
|||
http:
|
||||
paths:
|
||||
- pathType: Prefix
|
||||
path: "/"
|
||||
path: "/api/"
|
||||
backend:
|
||||
service:
|
||||
name: proxy-admin
|
||||
|
|
|
|||
|
|
@ -12,20 +12,6 @@ spec:
|
|||
labels:
|
||||
service: runner
|
||||
spec:
|
||||
initContainers:
|
||||
- name: runner-db-migrate
|
||||
image: barretthousen/service-runner
|
||||
command:
|
||||
- /opt/runner
|
||||
args:
|
||||
- -migrate
|
||||
resources:
|
||||
limits:
|
||||
cpu: "250m"
|
||||
memory: "64Mi"
|
||||
volumeMounts:
|
||||
- mountPath: /config/
|
||||
name: runner-config
|
||||
containers:
|
||||
- name: runner
|
||||
image: barretthousen/service-runner
|
||||
|
|
@ -34,6 +20,8 @@ spec:
|
|||
name: grpc
|
||||
command:
|
||||
- /opt/runner
|
||||
args:
|
||||
- -migrate
|
||||
resources:
|
||||
limits:
|
||||
cpu: "250m"
|
||||
|
|
|
|||
|
|
@ -7,17 +7,5 @@ spec:
|
|||
spec:
|
||||
containers:
|
||||
- name: catalog
|
||||
command:
|
||||
- /go/bin/dlv
|
||||
args:
|
||||
- --headless
|
||||
- --listen=0.0.0.0:2345
|
||||
- --api-version=2
|
||||
- --log
|
||||
- --accept-multiclient
|
||||
#- --log-output=rpc,dap
|
||||
- exec
|
||||
- /opt/catalog
|
||||
- --continue
|
||||
ports:
|
||||
- containerPort: 2345
|
||||
|
|
|
|||
|
|
@ -6,9 +6,8 @@ FROM alpine as development
|
|||
|
||||
ARG service
|
||||
|
||||
COPY bin/${service}-debug /opt/${service}-debug
|
||||
|
||||
COPY --from=builder /go/bin/dlv /go/bin/dlv
|
||||
COPY .bin/${service}-debug /opt/${service}-debug
|
||||
|
||||
ENV SERVICE=${service}
|
||||
|
||||
|
|
@ -44,8 +44,6 @@ func (app *catalogApp) Start(ctx context.Context) error {
|
|||
if err := kernel.MigrateDB(ctx, app.DB_Migrate, dbMigrateScript, "catalog"); err != nil {
|
||||
return fmt.Errorf("could not execute db migration: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
ioc := dig.New()
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ func init() {
|
|||
log.SetFlags(logFlags)
|
||||
|
||||
writer = os.NewFile(0, os.DevNull)
|
||||
|
||||
SetLogLevel(LevelError)
|
||||
}
|
||||
|
||||
const (
|
||||
|
|
@ -31,6 +33,8 @@ var (
|
|||
|
||||
type LogLevel int
|
||||
|
||||
var currentLogLevel LogLevel
|
||||
|
||||
const (
|
||||
LevelError LogLevel = iota
|
||||
LevelInfo
|
||||
|
|
@ -61,6 +65,7 @@ type Logger interface {
|
|||
}
|
||||
|
||||
func SetLogLevel(ll LogLevel) {
|
||||
currentLogLevel = ll
|
||||
for i := 0; i < len(loggers); i++ {
|
||||
target := writer
|
||||
|
||||
|
|
|
|||
|
|
@ -77,18 +77,18 @@ func MigrateDB(ctx context.Context, pg PostgresConnection, migrationFS embed.FS,
|
|||
}
|
||||
defer db.Close()
|
||||
|
||||
goose.SetTableName(fmt.Sprintf("bh_%s_migrations", migrationKey))
|
||||
goose.SetVerbose(currentLogLevel == LevelTrace)
|
||||
goose.SetBaseFS(migrationFS)
|
||||
|
||||
if err := goose.SetDialect("postgres"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
goose.SetBaseFS(migrationFS)
|
||||
|
||||
if migrationKey == "" {
|
||||
migrationKey = "public"
|
||||
}
|
||||
|
||||
goose.SetTableName(fmt.Sprintf("bh_%s_migrations", migrationKey))
|
||||
|
||||
path := "internal/data/postgres/migrations"
|
||||
if err := goose.Up(db, path); err != nil {
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ import (
|
|||
)
|
||||
|
||||
type (
|
||||
RunnerApp struct {
|
||||
runnerApp struct {
|
||||
LogLevel kernel.LogLevel `yaml:"log_level" env:"BH_LOG_LEVEL" env-default:"0" yaml-default:"0"`
|
||||
Port int `yaml:"port" env:"RUNNER_PORT"`
|
||||
CatalogEndpoint string `yaml:"catalog_endpoint" env:"RUNNER_CATALOG_ENDPOINT"`
|
||||
|
|
@ -40,21 +40,19 @@ var (
|
|||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
kernel.Run(context.Background(), &RunnerApp{
|
||||
kernel.Run(context.Background(), &runnerApp{
|
||||
CatalogEndpoint: "local-catalog:5001",
|
||||
LogLevel: kernel.LevelTrace,
|
||||
Port: 5001,
|
||||
})
|
||||
}
|
||||
|
||||
func (app *RunnerApp) Start(ctx context.Context) error {
|
||||
func (app *runnerApp) Start(ctx context.Context) error {
|
||||
if *migrate {
|
||||
kernel.InfoLog.Printf("running db migrations on %v", app.DB_Migrate)
|
||||
if err := kernel.MigrateDB(ctx, app.DB_Migrate, dbMigrateScript, "internal/data/postgres/migrations"); err != nil {
|
||||
if err := kernel.MigrateDB(ctx, app.DB_Migrate, dbMigrateScript, "runner"); err != nil {
|
||||
return fmt.Errorf("could not execute db migration: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
ioc := dig.New()
|
||||
|
|
@ -117,10 +115,10 @@ func (app *RunnerApp) Start(ctx context.Context) error {
|
|||
})
|
||||
}
|
||||
|
||||
func (app *RunnerApp) OnStop(ctx context.Context) {
|
||||
func (app *runnerApp) OnStop(ctx context.Context) {
|
||||
if err := kernel.StopGRPCServer(); err != nil {
|
||||
kernel.ErrorLog.Printf("could not gracefully stop GRPC server: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (app *RunnerApp) GetLogLevel() kernel.LogLevel { return app.LogLevel }
|
||||
func (app *runnerApp) GetLogLevel() kernel.LogLevel { return app.LogLevel }
|
||||
|
|
|
|||
Loading…
Reference in New Issue