Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update codegen base image #4968

Merged
merged 3 commits into from
Jun 13, 2024
Merged

Update codegen base image #4968

merged 3 commits into from
Jun 13, 2024

Conversation

ffjlabo
Copy link
Member

@ffjlabo ffjlabo commented Jun 12, 2024

What this PR does / why we need it:

I changed the codegen's base image from golang:1.20.4-alpine3.16 to golang:1.22.4 to keep using protoc-gen-js.
This change requires updating the go version to 1.22.x.

fixes

  • Update the base image from golang:1.20.4-alpine3.16 to golang:1.22.4.
  • Get protoc-gen-js from the github releases directly.
  • Update the generated code using the image.

Why I changed from alpine to debian

We use protoc-gen-js in the codegen container.
protoc-gen-js is no longer installed by default after protobuf 3.20.
protocolbuffers/protobuf-javascript#127 (comment)

Also, protobuf, which provides protoc-gen-js, is no longer provided after alpine 3.16.
cf. alpine 3.16
cf. alpine 3.17
This is the problem with updating the go version because the alpine-based go 1.22.x image uses the alpine after version 16.

I think there are two patterns to avoid this problem for now.

  1. Build protoc-gen-js by using bazel.
  2. Get protoc-gen-js from the github releases directly.

But we couldn't choose both of them while using alpine-based image.
The bazel doesn't expect to be used on the alpine linux.
Also we couldn't use the released binary because of the glibc dependency.

Why choosing to get protoc-gen-js from the github releases directly

The build time with Bazel is too long—more than 30 minutes.
So I decided to get protoc-gen-js from the github releases directly.

Which issue(s) this PR fixes:

Part of #4874

Does this PR introduce a user-facing change?:

  • How are users affected by this change:
  • Is this breaking change:
  • How to migrate (if breaking change):

Copy link

codecov bot commented Jun 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 29.32%. Comparing base (8129078) to head (b72f8a4).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4968      +/-   ##
==========================================
- Coverage   29.34%   29.32%   -0.02%     
==========================================
  Files         323      323              
  Lines       40984    40984              
==========================================
- Hits        12027    12020       -7     
- Misses      27997    28002       +5     
- Partials      960      962       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

…and use protoc-gen-js

