+908
-1915
lines changedFilter options
+908
-1915
lines changed Original file line number Diff line number Diff line change
@@ -20,3 +20,4 @@ example/dazzle__*.Dockerfile
20
20
# dive log
21
21
dive.logdazzle
22
22
dazzle
23
+
!pkg/dazzle
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ builds:
3
3
env:
4
4
- CGO_ENABLED=0
5
5
ldflags:
6
-
- -s -w -X github.com/32leaves/dazzle/cmd/core.version={{.Version}}-{{.ShortCommit}}
6
+
- -s -w -X github.com/csweichel/dazzle/cmd/core.version={{.Version}}-{{.ShortCommit}}
7
7
- id: dazzle-util
8
8
env:
9
9
- CGO_ENABLED=0
@@ -12,7 +12,7 @@ builds:
12
12
flags:
13
13
- -tags=util
14
14
ldflags:
15
-
- -s -w -X github.com/32leaves/dazzle/cmd/util.version={{.Version}}-{{.ShortCommit}}
15
+
- -s -w -X github.com/csweichel/dazzle/cmd/util.version={{.Version}}-{{.ShortCommit}}
16
16
archives:
17
17
- id: dazzle
18
18
replacements:
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
1
1
<img src="logo.png" width="100">
2
2
3
-
[](https://gitpod.io/#https://github.com/32leaves/dazzle)
4
-
[](https://goreportcard.com/report/github.com/32leaves/dazzle)
3
+
[](https://gitpod.io/#https://github.com/csweichel/dazzle)
4
+
[](https://goreportcard.com/report/github.com/csweichel/dazzle)
5
5
[](https://masterminds.github.io/stability/experimental.html)
6
6
7
7
dazzle is a rather experimental Docker image builder. Its goal is to build independent layers where a change to one layer does *not* invalidate the ones sitting "above" it. To this end, dazzle uses black magic.
Original file line number Diff line number Diff line change
@@ -21,138 +21,44 @@
21
21
package core
22
22
23
23
import (
24
-
"encoding/xml"
25
-
"fmt"
26
-
"io/ioutil"
27
-
"os"
24
+
"context"
28
25
29
-
"github.com/32leaves/dazzle/pkg/dazzle"
30
-
"github.com/32leaves/dazzle/pkg/fancylog"
31
-
"github.com/32leaves/dazzle/pkg/test"
26
+
"github.com/csweichel/dazzle/pkg/dazzle"
27
+
"github.com/csweichel/dazzle/pkg/fancylog"
28
+
"github.com/moby/buildkit/client"
32
29
log "github.com/sirupsen/logrus"
33
30
"github.com/spf13/cobra"
34
31
)
35
32
36
33
// buildCmd represents the build command
37
34
var buildCmd = &cobra.Command{
38
-
Use: "build [context]",
35
+
Use: "build <target-ref> <context>",
39
36
Short: "Builds a Docker image with independent layers",
40
-
Args: cobra.MaximumNArgs(1),
37
+
Args: cobra.MinimumNArgs(2),
41
38
RunE: func(cmd *cobra.Command, args []string) error {
42
39
formatter := &fancylog.Formatter{}
43
40
log.SetFormatter(formatter)
44
41
45
-
var wd string
46
-
if len(args) > 0 {
47
-
wd = args[0]
48
-
49
-
if stat, err := os.Stat(wd); os.IsNotExist(err) || !stat.IsDir() {
50
-
return fmt.Errorf("context %s must be a directory", wd)
51
-
}
52
-
} else {
53
-
var err error
54
-
wd, err = os.Getwd()
55
-
if err != nil {
56
-
return err
57
-
}
58
-
}
59
-
60
-
dfn, err := cmd.Flags().GetString("file")
61
-
if err != nil {
62
-
return err
63
-
}
64
-
tag, err := cmd.Flags().GetString("tag")
65
-
if err != nil {
66
-
return err
67
-
}
68
-
repo, err := cmd.Flags().GetString("repository")
42
+
var (
43
+
targetref = args[0]
44
+
wd = args[1]
45
+
)
46
+
prj, err := dazzle.LoadFromDir(wd)
69
47
if err != nil {
70
48
return err
71
49
}
72
-
repoChanged := cmd.Flags().Changed("repository")
73
-
if !repoChanged {
74
-
log.Warn("Using dazzle without --repository will likely produce incorrect results!")
75
-
}
76
50
77
-
env, err := dazzle.NewEnvironment()
51
+
sckt, _ := cmd.Flags().GetString("addr")
52
+
cl, err := client.New(context.Background(), sckt, client.WithFailFast())
78
53
if err != nil {
79
-
log.Fatal(err)
80
-
}
81
-
env.Formatter = formatter
82
-
83
-
log.WithField("version", version).Debug("this is dazzle")
84
-
85
-
cfg := dazzle.BuildConfig{
86
-
Env: env,
87
-
BuildImageRepo: repo,
88
-
}
89
-
90
-
res, err := dazzle.Build(cfg, wd, dfn, tag)
91
-
logBuildResult(res)
92
-
testXMLOutput, _ := cmd.Flags().GetString("output-test-xml")
93
-
if testXMLOutput != "" {
94
-
serr := saveTestXMLOutput(res, testXMLOutput)
95
-
if serr != nil {
96
-
log.WithError(serr).Error("cannot save test result")
97
-
}
98
-
}
99
-
if err != nil {
100
-
log.Fatal(err)
54
+
return err
101
55
}
102
-
103
-
return nil
56
+
return prj.Build(context.Background(), cl, targetref)
104
57
},
105
58
}
106
59
107
60
func init() {
108
61
rootCmd.AddCommand(buildCmd)
109
62
110
-
buildCmd.Flags().StringP("file", "f", "Dockerfile", "name of the Dockerfile")
111
-
buildCmd.Flags().StringP("tag", "t", "dazzle-built:latest", "tag of the resulting image")
112
-
buildCmd.Flags().StringP("repository", "r", "dazzle-work", "name of the Docker repository to work in (e.g. eu.gcr.io/someprj/dazzle-work)")
113
-
buildCmd.Flags().String("output-test-xml", "", "save the test results as JUnit XML file")
114
-
}
115
-
116
-
func logBuildResult(res *dazzle.BuildResult) {
117
-
if res == nil {
118
-
return
119
-
}
120
-
121
-
log.Info("build done")
122
-
log.WithField("size", res.BaseImage.Size).Debugf("base layer: %s", res.BaseImage.Ref)
123
-
for _, l := range res.Layers {
124
-
log.WithField("size", l.Size).WithField("ref", l.Ref).Debugf(" layer %s", l.LayerName)
125
-
}
126
-
}
127
-
128
-
func saveTestXMLOutput(res *dazzle.BuildResult, fn string) error {
129
-
if res == nil {
130
-
return nil
131
-
}
132
-
133
-
var r test.Results
134
-
for _, l := range res.Layers {
135
-
ltr := l.TestResult
136
-
if ltr == nil {
137
-
continue
138
-
}
139
-
140
-
for _, tr := range ltr.Result {
141
-
ttr := *tr
142
-
ttr.Desc = fmt.Sprintf("%s: %s", l.LayerName, tr.Desc)
143
-
r.Result = append(r.Result, &ttr)
144
-
}
145
-
}
146
-
147
-
fc, err := xml.Marshal(r)
148
-
if err != nil {
149
-
return err
150
-
}
151
-
152
-
err = ioutil.WriteFile(fn, fc, 0644)
153
-
if err != nil {
154
-
return err
155
-
}
156
-
157
-
return nil
63
+
buildCmd.Flags().String("addr", "unix:///run/buildkit/buildkitd.sock", "address of buildkitd")
158
64
}
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4