Skip to content

Commit

Permalink
Publish svcat binaries during build (openshift#1725)
Browse files Browse the repository at this point in the history
* Add cross-build targets for svcat

* svcat-all builds all supported client platforms (darwin, linux, windows)
* svcat-for-X builds a specific platform
* svcat builds for the current dev's platform

* Wire up pkg.VERSION to svcat

Versions for svcat are tracked using svcat-vX.Y.Z tags.
Versions for service catalog continue to use vX.Y.Z. I've fixed the
VERSION variable to contain the tag value to account for not using
annotated tags.

Since there are no existing versions for svcat yet I have a small hack
to print v0 so that the first PR can build. We can remove that once we
have tags.

* Publish svcat binaries on tagged builds

Download the latest client with https://download.svcat.sh/cli/latest/darwin/amd64/svcat
Download an older client with  https://download.svcat.sh/cli/VERSION/darwin/amd64/svcat

* Update svcat installation instructions

* Use same version for server and client

* Renamed from SVCAT_VERSION to TAG_VERSION to make it clear that it's
only a formatting difference.
* The cli uses the format that always includes a tag, so that it's clear
which release you are "closest" to, e.g. v1.2.3 for official releases
and v1.2.3-2-gabc123 for untagged commits.

* Document svcat releases in the devguide
  • Loading branch information
carolynvs authored and kibbles-n-bytes committed Feb 23, 2018
1 parent 8f986ae commit 62284da
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ script:
make verify-docs
else
echo "Running full build"
make verify build build-integration build-e2e test images svcat
make verify build build-integration build-e2e test images svcat-all
fi
jobs:
include:
Expand Down
39 changes: 34 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ SRC_DIRS = $(shell sh -c "find $(TOP_SRC_DIRS) -name \\*.go \
-exec dirname {} \\; | sort | uniq")
TEST_DIRS ?= $(shell sh -c "find $(TOP_SRC_DIRS) -name \\*_test.go \
-exec dirname {} \\; | sort | uniq")
# Either the tag name, e.g. v1.2.3 or the commit hash for untagged commits, e.g. abc123
VERSION ?= $(shell git describe --always --abbrev=7 --dirty)
# Either the tag name, e.g. v1.2.3 or a combination of the closest tag combined with the commit hash, e.g. v1.2.3-2-gabc123
TAG_VERSION ?= $(shell git describe --tags --abbrev=7 --dirty)
BUILD_LDFLAGS = $(shell build/version.sh $(ROOT) $(SC_PKG))
GIT_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD)

Expand All @@ -57,10 +60,19 @@ TYPES_FILES = $(shell find pkg/apis -name types.go)
GO_VERSION ?= 1.9

ALL_ARCH=amd64 arm arm64 ppc64le s390x
ALL_CLIENT_PLATFORM=darwin linux windows

PLATFORM ?= linux
# This is the current platform, so that we can build a native client binary by default
CLIENT_PLATFORM?=$(shell uname -s | tr A-Z a-z)
ARCH ?= amd64

ifeq ($(PLATFORM),windows)
FILE_EXT=.exe
else
FILE_EXT=
endif

# TODO: Consider using busybox instead of debian
BASEIMAGE?=gcr.io/google-containers/debian-base-$(ARCH):0.2

Expand Down Expand Up @@ -95,7 +107,7 @@ ifdef NO_DOCKER
else
# Mount .pkg as pkg so that we save our cached "go build" output files
DOCKER_CMD = docker run --security-opt label:disable --rm -v $(PWD):/go/src/$(SC_PKG) \
-v $(PWD)/.pkg:/go/pkg scbuildimage
-v $(PWD)/.pkg:/go/pkg --env AZURE_STORAGE_CONNECTION_STRING scbuildimage
scBuildImageTarget = .scBuildImage
endif

Expand Down Expand Up @@ -367,13 +379,30 @@ release-push-%:
$(MAKE) ARCH=$* build
$(MAKE) ARCH=$* push

