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

Remove Bazel from cloud-provider-gcp #259

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
27 changes: 0 additions & 27 deletions .bazelrc

This file was deleted.

4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
bazel-*
MERGED_LICENSES

_output

.idea
19 changes: 0 additions & 19 deletions BUILD

This file was deleted.

40 changes: 40 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright 2021 The Kubernetes 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.

.EXPORT_ALL_VARIABLES:
OUT_DIR ?= _output
BIN_DIR := $(OUT_DIR)/bin

.PHONY: all
all: test bin images

.PHONY: clean
clean:
rm -rf _output

.PHONY: test
test:
./build/run-tests.sh

.PHONY: bin
bin:
./build/build-bin.sh

.PHONY: images
images: bin
./build/build-images.sh

.PHONY: release-tars
release-tars: bin images
./build/build-release-tars.sh
56 changes: 25 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,71 +1,60 @@
# cloud-provider-gcp

## Publishing gcp-controller-manager image
## Building Container Images

This command will build and publish
`gcr.io/k8s-image-staging/gcp-controller-manager:latest`:
`gcr.io/k8s-image-staging/cloud-controller-manager`:

```
bazel run //cmd/gcp-controller-manager:publish
```sh
make images
```

Environment variables `IMAGE_REGISTRY`, `IMAGE_REPO` and `IMAGE_TAG` can be
used to override destination GCR repository and tag.

This command will build and publish
`example.com/my-repo/gcp-controller-manager:v1`:
`example.com/my-repo/cloud-controller-manager:v1`:


```
IMAGE_REGISTRY=example.com IMAGE_REPO=my-repo IMAGE_TAG=v1 bazel run //cmd/gcp-controller-manager:publish
```sh
IMAGE_REGISTRY=example.com IMAGE_REPO=my-repo IMAGE_TAG=v1 make images
```

# Cross-compiling

Selecting the target platform is done with the `--platforms` option with `bazel`.
This command builds release tarballs for Windows:

```
bazel build --platforms=@io_bazel_rules_go//go/toolchain:windows_amd64 //release:release-tars
This project uses standard go tools for cross-building.
```sh
GOOS=linux GOARCH=amd64 go build ./cmd/cloud-controller-manager
```
Alternatively, run `make bin` to build both server and node binaries for all supported platforms.

This command explicitly targets Linux as the target platform:

```
bazel build --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 //release:release-tars
```
Server
- linux/amd64

Node:
- linux/amd64
- windows/amd64

# Dependency management

Dependencies are managed using [Go modules](https://github.com/golang/go/wiki/Modules) (`go mod` subcommands).

Note that builds are done with Bazel and not the Go tool. Don't follow public
Go module docs, instead use instructions in this readme.

## Working within GOPATH
Copy link
Member Author

Choose a reason for hiding this comment

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

Note: this is no longer true for go >= 1.16


If you work within `GOPATH`, `go mod` will error out unless you do one of:

- move repo outside of GOPATH (it should "just work")
- set env var `GO111MODULE=on`
This project manages dependencies using standard [Go modules](https://github.com/golang/go/wiki/Modules) (`go mod` subcommands).

## Add a new dependency

```
go get github.com/new/dependency && ./tools/update_vendor.sh
go get github.com/new/dependency
```

## Update an existing dependency

```
go get -u github.com/existing/dependency && ./tools/update_vendor.sh
go get -u github.com/existing/dependency
```

## Update all dependencies

```
go get -u && ./tools/update_vendor.sh
go get -u
```

Note that this most likely won't work due to cross-dependency issues or repos
Expand All @@ -87,3 +76,8 @@ To re-generate `BUILD` files:
```sh
tools/update_bazel.sh
```
## Clean up unused dependencies

```
go mod tidy
```
110 changes: 0 additions & 110 deletions WORKSPACE

This file was deleted.

52 changes: 52 additions & 0 deletions build/build-bin.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env bash

# Copyright 2021 The Kubernetes 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.

# Build Kubernetes release images. This will build the server target binaries,
# and create wrap them in Docker images, see `make release` for full releases

set -o errexit
set -o nounset
set -o pipefail

KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..

source "${KUBE_ROOT}/build/lib/common.sh"
source "${KUBE_ROOT}/tools/version.sh"

function build-binaries() {
mkdir -p "${BIN_DIR}/linux-amd64" "${BIN_DIR}/windows-amd64"

local goldflags goflags
goldflags="${GOLDFLAGS=-s -w} $(kube::version::ldflags)"
goflags=(
-ldflags "${goldflags}"
-trimpath
)

for binary in "${SERVER_BINARIES[@]}"; do
# build for linux-amd64
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build "${goflags[@]}" -o "${BIN_DIR}/linux-amd64/${binary}" "./cmd/${binary}"
done

for binary in "${NODE_BINARIES[@]}"; do
# build for linux-amd64
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build "${goflags[@]}" -o "${BIN_DIR}/linux-amd64/${binary}" "./cmd/${binary}"
# build for windows-amd64
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build "${goflags[@]}" -o "${BIN_DIR}/windows-amd64/${binary}.exe" "./cmd/${binary}"
done
}

build-binaries
Loading