Skip to content
This repository has been archived by the owner on Mar 26, 2021. It is now read-only.

Commit

Permalink
Update the release script to support versioned releases.
Browse files Browse the repository at this point in the history
  • Loading branch information
perotinus committed Dec 18, 2017
1 parent 0e18c44 commit fd8af84
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 31 deletions.
7 changes: 7 additions & 0 deletions cmd/clusterregistry/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
load("@io_bazel_rules_docker//docker:docker.bzl", "docker_build", "docker_push")
load("//pkg/version:def.bzl", "version_x_defs")
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")

docker_build(
name = "clusterregistry-image",
Expand All @@ -17,6 +18,12 @@ docker_push(
tag = "dev",
)

pkg_tar(
name = "clusterregistry-server",
srcs = [":clusterregistry"],
extension = "tar.gz",
)

go_library(
name = "go_default_library",
srcs = ["clusterregistry.go"],
Expand Down
7 changes: 7 additions & 0 deletions cmd/crinit/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
load("//pkg/version:def.bzl", "version_x_defs")
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")

pkg_tar(
name = "clusterregistry-client",
srcs = [":crinit"],
extension = "tar.gz",
)

go_library(
name = "go_default_library",
Expand Down
66 changes: 56 additions & 10 deletions docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,31 @@ The cluster registry has a script, [`hack/release.sh`](../hack/release.sh), that
is used to build releases and push them for public consumption. This script is
run nightly by Prow.

## Versioned releases

[`hack/release.sh`](../hack/release.sh) can be called with one argument, a
version name, to build a versioned release. e.g.,

```sh
./hack/release.sh v0.0.2-rc0
```

This will push a container image with the `latest` and `v0.0.2-rc0` tags and
binaries into a `v0.0.2-rc0` subdirectory in the GCS bucket. *You must add a
corresponding Git tag and release to the cluster-registry repo.*

> Currently, there is no verification that the binaries pushed by
> `hack/release.sh` match the tag that is provided as an argument to the script.
> This will be fixed as the release process evolves.
### Binaries

Binaries are stored in Google Cloud Storage, in the `crreleases` bucket.
Currently there are only binaries releases for 64-bit Linux.
Currently there are only binary releases for 64-bit Linux.

#### Nightlies

To get the latest client library (i.e., `crinit`), run:
To get the latest nightly client library (i.e., `crinit`), run:

```sh
PACKAGE=client
Expand All @@ -173,23 +192,50 @@ To verify, run:
curl http://storage.googleapis.com/crreleases/nightly/$LATEST/clusterregistry-$PACKAGE.tar.gz.sha | sha256sum -c -
```

To get the latest server binaries, run the commands above but replace
`PACKAGE=client` with `PACKAGE=server`.
To get the latest nightly server binaries, run the commands above but replace
`PACKAGE=client` with `PACKAGE=server`. To get a nightly build from a specific
day, replace `LATEST=...` with `LATEST=YYYYMMDD`, where `YYYYMMDD` is a date,
e.g., 20171201.

#### Released

To get the latest released version, run the commands above, but remove
`nightly/` from all URL paths, e.g.,

```sh
PACKAGE=client
LATEST=$(curl https://storage.googleapis.com/crreleases/latest)
curl -O http://storage.googleapis.com/crreleases/$LATEST/clusterregistry-$PACKAGE.tar.gz
```

### Images

A Docker image for the [`clusterregistry`](../cmd/clusterregistry) binary is
pushed to GCR.
pushed to GCR nightly and for each release.

To pull the latest image, run:
To pull the latest nightly image, run:

```sh
docker pull gcr.io/crreleases/nightly/clusterregistry:latest_nightly
docker pull gcr.io/crreleases/clusterregistry:latest_nightly
```

To pull an image from a specific date, replace `latest` with the date in
`YYYYMMDD` format. For example,
To pull a nightly image from a specific date, replace `latest_nightly` with the
date in `YYYYMMDD` format. For example,

```sh
docker pull gcr.io/crreleases/clusterregistry:20171201
```

To pull the latest released image, run:
```sh
docker pull gcr.io/crreleases/nightly/clusterregistry:20171201
docker pull gcr.io/crreleases/clusterregistry:latest
```

To pull a specific version, replace `latest` with a version tag, e.g.,

```sh
docker pull gcr.io/crreleases/clusterregistry:v0.0.1
```

The tags will map to tags in the cluster-registry repository, which you can
find [here](https://github.com/kubernetes/cluster-registry/tags).
75 changes: 54 additions & 21 deletions hack/release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@

set -euo pipefail

ROOT_RELEASE_DIR="${ROOT_RELEASE_DIR:-nightly}"
RELEASE_TAG=${1:-}
BUILD_DATE="$(TZ=Etc/UTC date +%Y%m%d)"
RELEASE_VERSION="${RELEASE_TAG:-$BUILD_DATE}"
GCP_PROJECT=${GCP_PROJECT:-crreleases}
GCS_BUCKET=${GCS_BUCKET:-crreleases}
GCR_REPO_PATH="${GCP_PROJECT}/clusterregistry"
SCRIPT_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
TMPDIR="$(mktemp -d /tmp/crrelXXXXXXXX)"

Expand All @@ -26,51 +31,79 @@ function clean_up() {
}
trap clean_up EXIT

BUILD_DATE="$(TZ=Etc/UTC date +%Y%m%d)"
RELEASE_DIR="${TMPDIR}/${BUILD_DATE}"
RELEASE_TMPDIR="${TMPDIR}/${RELEASE_VERSION}"

# Check for and install necessary dependencies.
command -v bazel >/dev/null 2>&1 || { echo >&2 "Please install bazel before running this script."; exit 1; }
command -v gcloud >/dev/null 2>&1 || { echo >&2 "Please install gcloud before running this script."; exit 1; }
gcloud components install gsutil docker-credential-gcr
docker-credential-gcr configure-docker
docker-credential-gcr configure-docker 1>&2

cd "${SCRIPT_ROOT}/.."

# Build the tools.
bazel build //cmd/crinit //cmd/clusterregistry
# Build the tarballs of the tools.
bazel build \
//cmd/crinit:clusterregistry-client \
//cmd/clusterregistry:clusterregistry-server

# Create the archives.
mkdir -p "${RELEASE_DIR}"
tar czf "${RELEASE_DIR}/clusterregistry-client.tar.gz" -C bazel-bin/cmd/crinit crinit
tar czf "${RELEASE_DIR}/clusterregistry-server.tar.gz" -C bazel-bin/cmd/clusterregistry clusterregistry
# Copy the archives.
mkdir -p "${RELEASE_TMPDIR}"
cp \
bazel-bin/cmd/crinit/clusterregistry-client.tar.gz \
bazel-bin/cmd/clusterregistry/clusterregistry-server.tar.gz \
"${RELEASE_TMPDIR}"

# Create the `latest` file
echo "${BUILD_DATE}" > "${TMPDIR}/latest"
# Create the `latest` file.
echo "${RELEASE_VERSION}" > "${TMPDIR}/latest"

pushd "${RELEASE_DIR}"
pushd "${RELEASE_TMPDIR}" 1>&2

# Create the SHAs.
sha256sum clusterregistry-client.tar.gz > clusterregistry-client.tar.gz.sha
sha256sum clusterregistry-server.tar.gz > clusterregistry-server.tar.gz.sha

popd
popd 1>&2

SUBDIR=""
LATEST_TAG="latest"
if [[ -z "${RELEASE_TAG}" ]]; then
SUBDIR="nightly/"
LATEST_TAG="latest_nightly"
fi

# Upload the files to GCS.
gsutil cp -r "${TMPDIR}"/* "gs://crreleases/${ROOT_RELEASE_DIR}"
gsutil -m cp -r "${TMPDIR}"/* "gs://${GCS_BUCKET}/${SUBDIR}"

# Push the server container image.
bazel run //cmd/clusterregistry:push-clusterregistry-image --define repository=crreleases/nightly/clusterregistry
bazel run //cmd/clusterregistry:push-clusterregistry-image --define repository="${GCR_REPO_PATH}" 1>&2

# Adjust the tags on the image. The `push-clusterregistry-image` rule tags the
# pushed image with the `dev` tag by default. This consistent tag allows the
# tool to easily add other tags to the image. The tool then removes the `dev`
# tag since this is not a development image.
gcloud container images add-tag --quiet \
gcr.io/crreleases/nightly/clusterregistry:dev \
gcr.io/crreleases/nightly/clusterregistry:${BUILD_DATE}
"gcr.io/${GCR_REPO_PATH}:dev" \
"gcr.io/${GCR_REPO_PATH}:${RELEASE_VERSION}"
gcloud container images add-tag --quiet \
gcr.io/crreleases/nightly/clusterregistry:dev \
gcr.io/crreleases/nightly/clusterregistry:latest_nightly
"gcr.io/${GCR_REPO_PATH}:dev" \
"gcr.io/${GCR_REPO_PATH}:${LATEST_TAG}"
gcloud container images untag --quiet \
gcr.io/crreleases/nightly/clusterregistry:dev
"gcr.io/${GCR_REPO_PATH}:dev"

# Echo a release note to stdout for later use.
ROOT_GCS_PATH="https://storage.googleapis.com/${GCS_BUCKET}/${SUBDIR}${RELEASE_VERSION}"
cat <<END
# ${RELEASE_TAG}
clusterregistry Docker image: \`gcr.io/${GCR_REPO_PATH}:${RELEASE_VERSION}\`
# Download links
## Client (crinit)
[client](${ROOT_GCS_PATH}/clusterregistry-client.tar.gz)
[client SHA](${ROOT_GCS_PATH}/clusterregistry-client.tar.gz.sha)
## Server (clusterregistry)
[server](${ROOT_GCS_PATH}/clusterregistry-server.tar.gz)
[server SHA](${ROOT_GCS_PATH}/clusterregistry-server.tar.gz.sha)
END

0 comments on commit fd8af84

Please sign in to comment.