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

API release automation with go script #8484

Merged
merged 14 commits into from
Oct 28, 2021
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 36 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,24 @@ version: $(VERSRC)
# This rule triggers re-generation of version files specified if Makefile changes.
$(VERSRC): Makefile
VERSION=$(VERSION) $(MAKE) -f version.mk setver
# Update api module path, but don't fail on error.
$(MAKE) update-api-module-path || true

# This rule updates the api module path to be in sync with the current api release version.
# e.g. github.com/gravitational/teleport/api/vX -> github.com/gravitational/teleport/api/vY
#
# It will immediately fail if:
# 1. A suffix is present in the version - e.g. "v7.0.0-alpha"
# 2. The major version suffix in the api module path hasn't changed. e.g:
# - v7.0.0 -> v7.1.0 - both use version suffix "/v7" - github.com/gravitational/teleport/api/v7
# - v0.0.0 -> v1.0.0 - both have no version suffix - github.com/gravitational/teleport/api
#
# Note: any build flags needed to compile go files (such as build tags) should be provided below.
.PHONY: update-api-module-path
update-api-module-path:
go run build.assets/update_api_module_path/main.go -tags "bpf fips pam roletester desktop_access_beta"
$(MAKE) update-vendor
$(MAKE) grpc

# make tag - prints a tag to use with git for the current version
# To put a new release on Github:
Expand Down Expand Up @@ -679,7 +697,7 @@ enter:
# grpc generates GRPC stubs from service definitions
.PHONY: grpc
grpc:
make -C build.assets grpc
$(MAKE) -C build.assets grpc

# buildbox-grpc generates GRPC stubs inside buildbox
.PHONY: buildbox-grpc
Expand Down Expand Up @@ -873,17 +891,30 @@ init-submodules-e: init-webapps-submodules-e
git submodule init e
git submodule update

# Update go.mod and vendor files.
.PHONY: update-vendor
update-vendor:
# update modules in api/
cd api && go mod tidy
# update modules in root directory
go mod tidy
go mod vendor
# delete the vendored api package. In its place
# create a symlink to the the original api package
rm -r vendor/github.com/gravitational/teleport/api
cd vendor/github.com/gravitational/teleport && ln -s ../../../../api api
$(MAKE) vendor-api

# When teleport vendors its dependencies, Go also vendors the local api sub module. To get
# around this issue, we replace the vendored api package with a symlink to the
# local module. The symlink should be in vendor/.../api or vendor/.../api/vX if X >= 2.
.PHONY: vendor-api
vendor-api: API_VENDOR_PATH := vendor/$(shell head -1 api/go.mod | awk '{print $$2;}')
zmb3 marked this conversation as resolved.
Show resolved Hide resolved
vendor-api:
Joerger marked this conversation as resolved.
Show resolved Hide resolved
rm -rf vendor/github.com/gravitational/teleport/api
zmb3 marked this conversation as resolved.
Show resolved Hide resolved
mkdir -p $(shell dirname $(API_VENDOR_PATH))
# make a relative link to the true api dir (without using `ln -r` for non-linux OS compatibility)
if [ -d $(shell dirname $(API_VENDOR_PATH))/../../../../../api/ ]; then \
ln -s ../../../../../api $(API_VENDOR_PATH); \
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't love the subtle difference between these two cases. Any way we can figure out the nasty relative path ahead of time?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For linux we could use ln -r and readlink, but I'm not sure what else we could do to keep this os independent. I tried searching a bit but didn't find anything.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to write a platform-independent version in Go, perhaps?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it possible to write a platform-independent version in Go, perhaps?

I think it's better to keep build steps and dev tools in bash/Make, or at least that's been the preference thus far. This PR itself is a bit of an edge case since updating the go module import path specifically benefits from using Go due to the golang.org/x/tools package. If we want to move towards go scripts or something similar, it should probably be a more discussed and deliberate effort.

else \
ln -s ../../../../api $(API_VENDOR_PATH); \
fi;

# update-webassets updates the minified code in the webassets repo using the latest webapps
# repo and creates a PR in the teleport repo to update webassets submodule.
Expand Down
4 changes: 3 additions & 1 deletion build.assets/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ RUN (git clone https://github.com/gogo/protobuf.git ${GOPATH}/src/github.com/gog
git reset --hard ${GOGO_PROTO_TAG} && \
make install)

ENV PROTO_INCLUDE "/usr/local/include":"${GOPATH}/src":"${GOPATH}/src/github.com/gogo/protobuf/protobuf":"${GOGOPROTO_ROOT}":"${GOGOPROTO_ROOT}/protobuf":"${GOPATH}/src/github.com/gravitational/teleport/lib/services"
# Note: protoc reads the proto files from /vendor/.../teleport/api/vX rather than
# /api because protoc does not understand go modules, and reads vX as a directory.
ENV PROTO_INCLUDE "/usr/local/include":"/go/src/github.com/gravitational/teleport/vendor":"/go/src/github.com/gogo/protobuf/protobuf":"${GOGOPROTO_ROOT}":"${GOGOPROTO_ROOT}/protobuf"

# Install PAM module and policies for testing.
COPY pam/ /opt/pam_teleport/
Expand Down
Loading