Skip to content

Commit

Permalink
API release automation with go script (#8484)
Browse files Browse the repository at this point in the history
  • Loading branch information
Joerger authored Oct 28, 2021
1 parent 5463c79 commit 20da22c
Show file tree
Hide file tree
Showing 10 changed files with 2,991 additions and 8 deletions.
41 changes: 36 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,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 @@ -689,7 +707,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 @@ -883,17 +901,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;}')
vendor-api:
rm -rf vendor/github.com/gravitational/teleport/api
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); \
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 @@ -155,7 +155,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

0 comments on commit 20da22c

Please sign in to comment.