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

Add helmfile & chamber #54

Merged
merged 26 commits into from
May 1, 2018
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@ FROM golang:1.9.2-alpine3.7

RUN apk update && \
apk --update add \
jq \
git \
make \
curl \
bash \
grep
ca-certificates \
coreutils \
curl \
git \
gettext \
grep \
jq \
make

ADD ./ /build-harness/

RUN cd /build-harness && \
make helm/install template/deps
ENV INSTALL_PATH /usr/local/bin

WORKDIR /build-harness

RUN make -s chamber/install helm/install helmfile/install template/deps

ENTRYPOINT ["/bin/bash"]

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

export TIMEOUT=3
export STDOUT=${STDOUT:-/dev/null}

# helper functions
function info() {
echo -e "\e[32mINFO:\e[0m $1";
}

function err() {
echo -e "\e[31mERROR:\e[0m $1" ;
exit 1;
}

function check() {
command -v "$1" >/dev/null 2>&1 || err "$1 not installed!";
}

# wait for helm to become operational
wait_for_helm() {
info "Waiting for helm tiller..."
while true; do
status=$(kubectl get pods -l app=helm -l name=tiller --show-all=false -o=custom-columns=STATUS:.status.phase --no-headers=true -nkube-system | tr '\n' ',')
info "Helm status: $status"
if [ "$status" = "Running" ]; then
break;
fi
sleep $TIMEOUT
done
}

function set_context() {
if [ -n "$KUBE_CONTEXT" ]; then
info "Using ${KUBE_CONTEXT} kube context"
kubectl config use-context ${KUBE_CONTEXT}
fi
}

function upsert() {
helm_version=$(helm version --client --short | grep -Eo "v[0-9]\.[0-9]\.[0-9]")
tiller_version=$(timeout $TIMEOUT helm version --server --short | grep -Eo "v[0-9]\.[0-9]\.[0-9]")

if [ -z "$tiller_version" ]; then
err "Unable to connect to helm server"
fi

if [ "$helm_version" != "$tiller_version" ]; then
info "Helm version: $helm_version, differs with tiller version: $tiller_version"
info "Upgrarding tiller to $helm_version"
helm init --upgrade --force-upgrade > $STDOUT
wait_for_helm
sleep 3
info "Helm version"
helm version --short | sed 's/^/ - /'
else
info "Helm version: $helm_version matches tiller version: $tiller_version."
info "Initializing helm client..."
helm init --client-only > $STDOUT
fi
}

if [ "$1" == "upsert" ]; then
check kubectl
check helm
check timeout
set_context
upsert
else
err "Unknown commmand"
fi
9 changes: 9 additions & 0 deletions modules/chamber/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CURL := $(shell which curl)
CHAMBER_VERSION ?= 2.0.0
CHAMBER := $(shell which chamber)

## Install chamber
chamber/install: packages/install/chamber
@exit 0


16 changes: 9 additions & 7 deletions modules/helm/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CURL := $(shell which curl)
HELM_VERSION ?= v2.7.2
export HELM_VERSION ?= 2.9.0
HELM_PLATFORM ?= $(OS)-amd64
HELM := $(shell which helm)
HELM_HOME ?= $(HOME)/.helm
Expand All @@ -8,10 +8,7 @@ HELM_REPO_PATH ?= ./$(REPO_NAME)
HELM_PACKAGE_PATH ?= ./packages/$(REPO_NAME)

## Install helm
helm/install:
@$(CURL) https://kubernetes-helm.storage.googleapis.com/helm-$(HELM_VERSION)-$(HELM_PLATFORM).tar.gz | tar xvz
@chmod +x $(HELM_PLATFORM)/helm
@mv $(HELM_PLATFORM)/helm /usr/local/bin/
helm/install: packages/install/helm packages/install/yq
@helm init --client-only
@chmod -R 777 "$(HELM_HOME)"
@helm repo remove local || true
Expand All @@ -20,5 +17,10 @@ helm/install:
helm/serve/index:
$(call assert-set,CURRENT_REPO_URL)
$(call assert-set,HELM)
@$(SELF) helm:repo:index REPO_NAME=incubator
@$(SELF) helm:repo:index REPO_NAME=stable
@$(SELF) helm/repo/index REPO_NAME=incubator
@$(SELF) helm/repo/index REPO_NAME=stable

## Install or upgrade helm tiller
helm/toolbox/upsert:
@$(BUILD_HARNESS_PATH)/bin/helm_toolbox.sh upsert

12 changes: 7 additions & 5 deletions modules/helm/Makefile.chart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ helm/chart/build:
@rm -rf $(HELM_PACKAGE_PATH)$(CHART_NAME)
@mkdir -p $(HELM_PACKAGE_PATH)$(CHART_NAME)
@cp -R $(CHART_TPL)/* $(HELM_PACKAGE_PATH)$(CHART_NAME)
@find $(HELM_PACKAGE_PATH)$(CHART_NAME) -type f | xargs -I{} bash -c 'IN={} OUT={} $(SELF) -s template/build'
@echo "Pinning chart version and image.tag to $(SEMVERSION)"
@set -o pipefail; yq write --inplace $(HELM_PACKAGE_PATH)$(CHART_NAME)/Chart.yaml version $(SEMVERSION) | head -1
@set -o pipefail; yq write --inplace $(HELM_PACKAGE_PATH)$(CHART_NAME)/values.yaml image.tag $(SEMVERSION) | head -1
@echo "Fetch dependencies"
@$(HELM) dependency build --debug $(HELM_PACKAGE_PATH)$(CHART_NAME)
@echo "Create package"
Expand All @@ -49,10 +51,10 @@ helm/chart/build-all:
$(call assert-set,CHART_TPL)
@for version in $(SEMVERSIONS) ; do \
echo "Build chart $(CHART_NAME) version $$version"; \
CHART_NAME=$(CHART_NAME) \
CHART_TPL=$(CHART_TPL) \
SEMVERSION=$$version \
$(SELF) -s helm/chart/build; \
$(SELF) -s helm/chart/build \
CHART_NAME=$(CHART_NAME) \
CHART_TPL=$(CHART_TPL) \
SEMVERSION=$$version; \
done

## Publish chart $CHART_NAME to $REPO_GATEWAY_ENDPOINT
Expand Down
9 changes: 9 additions & 0 deletions modules/helmfile/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CURL := $(shell which curl)
HELMFILE_VERSION ?= 0.12.0
HELMFILE := $(shell which helm)

## Install helmfile
helmfile/install: packages/install/helmfile packages/install/kubectl packages/install/helm
@exit 0


20 changes: 20 additions & 0 deletions modules/packages/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export INSTALL_PATH ?= $(BUILD_HARNESS_PATH)/vendor
export PACKAGES_VERSION ?= 0.1.0
export PACKAGES_PATH ?= $(BUILD_HARNESS_PATH)/vendor/packages

## Install packages
packages/install:
@if [ ! -d $(PACKAGES_PATH) ]; then \
echo "Installing packages $(PACKAGES_VERSION)..."; \
rm -rf $(PACKAGES_PATH); \
git clone --depth=1 -b $(PACKAGES_VERSION) https://github.com/cloudposse/packages.git $(PACKAGES_PATH); \
rm -rf $(PACKAGES_PATH)/.git; \
fi

## Install package (e.g. helm, helmfile, kubectl)
packages/install/%: packages/install
@make -C $(PACKAGES_PATH)/install $(subst packages/install/,,$@)

## Uninstall package (e.g. helm, helmfile, kubectl)
packages/uninstall/%: packages/install
@make -C $(PACKAGES_PATH)/uninstall $(subst packages/uninstall/,,$@)