Skip to content

Commit

Permalink
Build cleanup + release process documentation (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
rhim authored Feb 21, 2017
1 parent b303809 commit 05e629e
Show file tree
Hide file tree
Showing 4 changed files with 246 additions and 164 deletions.
26 changes: 14 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# this is the classic first makefile target, and it's also the default target
# run when `make` is invoked with no specific target.
all: release
all: build

# release creates a release package for contiv.
# build creates a release package for contiv.
# It uses a pre-built image specified by BUILD_VERSION.
release:
build:
rm -rf release/
@bash ./scripts/release.sh
@bash ./scripts/build.sh

# Brings up a demo cluster to install Contiv on - by default this is a docker, centos cluster.
# It can be configured to start a RHEL cluster by setting CONTIV_NODE_OS=rhel7.
Expand All @@ -20,33 +20,35 @@ cluster-destroy:
# demo-k8s brings up a cluster with k8s, runs the installer on it, and shows the URL
# of the demo Contiv Admin Console which was set up
# BUILD_VERSION must be setup to use a specific build, e.g.
# export BUILD_VERSION-1.0.0-beta.3
# export BUILD_VERSION=1.0.0-beta.3
# Or run make as BUILD_VERSION=1.0.0-beta.3 make demo-k8s
demo-k8s:
CONTIV_KUBEADM=1 make cluster
CONTIV_KUBEADM=1 make install-test-kubeadm

# demo-swarm brings up a cluster with docker swarm, runs the installer on it, and shows the URL
# of the demo Contiv Admin Console which was set up
# BUILD_VERSION must be setup to use a specific build, e.g.
# export BUILD_VERSION-1.0.0-beta.3
# export BUILD_VERSION=1.0.0-beta.3
# Or run make as BUILD_VERSION=1.0.0-beta.3 make demo-k8s
demo-swarm:
make cluster
make install-test-swarm

# Create a release and test the release installation on a vagrant cluster
# Create a build and test the release installation on a vagrant cluster
# TODO: The vagrant part of this can be optimized by taking snapshots instead
# of creating a new set of VMs for each case
release-test-kubeadm: release
release-test-kubeadm: build
# Test kubeadm (centos by default)
CONTIV_KUBEADM=1 make cluster
CONTIV_KUBEADM=1 make install-test-kubeadm

release-test-swarm: release
release-test-swarm: build
# Test swarm (centos by default)
make cluster
make install-test-swarm

release-test-kubelegacy: release
release-test-kubelegacy: build
# Test k8s ansible (centos by default)
make cluster
make install-test-kube-legacy
Expand All @@ -67,6 +69,6 @@ install-test-swarm:
# ci does everything necessary for a Github PR-triggered CI run.
# currently, this means building a container image and running
# all of the available tests.
ci: release install-test-swarm install-test-kubeadm
ci: build install-test-swarm install-test-kubeadm

.PHONY: all release cluster cluster-destroy release-test-swarm release-test-kubeadm release-test-kubelegacy install-test-swarm install-test-kubeadm install-test-kube-legacy
.PHONY: all build cluster cluster-destroy release-test-swarm release-test-kubeadm release-test-kubelegacy install-test-swarm install-test-kubeadm install-test-kube-legacy
34 changes: 34 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Automated releases
TBD

# Manual releases
1. Set BUILD_VERSION, e.g., 1.0.0-beta.3. Set or update the following variables under script/build.sh. Merge via PR to appropriate branch.

```
auth_proxy_version=${CONTIV_API_PROXY_VERSION:-"1.0.0-beta.3"}
aci_gw_version=${CONTIV_ACI_GW_VERSION:-"latest"}
contiv_version=${CONTIV_VERSION:-"1.0.0-beta.3"}
etcd_version=${CONTIV_ETCD_VERSION:-2.3.7}
docker_version=${CONTIV_DOCKER_VERSION:-1.12.6}
```

2. Build docker binary image. This would create a docker image contiv/install:$BUILD_VERSION. It also creates two release bundles - contiv-${BUILD_VETSION}.tgz and contiv-full-${BUILD_VERSION}.tgz. This version should be tested locally using a vagrant setup with release-test-* make targets.

```
make build
```

2. Execute ```./scripts/release.sh``` Creates a new release on GitHub.

```
export GITHUB_USER=contiv
export GITHUB_TOKEN=<your token here>
./scripts/release.sh
```

3. Push image to docker hub

```
docker login -u $docker_user -p $docker_password
docker push contiv/install:$BUILD_VERSION
```
162 changes: 162 additions & 0 deletions scripts/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
#!/bin/bash

set -euo pipefail

DEV_IMAGE_NAME="devbuild"
IMAGE_NAME="contiv/auth_proxy"
VERSION=${BUILD_VERSION-$DEV_IMAGE_NAME}

auth_proxy_version=${CONTIV_API_PROXY_VERSION:-"1.0.0-beta.3"}
aci_gw_version=${CONTIV_ACI_GW_VERSION:-"latest"}
contiv_version=${CONTIV_VERSION:-"1.0.0-beta.3"}
etcd_version=${CONTIV_ETCD_VERSION:-2.3.7}
docker_version=${CONTIV_DOCKER_VERSION:-1.12.6}

function usage {
echo "Usage:"
echo "./release.sh -a <ACI gateway image> -c <contiv version> -e <etcd version> -p <API proxy image version> "
exit 1
}

function error_ret {
echo ""
echo $1
exit 1
}

while getopts ":a:p:c:e:" opt; do
case $opt in
a)
aci_gw_version=$OPTARG
;;
c)
contiv_version=$OPTARG
;;
e)
etcd_version=$OPTARG
;;
p)
auth_proxy_version=$OPTARG
;;
:)
echo "An argument required for $OPTARG was not passed"
usage
;;
?)
usage
;;
esac
done