Signed-off-by: Yoshiki Fujikane <[email protected]>
Signed-off-by: Yoshiki Fujikane <[email protected]>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about adding these files that protoc-gen-js generated as linguist-generated=true with .gitattributes
The file patterns can be specified as the same as the .gitignore file, so we may be able to mark these files with one-line such as **/*_pb.js linguist-generated=true

ref; https://docs.github.com/en/repositories/working-with-files/managing-files/customizing-how-changed-files-appear-on-github

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the comment! It looks good to me.
Added b72f8a4

@ffjlabo
Copy link
Member Author

ffjlabo commented Jun 12, 2024

The result

I tried it on my machine, and it works well.

  • build the image
  • execute make/gen with using the image
%docker built tool/codegen -t codegen-debian
% make gen/code                                                                                                                                                                                                    
# NOTE: Specify a specific version temporally until the next release.
docker run --rm -v /Users/s14218/oss/pipe-cd/pipecd:/repo -it --entrypoint ./tool/codegen/codegen.sh codegen-debian /repo #v0.44.0-38-g7229285

- pkg/model
deleting previously generated Go files...
successfully deleted
generating new Go files...
successfully generated

- pkg/app/server/service/apiservice
deleting previously generated Go files...
successfully deleted
generating new Go files...
successfully generated

- pkg/app/server/service/pipedservice
deleting previously generated Go files...
successfully deleted
generating new Go files...
successfully generated

- pkg/app/server/service/webservice
deleting previously generated Go files...
successfully deleted
generating new Go files...
successfully generated

- pkg/app/helloworld/service
deleting previously generated Go files...
successfully deleted
generating new Go files...
successfully generated

- pkg/plugin/api/v1alpha1/platform
deleting previously generated Go files...
successfully deleted
generating new Go files...
successfully generated

- pkg/app/pipedv1/cmd/piped/service
deleting previously generated Go files...
successfully deleted
generating new Go files...
successfully generated

- pkg/model
deleting previously generated JS files...
successfully deleted
generating new JS files...
successfully generated

- pkg/app/server/service/webservice
deleting previously generated JS files...
successfully deleted
generating new JS files...
successfully generated

- pkg/redis/redistest/redis.mock.go
generating mock...
go: downloading github.com/gomodule/redigo v2.0.0+incompatible
successfully generated

- pkg/datastore/datastoretest/datastore.mock.go
generating mock...
go: downloading golang.org/x/oauth2 v0.7.0
go: downloading google.golang.org/protobuf v1.33.0
go: downloading github.com/envoyproxy/protoc-gen-validate v0.10.1
go: downloading golang.org/x/crypto v0.21.0
successfully generated

- pkg/filestore/filestoretest/filestore.mock.go
generating mock...
successfully generated

- pkg/app/piped/platformprovider/kubernetes/kubernetestest/kubernetes.mock.go
generating mock...
go: downloading go.uber.org/zap v1.10.1-0.20190709142728-9a9fa7d4b5f0
go: downloading k8s.io/api v0.24.3
go: downloading k8s.io/apimachinery v0.24.3
go: downloading k8s.io/client-go v0.24.3
go: downloading sigs.k8s.io/yaml v1.2.0
go: downloading github.com/prometheus/client_golang v1.11.1
go: downloading golang.org/x/sync v0.1.0
go: downloading github.com/creasty/defaults v1.6.0
go: downloading github.com/golang/protobuf v1.5.3
go: downloading k8s.io/klog/v2 v2.60.1
go: downloading github.com/gogo/protobuf v1.3.2
go: downloading sigs.k8s.io/structured-merge-diff/v4 v4.2.1
go: downloading go.uber.org/atomic v1.7.0
go: downloading go.uber.org/multierr v1.2.0
go: downloading gopkg.in/yaml.v2 v2.4.0
go: downloading github.com/beorn7/perks v1.0.1
go: downloading github.com/cespare/xxhash/v2 v2.2.0
go: downloading github.com/prometheus/client_model v0.2.0
go: downloading github.com/prometheus/common v0.26.0
go: downloading github.com/prometheus/procfs v0.6.0
go: downloading github.com/google/gofuzz v1.1.0
go: downloading sigs.k8s.io/json v0.0.0-20211208200746-9f7c6b3444d2
go: downloading github.com/go-logr/logr v1.2.0
go: downloading github.com/google/gnostic v0.5.7-v3refs
go: downloading golang.org/x/net v0.23.0
go: downloading k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9
go: downloading github.com/imdario/mergo v0.3.12
go: downloading github.com/spf13/pflag v1.0.5
go: downloading golang.org/x/term v0.18.0
go: downloading gopkg.in/inf.v0 v0.9.1
go: downloading github.com/json-iterator/go v1.1.12
go: downloading github.com/matttproud/golang_protobuf_extensions v1.0.1
go: downloading k8s.io/kube-openapi v0.0.0-20220328201542-3ee0da9b0b42
go: downloading github.com/davecgh/go-spew v1.1.1
go: downloading golang.org/x/time v0.1.0
go: downloading golang.org/x/sys v0.18.0
go: downloading gopkg.in/yaml.v3 v3.0.1
go: downloading github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd
go: downloading github.com/modern-go/reflect2 v1.0.2
go: downloading golang.org/x/text v0.14.0
go: downloading github.com/go-openapi/swag v0.19.14
go: downloading github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822
go: downloading github.com/go-openapi/jsonreference v0.19.5
go: downloading github.com/emicklei/go-restful v2.16.0+incompatible
go: downloading github.com/PuerkitoBio/purell v1.1.1
go: downloading github.com/go-openapi/jsonpointer v0.19.5
go: downloading github.com/mailru/easyjson v0.7.6
go: downloading github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578
go: downloading github.com/josharian/intern v1.0.0
successfully generated

- pkg/cache/cachetest/cache.mock.go
generating mock...
successfully generated

- pkg/git/gittest/git.mock.go
generating mock...
successfully generated

- pkg/jwt/jwttest/jwt.mock.go
generating mock...
go: downloading github.com/golang-jwt/jwt v3.2.1+incompatible
successfully generated

- pkg/insight/insighttest/insight.mock.go
generating mock...
successfully generated

Successfully generated all code

@ffjlabo
Copy link
Member Author

ffjlabo commented Jun 12, 2024

📝 The workflow gen fails, but it's ok.
https://github.com/pipe-cd/pipecd/actions/runs/9478841298/job/26116105748?pr=4968

Currently, the workflow uses make/gen with the old version of codegen image.
https://github.com/pipe-cd/pipecd/blob/master/Makefile#L202

I will change the image hash in the Makefile after the PR is merged.

Comment on lines +44 to +53
# protoc-gen-js
# This is a workaround to use it https://github.com/protocolbuffers/protobuf-javascript/issues/127#issuecomment-1361047597
RUN for target in x86_64 aarch_64; do \
mkdir /protoc-gen-js-${target} && cd /protoc-gen-js-${target} \
&& wget https://github.com/protocolbuffers/protobuf-javascript/releases/download/v${PROTOC_GEN_JS_VER}/protobuf-javascript-${PROTOC_GEN_JS_VER}-linux-${target}.tar.gz \
&& tar xvfz protobuf-javascript-${PROTOC_GEN_JS_VER}-linux-${target}.tar.gz \
&& chmod +x bin/protoc-gen-js \
&& rm -rf protobuf-javascript-${PROTOC_GEN_JS_VER}-linux-${target}.tar.gz; \
done && \
mv /protoc-gen-js-aarch_64/ /protoc-gen-js-aarch64/
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Get the binary not only for x86_64 but also aarch_64 to check it on the local machine.

Signed-off-by: Yoshiki Fujikane <[email protected]>
@@ -15,7 +15,7 @@
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.27.1
// protoc v3.18.1
// protoc v3.21.12
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The *.pb.go changes are just a comment update for protoc version.

Comment on lines +16 to +22
var global =
(typeof globalThis !== 'undefined' && globalThis) ||
(typeof window !== 'undefined' && window) ||
(typeof global !== 'undefined' && global) ||
(typeof self !== 'undefined' && self) ||
(function () { return this; }).call(null) ||
Function('return this')();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes in *.pb.js are like this and the below.
I think it is ok because the web test is passed.

Comment on lines -1 to -14
// Copyright 2023 The PipeCD Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love this ❤️

@khanhtc1202
Copy link
Member

📝 The workflow gen fails, but it's ok. https://github.com/pipe-cd/pipecd/actions/runs/9478841298/job/26116105748?pr=4968

Currently, the workflow uses make/gen with the old version of codegen image. https://github.com/pipe-cd/pipecd/blob/master/Makefile#L202

I will change the image hash in the Makefile after the PR is merged.

Fyi, the current CI configuration is here: https://github.com/pipe-cd/pipecd/blob/master/.github/workflows/gen.yaml#L14

Copy link
Member

@khanhtc1202 khanhtc1202 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

Copy link
Contributor

@Warashi Warashi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@khanhtc1202 khanhtc1202 merged commit 7e27cad into master Jun 13, 2024
22 of 25 checks passed
@khanhtc1202 khanhtc1202 deleted the update-codegen-base-image branch June 13, 2024 02:28
@github-actions github-actions bot mentioned this pull request Jul 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants