@@ -100,10 +100,20 @@ func (m *ApoxyCli) BuilderContainer(ctx context.Context, src *dagger.Directory)
100
100
func (m * ApoxyCli ) BuildCLI (
101
101
ctx context.Context ,
102
102
src * dagger.Directory ,
103
+ platform string ,
103
104
) * dagger.Container {
105
+ p := dagger .Platform (platform )
106
+ goarch := archOf (p )
107
+ os := osOf (p )
108
+
104
109
builder := m .BuilderContainer (ctx , src )
105
110
return builder .
106
- WithEnvVariable ("CGO_ENABLED" , "1" ).
111
+ WithEnvVariable ("GOARCH" , goarch ).
112
+ WithEnvVariable ("GOOS" , os ).
113
+ WithMountedCache ("/go/pkg/mod" , dag .CacheVolume ("go-mod-" + goarch )).
114
+ WithEnvVariable ("GOMODCACHE" , "/go/pkg/mod" ).
115
+ WithMountedCache ("/go/build-cache" , dag .CacheVolume ("go-build-" + goarch )).
116
+ WithEnvVariable ("GOCACHE" , "/go/build-cache" ).
107
117
WithExec ([]string {"go" , "build" , "-o" , "/apoxy" , "-ldflags" , "-s -w" , "." })
108
118
}
109
119
@@ -114,7 +124,10 @@ func (m *ApoxyCli) PublishGithubRelease(
114
124
githubToken * dagger.Secret ,
115
125
tag string ,
116
126
) * dagger.Container {
117
- cliCtr := m .BuildCLI (ctx , src )
127
+ cliCtrLinuxAmd64 := m .BuildCLI (ctx , src , "linux/amd64" )
128
+ cliCtrLinuxArm64 := m .BuildCLI (ctx , src , "linux/arm64" )
129
+ cliCtrMacosAmd64 := m .BuildCLI (ctx , src , "darwin/amd64" )
130
+ cliCtrMacosArm64 := m .BuildCLI (ctx , src , "darwin/arm64" )
118
131
119
132
return dag .Container ().
120
133
From ("ubuntu:22.04" ).
@@ -126,7 +139,10 @@ func (m *ApoxyCli) PublishGithubRelease(
126
139
WithExec ([]string {"mv" , "gh_2.62.0_linux_amd64/bin/gh" , "/usr/local/bin/gh" }).
127
140
WithExec ([]string {"rm" , "-rf" , "gh_2.62.0_linux_amd64" , "gh_2.62.0_linux_amd64.tar.gz" }).
128
141
WithSecretVariable ("GITHUB_TOKEN" , githubToken ).
129
- WithFile ("/apoxy" , cliCtr .File ("/apoxy" )).
142
+ WithFile ("/apoxy-linux-amd64" , cliCtrLinuxAmd64 .File ("/apoxy" )).
143
+ WithFile ("/apoxy-linux-arm64" , cliCtrLinuxArm64 .File ("/apoxy" )).
144
+ WithFile ("/apoxy-darwin-amd64" , cliCtrMacosAmd64 .File ("/apoxy" )).
145
+ WithFile ("/apoxy-darwin-arm64" , cliCtrMacosArm64 .File ("/apoxy" )).
130
146
WithExec ([]string {
131
147
"gh" , "release" , "create" ,
132
148
tag ,
@@ -137,7 +153,28 @@ func (m *ApoxyCli) PublishGithubRelease(
137
153
WithExec ([]string {
138
154
"gh" , "release" , "upload" ,
139
155
tag ,
140
- "/apoxy" ,
156
+ "/apoxy-linux-amd64" ,
157
+ "--clobber" ,
158
+ "--repo" , "github.com/apoxy-dev/apoxy-cli" ,
159
+ }).
160
+ WithExec ([]string {
161
+ "gh" , "release" , "upload" ,
162
+ tag ,
163
+ "/apoxy-linux-arm64" ,
164
+ "--clobber" ,
165
+ "--repo" , "github.com/apoxy-dev/apoxy-cli" ,
166
+ }).
167
+ WithExec ([]string {
168
+ "gh" , "release" , "upload" ,
169
+ tag ,
170
+ "/apoxy-darwin-amd64" ,
171
+ "--clobber" ,
172
+ "--repo" , "github.com/apoxy-dev/apoxy-cli" ,
173
+ }).
174
+ WithExec ([]string {
175
+ "gh" , "release" , "upload" ,
176
+ tag ,
177
+ "/apoxy-darwin-arm64" ,
141
178
"--clobber" ,
142
179
"--repo" , "github.com/apoxy-dev/apoxy-cli" ,
143
180
})
@@ -202,6 +239,10 @@ func archOf(p dagger.Platform) string {
202
239
return platforms .MustParse (string (p )).Architecture
203
240
}
204
241
242
+ func osOf (p dagger.Platform ) string {
243
+ return platforms .MustParse (string (p )).OS
244
+ }
245
+
205
246
// BuildBackplane builds a backplane binary.
206
247
func (m * ApoxyCli ) BuildBackplane (
207
248
ctx context.Context ,
@@ -220,13 +261,9 @@ func (m *ApoxyCli) BuildBackplane(
220
261
WithMountedCache ("/go/pkg/mod" , dag .CacheVolume ("go-mod-" + goarch )).
221
262
WithEnvVariable ("GOMODCACHE" , "/go/pkg/mod" ).
222
263
WithMountedCache ("/go/build-cache" , dag .CacheVolume ("go-build-" + goarch )).
223
- WithEnvVariable ("GOCACHE" , "/go/build-cache" )
224
-
225
- builder = builder .
264
+ WithEnvVariable ("GOCACHE" , "/go/build-cache" ).
226
265
WithEnvVariable ("CGO_ENABLED" , "1" ).
227
- WithEnvVariable ("CC" , fmt .Sprintf ("zig-wrapper cc --target=%s-linux-musl" , canonArchFromGoArch (goarch )))
228
-
229
- builder = builder .
266
+ WithEnvVariable ("CC" , fmt .Sprintf ("zig-wrapper cc --target=%s-linux-musl" , canonArchFromGoArch (goarch ))).
230
267
WithExec ([]string {"go" , "build" , "-ldflags" , "-v -linkmode=external" , "-o" , bpOut , "./cmd/backplane" }).
231
268
WithExec ([]string {"go" , "build" , "-ldflags" , "-v -linkmode=external" , "-o" , dsOut , "./cmd/dial-stdio" })
232
269
0 commit comments