Skip to content

Commit a9f93e0

Browse files
committed
[ci] add cross compiling of cli for releases
1 parent e9b60cd commit a9f93e0

File tree

3 files changed

+49
-12
lines changed

3 files changed

+49
-12
lines changed

.github/workflows/dev.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ jobs:
1818
SHUTUP: 1
1919
timeout-minutes: 15
2020
run: |
21-
dagger call -v build-cli --src=.
21+
dagger call -v build-cli --src=. --platform=linux/amd64

.github/workflows/main.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ jobs:
1919
SHUTUP: 1
2020
timeout-minutes: 15
2121
run: |
22-
dagger call -v build-cli --src=.
22+
dagger call -v build-cli --src=. --platform=linux/amd64
2323
dagger call -v publish-images --src=. --tag=latest --registry-password=env:APOXY_DOCKERHUB_PASSWORD

ci/main.go

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,20 @@ func (m *ApoxyCli) BuilderContainer(ctx context.Context, src *dagger.Directory)
100100
func (m *ApoxyCli) BuildCLI(
101101
ctx context.Context,
102102
src *dagger.Directory,
103+
platform string,
103104
) *dagger.Container {
105+
p := dagger.Platform(platform)
106+
goarch := archOf(p)
107+
os := osOf(p)
108+
104109
builder := m.BuilderContainer(ctx, src)
105110
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").
107117
WithExec([]string{"go", "build", "-o", "/apoxy", "-ldflags", "-s -w", "."})
108118
}
109119

@@ -114,7 +124,10 @@ func (m *ApoxyCli) PublishGithubRelease(
114124
githubToken *dagger.Secret,
115125
tag string,
116126
) *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")
118131

119132
return dag.Container().
120133
From("ubuntu:22.04").
@@ -126,7 +139,10 @@ func (m *ApoxyCli) PublishGithubRelease(
126139
WithExec([]string{"mv", "gh_2.62.0_linux_amd64/bin/gh", "/usr/local/bin/gh"}).
127140
WithExec([]string{"rm", "-rf", "gh_2.62.0_linux_amd64", "gh_2.62.0_linux_amd64.tar.gz"}).
128141
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")).
130146
WithExec([]string{
131147
"gh", "release", "create",
132148
tag,
@@ -137,7 +153,28 @@ func (m *ApoxyCli) PublishGithubRelease(
137153
WithExec([]string{
138154
"gh", "release", "upload",
139155
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",
141178
"--clobber",
142179
"--repo", "github.com/apoxy-dev/apoxy-cli",
143180
})
@@ -202,6 +239,10 @@ func archOf(p dagger.Platform) string {
202239
return platforms.MustParse(string(p)).Architecture
203240
}
204241

242+
func osOf(p dagger.Platform) string {
243+
return platforms.MustParse(string(p)).OS
244+
}
245+
205246
// BuildBackplane builds a backplane binary.
206247
func (m *ApoxyCli) BuildBackplane(
207248
ctx context.Context,
@@ -220,13 +261,9 @@ func (m *ApoxyCli) BuildBackplane(
220261
WithMountedCache("/go/pkg/mod", dag.CacheVolume("go-mod-"+goarch)).
221262
WithEnvVariable("GOMODCACHE", "/go/pkg/mod").
222263
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").
226265
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))).
230267
WithExec([]string{"go", "build", "-ldflags", "-v -linkmode=external", "-o", bpOut, "./cmd/backplane"}).
231268
WithExec([]string{"go", "build", "-ldflags", "-v -linkmode=external", "-o", dsOut, "./cmd/dial-stdio"})
232269

0 commit comments

Comments
 (0)