/
dev.go
59 lines (50 loc) 路 1.42 KB
/
dev.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// SPDX-License-Identifier: MIT
// Copyright (c) 2019 Hadrien Chauvin
// Package dev implements the "dev" steps of pipelines.
package dev
import (
"context"
"github.com/hchauvin/warp/pkg/config"
"github.com/hchauvin/warp/pkg/dev/browsersync"
"github.com/hchauvin/warp/pkg/dev/ksync"
"github.com/hchauvin/warp/pkg/dev/portforward"
"github.com/hchauvin/warp/pkg/k8s"
"github.com/hchauvin/warp/pkg/pipelines"
"github.com/hchauvin/warp/pkg/stacks/names"
"golang.org/x/sync/errgroup"
)
// PatchPipeline patches a pipeline depending on the "dev" steps.
func PatchPipeline(cfg *config.Config, setup *pipelines.Setup, pipeline *pipelines.Pipeline) error {
return ksync.PatchSetup(cfg, setup, pipeline)
}
// Exec executes the "dev" steps.
func Exec(
ctx context.Context,
cfg *config.Config,
pipeline *pipelines.Pipeline,
name names.Name,
setupName string,
k8sClient *k8s.K8s,
) error {
setup, err := pipeline.Setups.Get(setupName)
if err != nil {
return err
}
g, gctx := errgroup.WithContext(ctx)
if len(setup.Dev.Ksync) > 0 {
g.Go(func() error {
return ksync.Exec(gctx, cfg, setup.Dev.Ksync, name, k8sClient)
})
}
if len(setup.Dev.BrowserSync) > 0 {
g.Go(func() error {
return browsersync.Exec(gctx, cfg, setup.Dev.BrowserSync, name, k8sClient)
})
}
if len(setup.Dev.PortForward) > 0 {
g.Go(func() error {
return portforward.Exec(gctx, cfg, setup.Dev.PortForward, name, k8sClient)
})
}
return g.Wait()
}