Skip to content

Commit

Permalink
chore(backend): clean up backend code generation (#5116)
Browse files Browse the repository at this point in the history
* chore(backend): tidy go.mod and update tools.go

* go install, instead of go get

* fix problems reported by go vet

* simplify some ide reported redundant syntax

* license is not required for generated code

* remove licenses for generated code

* cleanup

* remove license more

* rm unused BUILD.bazel files

* fixed generate_api.sh

* reimport error.proto
  • Loading branch information
Bobgy committed Feb 9, 2021
1 parent 9b4e37b commit 3d40bba
Show file tree
Hide file tree
Showing 263 changed files with 83 additions and 4,753 deletions.
8 changes: 0 additions & 8 deletions BUILD.bazel

This file was deleted.

26 changes: 0 additions & 26 deletions api/v2alpha1/BUILD.bazel

This file was deleted.

1 change: 0 additions & 1 deletion backend/api/auth.proto
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package api;

import "google/api/annotations.proto";
import "google/protobuf/empty.proto";
import "backend/api/error.proto";
import "protoc-gen-swagger/options/annotations.proto";

option (grpc.gateway.protoc_gen_swagger.options.openapiv2_swagger) = {
Expand Down
6 changes: 1 addition & 5 deletions backend/api/build_kfp_server_api_python_package.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash -e
#
# Copyright 2018-2020 Google LLC
# Copyright 2018-2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -66,10 +66,6 @@ pushd "$DIR"
python3 setup.py --quiet sdist
popd

echo "Adding license header for generated python files in $DIR."
go install github.com/google/addlicense
addlicense "$DIR"

echo "Run the following commands to update the package on PyPI"
echo "python3 -m pip install twine"
echo "python3 -m twine upload --username kubeflow-pipelines $DIR/dist/*"
Expand Down
30 changes: 14 additions & 16 deletions backend/api/generate_api.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

# Copyright 2018-2020 Google LLC
# Copyright 2018-2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,10 +28,9 @@ if [ -z "$VERSION" ]; then
echo "ERROR: $REPO_ROOT/VERSION is empty"
exit 1
fi
TMP_DIR="$(mktemp -d)"

BAZEL_BINDIR=$(bazel info bazel-bin)
SWAGGER_CMD=${DIR}/../../bazel-bin/external/com_github_go_swagger/cmd/swagger/*stripped/swagger
AUTOGEN_CMD="${DIR}/../../bazel-bin/external/com_github_mbrukman_autogen/autogen_tool"
GENERATED_GO_PROTO_FILES="${BAZEL_BINDIR}/backend/api/api_generated_go_sources/src/github.com/kubeflow/pipelines/backend/api/go_client/*.go"

# TODO this script should be able to be run from anywhere, not just within .../backend/api/
Expand All @@ -40,19 +39,16 @@ GENERATED_GO_PROTO_FILES="${BAZEL_BINDIR}/backend/api/api_generated_go_sources/s
rm -r -f ${DIR}/go_http_client/*
rm -r -f ${DIR}/go_client/*

# Build required tools.
bazel build @com_github_mbrukman_autogen//:autogen_tool
bazel build @com_github_go_swagger//cmd/swagger

# Build .pb.go and .gw.pb.go files from the proto sources.
bazel build //backend/api:api_generated_go_sources

mkdir -p ${DIR}/go_client

# Copy the generated files into the source tree and add license.
for f in $GENERATED_GO_PROTO_FILES; do
target=${DIR}/go_client/$(basename ${f})
cp $f $target
chmod 766 $target
${AUTOGEN_CMD} -i --no-tlc -c "Google LLC" -l apache $target
done

# Generate and copy back into source tree .swagger.json files.
Expand All @@ -68,6 +64,16 @@ jq -s '
.info.license = { "name": "Apache 2.0", "url": "https://raw.githubusercontent.com/kubeflow/pipelines/master/LICENSE" }
' ${DIR}/swagger/{run,job,pipeline,experiment,pipeline.upload,healthz}.swagger.json > "${DIR}/swagger/kfp_api_single_file.swagger.json"

# Reference: https://goswagger.io/install.html
SWAGGER_GO_VERSION=v0.18.0
pushd "${TMP_DIR}"
curl -LO "https://github.com/go-swagger/go-swagger/releases/download/${SWAGGER_GO_VERSION}/swagger_linux_amd64"
chmod +x swagger_linux_amd64
SWAGGER_CMD="${TMP_DIR}/swagger_linux_amd64"
popd

mkdir -p ${DIR}/go_http_client

# Generate Go HTTP client from the swagger files.
${SWAGGER_CMD} generate client \
-f ${DIR}/swagger/job.swagger.json \
Expand Down Expand Up @@ -134,11 +140,3 @@ sed -i -- 's/IntervalSecond string `json:"interval_second,omitempty"`/IntervalSe

# Executes the //go:generate directives in the generated code.
go generate ./...

# Add license to files in go_http_client.
find ${DIR}/go_http_client/ -name "*.go" -exec ${AUTOGEN_CMD} -i --no-tlc -c "Google LLC" -l apache {} \;

# Finally, run gazelle to add BUILD files for the generated code.
bazel run //:gazelle
# HACK: remove unnecessary BUILD.bazels
rm -f "$REPO_ROOT/sdk/python/kfp/components/structures/BUILD.bazel" "$REPO_ROOT/tools/metadatastore-upgrade/BUILD.bazel"
45 changes: 0 additions & 45 deletions backend/api/go_client/BUILD.bazel

This file was deleted.

86 changes: 36 additions & 50 deletions backend/api/go_client/auth.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 0 additions & 14 deletions backend/api/go_client/auth.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 0 additions & 14 deletions backend/api/go_client/error.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 0 additions & 14 deletions backend/api/go_client/error.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 0 additions & 14 deletions backend/api/go_client/experiment.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 0 additions & 14 deletions backend/api/go_client/experiment.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 3d40bba

Please sign in to comment.