# SvCat Kubectl plugin stuff
# svcat kubectl plugin
############################
.PHONY: $(BINDIR)/svcat
svcat: $(BINDIR)/svcat
$(BINDIR)/svcat: .init .generate_files cmd/svcat/main.go
.PHONY: $(BINDIR)/svcat/$(TAG_VERSION)/$(PLATFORM)/$(ARCH)/svcat$(FILE_EXT)
svcat:
# Compile a native binary for local dev/test
$(MAKE) svcat-for-$(CLIENT_PLATFORM)
cp $(BINDIR)/svcat/$(TAG_VERSION)/$(CLIENT_PLATFORM)/$(ARCH)/svcat$(FILE_EXT) $(BINDIR)/svcat/

svcat-all: $(addprefix svcat-for-,$(ALL_CLIENT_PLATFORM))

svcat-for-%:
$(MAKE) PLATFORM=$* VERSION=$(TAG_VERSION) svcat-xbuild

svcat-xbuild: $(BINDIR)/svcat/$(TAG_VERSION)/$(PLATFORM)/$(ARCH)/svcat$(FILE_EXT)
$(BINDIR)/svcat/$(TAG_VERSION)/$(PLATFORM)/$(ARCH)/svcat$(FILE_EXT): .init .generate_files
$(DOCKER_CMD) $(GO_BUILD) -o $@ $(SC_PKG)/cmd/svcat

svcat-publish: clean-bin svcat-all
# Download the latest client with https://download.svcat.sh/cli/latest/darwin/amd64/svcat
# Download an older client with https://download.svcat.sh/cli/VERSION/darwin/amd64/svcat
cp -R $(BINDIR)/svcat/$(TAG_VERSION) $(BINDIR)/svcat/$(MUTABLE_TAG)
# AZURE_STORAGE_CONNECTION_STRING will be used for auth in the following command
$(DOCKER_CMD) az storage blob upload-batch -d cli -s $(BINDIR)/svcat

# Dependency management via dep (https://golang.github.io/dep)
.PHONY: verify-vendor test-dep
verify-vendor: .init
Expand Down
6 changes: 6 additions & 0 deletions build/build-image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ RUN go get -u github.com/golang/lint/golint
RUN git clone https://github.com/duglin/vlinker.git /vlinker
ENV PATH=$PATH:/vlinker/bin

