Skip to content

Commit

Permalink
add protoc Dockerfile and instructions
Browse files Browse the repository at this point in the history
Signed-off-by: Matthias Bertschy <[email protected]>
  • Loading branch information
matthyx committed Aug 29, 2024
1 parent 601bb90 commit 8e2d7ce
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,15 @@ The code generation script will give you warnings about API rule violations.
Don’t mind them. To address these warnings, add them to the exclusion list as
show in the updated upstream repo.

You will also see a warning about `generate-internal-groups.sh` being deprecated:
Now it's time to generate the protobuf code:
```
WARNING: generate-internal-groups.sh is deprecated.
WARNING: Please use k8s.io/code-generator/kube_codegen.sh instead.
docker buildx build --file build/protoc.Dockerfile --platform linux/amd64 --tag protoc --load .
docker run --rm -it -v "$(pwd):/work" protoc
mkdir -p github.com/kubescape/storage
ln -sf /work/pkg github.com/kubescape/storage/
/go/bin/go-to-protobuf --packages=github.com/kubescape/storage/pkg/apis/softwarecomposition/v1beta1 --go-header-file=./hack/boilerplate.go.txt --apimachinery-packages='-k8s.io/apimachinery/pkg/util/intstr,-k8s.io/apimachinery/pkg/api/resource,-k8s.io/apimachinery/pkg/runtime/schema,-k8s.io/apimachinery/pkg/runtime,-k8s.io/apimachinery/pkg/apis/meta/v1,-k8s.io/apimachinery/pkg/apis/meta/v1beta1,-k8s.io/api/core/v1,-k8s.io/api/rbac/v1' --proto-import=/go/src/k8s.io/kubernetes/staging/src/ --proto-import=/go/src/k8s.io/kubernetes/vendor
```

This is valid, and upstream has also been updated to use the latest code
generation script — `kube_codegen.sh`. However, as of now it breaks code
generation for us, and we had no opportunity to reconcile the changes.

Once the code generation finishes successfully, you should be able to run tests and build the binary with no errors:
```
go build -v ./...
Expand Down
13 changes: 13 additions & 0 deletions build/protoc.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM --platform=$BUILDPLATFORM golang:1.23-bookworm AS builder

ENV GO111MODULE=on CGO_ENABLED=0
WORKDIR /work

RUN git clone -q --depth 1 https://github.com/kubernetes/kubernetes.git /go/src/k8s.io/kubernetes
RUN go install github.com/gogo/protobuf/protoc-gen-gogo@latest
RUN go install golang.org/x/tools/cmd/goimports@latest
RUN go install k8s.io/code-generator/cmd/go-to-protobuf@latest
RUN apt-get update && apt-get install -y unzip
RUN wget -q -O /tmp/protoc.zip https://github.com/protocolbuffers/protobuf/releases/download/v28.0/protoc-28.0-linux-x86_64.zip && \
unzip -q /tmp/protoc.zip -d /usr/local && \
rm /tmp/protoc.zip

0 comments on commit 8e2d7ce

Please sign in to comment.