release_dir="release"
output_dir="$release_dir/contiv-$VERSION/"
output_file="$release_dir/contiv-$VERSION.tgz"
tmp_output_file="contiv-$VERSION.tgz"
full_output_file="$release_dir/contiv-full-$VERSION.tgz"
tmp_full_output_file="contiv-full-$VERSION.tgz"

# Clean older dist folders and release binaries
rm -rf $output_dir
rm -rf $output_file

# Release files
# k8s - install.sh to take the args and construct contiv.yaml as required and to launch kubectl
# swarm - install.sh launches the container to do the actual installation
# Top level install.sh which will either take k8s/swarm install params and do the required.
mkdir -p $output_dir
cp -rf install $output_dir
cp -rf scripts/generate-certificate.sh $output_dir/install

# Get the ansible support files
chmod +x $output_dir/install/genInventoryFile.py
chmod +x $output_dir/install/generate-certificate.sh


# This is maybe optional - but assume we need it for
curl -sSL https://github.com/contiv/netplugin/releases/download/$contiv_version/netplugin-$contiv_version.tar.bz2 -o $output_dir/netplugin-$contiv_version.tar.bz2
pushd $output_dir
tar xf netplugin-$contiv_version.tar.bz2 netctl
rm -f netplugin-$contiv_version.tar.bz2
git clone http://github.com/contiv/ansible
popd

# Replace versions
ansible_yaml_dir=$output_dir/install/ansible/
ansible_env=$ansible_yaml_dir/env.json

k8s_yaml_dir=$output_dir/install/k8s/
contiv_yaml=$k8s_yaml_dir/contiv.yaml
aci_gw_yaml=$k8s_yaml_dir/aci_gw.yaml
auth_proxy_yaml=$k8s_yaml_dir/auth_proxy.yaml
etcd_yaml=$k8s_yaml_dir/etcd.yaml