# Install the azure client, used to publish svcat binaries
ENV AZCLI_VERSION=2.0.25
RUN apt-get update && apt-get install -y python-pip && \
rm -rf /var/lib/apt/lists/*
RUN pip install --disable-pip-version-check --no-cache-dir --upgrade cryptography azure-cli==${AZCLI_VERSION}

# Create the full dir tree that we'll mount our src into when we run the image
RUN mkdir -p /go/src/github.com/kubernetes-incubator/service-catalog

Expand Down
22 changes: 15 additions & 7 deletions cmd/svcat/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,26 @@ In order to use svcat, you will need:
Follow the appropriate instructions for your shell to download svcat. The binary
can be used by itself, or as kubectl plugin.

## Bash
## MacOS
```
curl -sLO https://servicecatalogcli.blob.core.windows.net/cli/latest/$(uname -s)/$(uname -m)/svcat
curl -sLO https://download.svcat.sh/cli/latest/darwin/amd64/svcat
chmod +x ./svcat
mv ./svcat /usr/local/bin/
svcat --version
```

## PowerShell
## Linux
```
curl -sLO https://download.svcat.sh/cli/latest/linux/amd64/svcat
chmod +x ./svcat
mv ./svcat /usr/local/bin/
svcat --version
```

## Windows

```
iwr 'https://servicecatalogcli.blob.core.windows.net/cli/latest/Windows/x86_64/svcat.exe' -UseBasicParsing -OutFile svcat.exe
iwr 'https://download.svcat.sh/cli/latest/windows/amd64/svcat.exe' -UseBasicParsing -OutFile svcat.exe
mkdir -f ~\bin
$env:PATH += ";${pwd}\bin"
svcat --version
Expand All @@ -46,9 +54,9 @@ You will need to find a permanent location for it and add it to your PATH.

## Manual
1. Download the appropriate binary for your operating system:
* macOS: https://servicecatalogcli.blob.core.windows.net/cli/latest/Darwin/x86_64/svcat
* Windows: https://servicecatalogcli.blob.core.windows.net/cli/latest/Windows/x86_64/svcat.exe
* Linux: https://servicecatalogcli.blob.core.windows.net/cli/latest/Linux/x86_64/svcat
* macOS: https://download.svcat.sh/cli/latest/darwin/amd64/svcat
* Windows: https://download.svcat.sh/cli/latest/windows/amd64/svcat.exe
* Linux: https://download.svcat.sh/cli/latest/linux/amd64/svcat
1. Make the binary executable.
1. Move the binary to a directory on your PATH.

Expand Down
7 changes: 2 additions & 5 deletions cmd/svcat/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/kubernetes-incubator/service-catalog/cmd/svcat/instance"
"github.com/kubernetes-incubator/service-catalog/cmd/svcat/plan"
"github.com/kubernetes-incubator/service-catalog/cmd/svcat/plugin"
"github.com/kubernetes-incubator/service-catalog/pkg"
"github.com/kubernetes-incubator/service-catalog/pkg/svcat"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
Expand Down Expand Up @@ -108,11 +109,7 @@ func buildRootCommand() *cobra.Command {
}

func printVersion(cxt *command.Context) {
if commit == "" { // commit is empty for Homebrew builds
fmt.Fprintf(cxt.Output, "svcat %s\n", version)
} else {
fmt.Fprintf(cxt.Output, "svcat %s (%s)\n", version, commit)
}
fmt.Fprintf(cxt.Output, "svcat %s\n", pkg.VERSION)
}

func newSyncCmd(cxt *command.Context) *cobra.Command {
Expand Down
2 changes: 1 addition & 1 deletion contrib/travis/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ docker login -u "${QUAY_USERNAME}" -p "${QUAY_PASSWORD}" quay.io

if [[ "${TRAVIS_TAG}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+[a-z]*(-(r|R)(c|C)[0-9]+)*$ ]]; then
echo "Pushing images with tags '${TRAVIS_TAG}' and 'latest'."
VERSION="${TRAVIS_TAG}" MUTABLE_TAG="latest" make release-push
VERSION="${TRAVIS_TAG}" MUTABLE_TAG="latest" make release-push svcat-publish
elif [[ "${TRAVIS_BRANCH}" == "master" ]]; then
echo "Pushing images with default tags (git sha and 'canary')."
make push
Expand Down
29 changes: 28 additions & 1 deletion docs/devguide.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ git remote -v
## Building

First `cd` to the root of the cloned repository tree.
To build the service-catalog:
To build the service-catalog server components:

$ make build

Expand All @@ -156,6 +156,10 @@ is done within a Docker container-- meaning you do not need to have all of the
necessary tooling installed on your host (such as a golang compiler or dep).
Building outside the container is possible, but not officially supported.

To build the service-catalog client, `svcat`:

$ make svcat

Note, this will do the basic build of the service catalog. There are more
more [advanced build steps](#advanced-build-steps) below as well.

Expand Down Expand Up @@ -263,6 +267,29 @@ The images are tagged with the current Git commit SHA:

$ docker images

### svcat targets
These are targets for the service-catalog client, `svcat`:

* `make svcat-all` builds all supported client platforms (darwin, linux, windows).
* `make svcat-for-X` builds a specific platform.
* `make svcat` builds for the current dev's platform.
* `make svcat-publish` compiles everything and uploads the binaries.

The same tags are used for both client and server. The cli uses the format that
always includes a tag, so that it's clear which release you are "closest" to,
e.g. v1.2.3 for official releases and v1.2.3-2-gabc123 for untagged commits.

### Deploying Releases

* Merge to master - A docker image for the server is pushed to [quay.io/kubernetes-service-catalog/service-catalog](http://quay.io/kubernetes-service-catalog/service-catalog),
tagged with the abbreviated commit hash. Nothing is deployed for the client, `svcat`.
* Tag a commit on master with vX.Y.Z - A docker image for the server is pushed,
tagged with the version, e.g. vX.Y.Z. The client binaries are published to
https://download.svcat.sh/cli/latest/OS/ARCH/svcat and https://download.svcat.sh/cli/VERSION/OS/ARCH/svcat.

The idea behind "latest" link is that we can provide a permanent link to the most recent stable release of `svcat`.
If someone wants to install a unreleased version, they must build it locally.

----

## Deploying to Kubernetes
Expand Down

0 comments on commit 62284da

Please sign in to comment.