-
Notifications
You must be signed in to change notification settings - Fork 0
/
image_build.go
42 lines (33 loc) · 936 Bytes
/
image_build.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
package cli
import (
"context"
"github.com/archimoebius/fishler/util"
"github.com/docker/docker/client"
"github.com/spf13/cobra"
)
var BuildCmd = &cobra.Command{
Use: "build",
Short: "Build the fishler Docker image",
Long: `If the fishler Docker image is not yet built, build it. Use --force to rebuild.`,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
CallPersistentPreRun(cmd, args)
},
Run: func(cmd *cobra.Command, args []string) {
forceBuild, _ := cmd.Flags().GetBool("force")
dockerClient, err := client.NewClientWithOpts(
client.FromEnv,
client.WithAPIVersionNegotiation(),
)
if err != nil {
util.Logger.Error(err)
}
ctx := context.Background()
err = util.BuildFishler(dockerClient, ctx, forceBuild)
if err != nil {
util.Logger.Error(err)
}
},
}
func init() {
BuildCmd.Flags().BoolP("force", "f", false, "Force the fishler image to be re-built if it exists")
}