sed -i.bak "s/__CONTIV_VERSION__/$contiv_version/g" $contiv_yaml
sed -i.bak "s/__API_PROXY_VERSION__/$auth_proxy_version/g" $auth_proxy_yaml
sed -i.bak "s/__ACI_GW_VERSION__/$aci_gw_version/g" $aci_gw_yaml
sed -i.bak "s/__ETCD_VERSION__/$etcd_version/g" $etcd_yaml

sed -i.bak "s/__DOCKER_VERSION__/$docker_version/g" $ansible_env
sed -i.bak "s/__CONTIV_VERSION__/$contiv_version/g" $ansible_env
sed -i.bak "s/__ACI_GW_VERSION__/$aci_gw_version/g" $ansible_env
sed -i.bak "s/__API_PROXY_VERSION__/$auth_proxy_version/g" $ansible_env
sed -i.bak "s/__ETCD_VERSION__/$etcd_version/g" $ansible_env

chmod +x $k8s_yaml_dir/install.sh
chmod +x $k8s_yaml_dir/uninstall.sh
sed -i.bak "s/__CONTIV_INSTALL_VERSION__/$VERSION/g" $ansible_yaml_dir/install_swarm.sh
sed -i.bak "s/__CONTIV_INSTALL_VERSION__/$VERSION/g" $ansible_yaml_dir/uninstall_swarm.sh
chmod +x $ansible_yaml_dir/install_swarm.sh
chmod +x $ansible_yaml_dir/uninstall_swarm.sh
chmod +x $output_dir/install/ansible/install.sh
chmod +x $output_dir/install/ansible/uninstall.sh
# Cleanup the backup files
rm -f $k8s_yaml_dir/*.bak
rm -f $ansible_yaml_dir/*.bak

# Build the docker container for ansible installation
ansible_spec=$output_dir/install/ansible/Dockerfile
docker build -t contiv/install:$VERSION -f $ansible_spec $output_dir

rm -rf $output_dir/scripts
echo "**************************************************************************************************"
echo " Please ensure that contiv/install:$VERSION is pushed to docker hub"
echo "**************************************************************************************************"

# Clean up the Dockerfiles, they are not part of the release bits.
rm -f $ansible_spec

# Create the binary cache folder
binary_cache=$output_dir/contiv_cache
mkdir -p $binary_cache

# Create the minimal tar bundle
tar czf $tmp_output_file -C $release_dir .

# Save the auth proxy & aci-gw images for packaging the full docker images with contiv install binaries
if [ "$(docker images -q contiv/auth_proxy:$auth_proxy_version 2>/dev/null)" == "" ]; then
docker pull contiv/auth_proxy:$auth_proxy_version
fi
proxy_image=$(docker images -q contiv/auth_proxy:$auth_proxy_version)
docker save $proxy_image -o $binary_cache/auth-proxy-image.tar

if [ "$(docker images -q contiv/aci-gw:$aci_gw_version 2>/dev/null)" == "" ]; then
docker pull contiv/aci-gw:$aci_gw_version
fi
aci_image=$(docker images -q contiv/aci-gw:$aci_gw_version)
docker save $aci_image -o $binary_cache/aci-gw-image.tar

curl -sL -o $binary_cache/netplugin-$contiv_version.tar.bz2 https://github.com/contiv/netplugin/releases/download/$contiv_version/netplugin-$contiv_version.tar.bz2

env_file=$output_dir/install/ansible/env.json
sed -i.bak "s#.*auth_proxy_local_install.*# \"auth_proxy_local_install\": True,#g" $env_file
sed -i.bak "s#.*contiv_network_local_install.*# \"contiv_network_local_install\": True#g" $env_file

# Create the full tar bundle
tar czf $tmp_full_output_file -C $release_dir .


mv $tmp_output_file $output_file
mv $tmp_full_output_file $full_output_file
rm -rf $output_dir

echo "Success: Contiv Installer version $VERSION is available at $output_file"
Loading

0 comments on commit 05e629e

Please sign in to comment.