-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimage.cue
177 lines (161 loc) · 3.9 KB
/
image.cue
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package testers
import (
"strings"
"dagger.io/dagger"
"dagger.io/dagger/core"
"universe.dagger.io/docker"
"universe.dagger.io/git"
"universe.dagger.io/go"
)
Base: {
version: string
packages: [pkgName=string]: version: string | *""
// FIXME Basically a copy of alpine.#Build with a different image
// Should we create a special definition?
docker.#Build & {
steps: [
docker.#Pull & {
source: "index.docker.io/golang:\(version)-alpine"
},
for pkgName, pkg in packages {
docker.#Run & {
command: {
name: "apk"
args: ["add", "\(pkgName)\(pkg.version)"]
flags: {
"-U": true
"--no-cache": true
}
}
}
},
]
}
}
Build: {
// config
versions: {
cue: string
hof: string
dagger: string
go: string
testscript: string
"txtar-c": testscript
"txtar-x": testscript
}
// provide when cue version is 'local'
cuesource: dagger.#FS
// Go based image
base: Base & {
version: versions.go
packages: {
bash: {}
"docker-cli": {}
gcc: {}
git: {}
make: {}
"musl-dev": {}
python3: {}
tree: {}
}
}
gotools: {
[tool=string]: {
code: git.#Pull & {
remote: string
ref: versions["\(tool)"]
keepGitDir: true
}
commit: {
write: docker.#Run & {
input: base.output
command: {
name: "sh"
args: ["-c", "git rev-parse HEAD > /commit.txt"]
}
mounts: source: {
dest: "/src"
contents: code.output
}
workdir: "/src"
}
read: core.#ReadFile & {
input: write.output.rootfs
path: "/commit.txt"
}
}
build: go.#Build & {
container: input: base.output
source: code.output
package: "./cmd/\(tool)"
}
}
if versions.cue != "local" {
cue: code: remote: "https://github.com/cue-lang/cue"
}
cue: build: {
ldflags: strings.Join([
"-X cuelang.org/go/cmd/cue/cmd.version=\(versions.cue)",
], " ")
}
hof: {
code: remote: "https://github.com/hofstadter-io/hof"
build: {
ldflags: strings.Join([
"-X github.com/hofstadter-io/hof/cmd/hof/verinfo.Version=\(versions.hof)",
"-X github.com/hofstadter-io/hof/cmd/hof/verinfo.Commit=\(hof.commit.read.contents)",
], " ")
}
}
dagger: {
code: remote: "https://github.com/dagger/dagger"
build: {
ldflags: strings.Join([
"-X go.dagger.io/dagger/version.Version=\(versions.dagger)",
"-X go.dagger.io/dagger/version.Revision=\(dagger.commit.read.contents)",
], " ")
}
}
testscript: code: remote: "https://github.com/rogpeppe/go-internal"
"txtar-c": code: remote: "https://github.com/rogpeppe/go-internal"
"txtar-x": code: remote: "https://github.com/rogpeppe/go-internal"
}
localcue: _
if versions.cue == "local" {
localcue: go.#Build & {
container: input: base.output
source: cuesource
package: "./cmd/cue"
}
}
// collect the bins for looping
bins: [
gotools.hof.build.output,
gotools.dagger.build.output,
gotools.testscript.build.output,
gotools."txtar-c".build.output,
gotools."txtar-x".build.output,
if versions.cue == "local" { localcue.output },
if versions.cue != "local" { gotools.cue.build.output },
]
// add the binaries to the base image
copy: docker.#Build & {
steps: [{ input: base.output}, ...]
steps: [
for bin in bins {
docker.#Copy & {
contents: bin
dest: "/usr/local/bin"
}
},
if versions.cue == "local" {
docker.#Copy & {
contents: cuesource
dest: "/localcue"
}
},
]
}
// the final image users should reference
output: docker.#Image & copy.output
}