Skip to content

Commit cfa178e

Browse files
leonardocemnencia
andauthored
feat: architecture detection (#106)
Signed-off-by: Leonardo Cecchi <[email protected]> Signed-off-by: Marco Nenciarini <[email protected]> Co-authored-by: Marco Nenciarini <[email protected]>
1 parent 3923866 commit cfa178e

File tree

3 files changed

+37
-22
lines changed

3 files changed

+37
-22
lines changed

protoc-gen-go-grpc/dagger/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module dagger/protoc-gen-go-grpc
33
go 1.24.0
44

55
require (
6-
github.com/99designs/gqlgen v0.17.79
6+
github.com/99designs/gqlgen v0.17.80
77
github.com/Khan/genqlient v0.8.1
88
github.com/vektah/gqlparser/v2 v2.5.30
99
golang.org/x/sync v0.17.0

protoc-gen-go-grpc/dagger/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
github.com/99designs/gqlgen v0.17.79 h1:RTsJZtdzcfROeWdt42NGMIabIbiBn69YyVmLEAuxtnA=
2-
github.com/99designs/gqlgen v0.17.79/go.mod h1:vgNcZlLwemsUhYim4dC1pvFP5FX0pr2Y+uYUoHFb1ig=
1+
github.com/99designs/gqlgen v0.17.80 h1:S64VF9SK+q3JjQbilgdrM0o4iFQgB54mVQ3QvXEO4Ek=
2+
github.com/99designs/gqlgen v0.17.80/go.mod h1:vgNcZlLwemsUhYim4dC1pvFP5FX0pr2Y+uYUoHFb1ig=
33
github.com/Khan/genqlient v0.8.1 h1:wtOCc8N9rNynRLXN3k3CnfzheCUNKBcvXmVv5zt6WCs=
44
github.com/Khan/genqlient v0.8.1/go.mod h1:R2G6DzjBvCbhjsEajfRjbWdVglSH/73kSivC9TLWVjU=
55
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883 h1:bvNMNQO63//z+xNgfBlViaCIJKLlCJ6/fmUseuG0wVQ=

protoc-gen-go-grpc/dagger/main.go

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"context"
77
"fmt"
88
"path"
9+
"runtime"
910
"strings"
1011

1112
"dagger/protoc-gen-go-grpc/internal/dagger"
@@ -17,29 +18,43 @@ type ProtocGenGoGRPC struct {
1718
}
1819

1920
func New(
20-
// Custom image to use to run protoc.
21-
// +optional
22-
// renovate image: datasource=docker depName=golang versioning=docker
23-
// +default="golang:1.24.5-bookworm"
21+
ctx context.Context,
22+
// Custom image to use to run protoc.
23+
// +optional
24+
// renovate image: datasource=docker depName=golang versioning=docker
25+
// +default="golang:1.24.5-bookworm"
2426
goImage string,
25-
// +optional
26-
// renovate: datasource=github-tags depName=protocolbuffers/protobuf versioning="regex:^v?(?<major>\\d+)\\.(?<minor>\\d+)$"
27-
// +default="v30.2"
27+
// +optional
28+
// renovate: datasource=github-tags depName=protocolbuffers/protobuf versioning="regex:^v?(?<major>\\d+)\\.(?<minor>\\d+)$"
29+
// +default="v32.1"
2830
protobufVersion string,
29-
// +optional
30-
// renovate: datasource=go depName=google.golang.org/protobuf/cmd/protoc-gen-go versioning=semver
31-
// +default="v1.36.6"
31+
// +optional
32+
// renovate: datasource=go depName=google.golang.org/protobuf/cmd/protoc-gen-go versioning=semver
33+
// +default="v1.36.6"
3234
protocGenGoVersion string,
33-
// +optional
34-
// renovate: datasource=go depName=google.golang.org/grpc/cmd/protoc-gen-go-grpc versioning=semver
35-
// +default="v1.5.1"
35+
// +optional
36+
// renovate: datasource=go depName=google.golang.org/grpc/cmd/protoc-gen-go-grpc versioning=semver
37+
// +default="v1.5.1"
3638
protocGenGoGRPCVersion string,
37-
) *ProtocGenGoGRPC {
38-
protobufRelURL := fmt.Sprintf("https://github.com/protocolbuffers/protobuf/releases/download/%v/protoc-%v-linux-x86_64.zip",
39-
protobufVersion, strings.TrimPrefix(protobufVersion, "v"))
40-
39+
) (*ProtocGenGoGRPC, error) {
40+
architecturesMap := map[string]string{
41+
"arm64": "aarch_64",
42+
"amd64": "x86_64",
43+
"ppc": "ppcle_64",
44+
"s390x": "s390_64",
45+
}
4146
protobuf := dag.Container().
42-
From(goImage).
47+
From(goImage)
48+
49+
architecture := runtime.GOARCH
50+
if remappedArchitecture, ok := architecturesMap[architecture]; ok {
51+
architecture = remappedArchitecture
52+
}
53+
54+
protobufRelURL := fmt.Sprintf("https://github.com/protocolbuffers/protobuf/releases/download/%v/protoc-%v-linux-%v.zip",
55+
protobufVersion, strings.TrimPrefix(protobufVersion, "v"), architecture)
56+
57+
protobuf = protobuf.
4358
WithExec([]string{"apt", "update"}).
4459
WithExec([]string{"apt", "install", "-y", "unzip"}).
4560
WithExec([]string{"curl", "-LO", protobufRelURL}).
@@ -54,7 +69,7 @@ func New(
5469

5570
return &ProtocGenGoGRPC{
5671
Ctr: protobuf,
57-
}
72+
}, nil
5873
}
5974

6075
// Container get the current container

0 commit comments

Comments
 (0)