diff --git a/.circleci/config.yml b/.circleci/config.yml index b6b64f8d..be9ba25c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,5 +1,23 @@ version: 2 jobs: + lint-charts: + docker: + - image: gcr.io/kubernetes-charts-ci/test-image:v3.3.2 + steps: + - checkout + - run: + name: lint + command: | + git remote add upstream https://github.com/paulczar/percona-helm-charts + git fetch upstream master + ct lint --config .circleci/ct.yaml + install-charts: + machine: true + steps: + - checkout + - run: + no_output_timeout: 12m + command: .circleci/install_charts.sh lint-scripts: docker: - image: koalaman/shellcheck-alpine @@ -22,12 +40,23 @@ jobs: workflows: version: 2 - release: + lint-and-install: jobs: - lint-scripts + - lint-charts: + filters: + branches: + ignore: master + tags: + ignore: /.*/ + - install-charts: + requires: + - lint-charts + release: + jobs: - release-charts: filters: tags: ignore: /.*/ branches: - only: master \ No newline at end of file + only: master diff --git a/.circleci/ct.yaml b/.circleci/ct.yaml new file mode 100644 index 00000000..79f73132 --- /dev/null +++ b/.circleci/ct.yaml @@ -0,0 +1 @@ +helm-extra-args: --timeout 600 \ No newline at end of file diff --git a/.circleci/install_charts.sh b/.circleci/install_charts.sh new file mode 100755 index 00000000..425dc57d --- /dev/null +++ b/.circleci/install_charts.sh @@ -0,0 +1,92 @@ +#!/usr/bin/env bash + +set -o errexit +set -o nounset +set -o pipefail + +readonly CT_VERSION=v2.3.3 +readonly KIND_VERSION=0.2.1 +readonly CLUSTER_NAME=chart-testing +readonly K8S_VERSION=v1.14.0 + +run_ct_container() { + echo 'Running ct container...' + docker run --rm --interactive --detach --network host --name ct \ + --volume "$(pwd)/.circleci/ct.yaml:/etc/ct/ct.yaml" \ + --volume "$(pwd):/workdir" \ + --workdir /workdir \ + "quay.io/helmpack/chart-testing:$CT_VERSION" \ + cat + echo +} + +cleanup() { + echo 'Removing ct container...' + docker kill ct > /dev/null 2>&1 + + echo 'Done!' +} + +docker_exec() { + docker exec --interactive ct "$@" +} + +create_kind_cluster() { + echo 'Installing kind...' + + curl -sSLo kind "https://github.com/kubernetes-sigs/kind/releases/download/$KIND_VERSION/kind-linux-amd64" + chmod +x kind + sudo mv kind /usr/local/bin/kind + + kind create cluster --name "$CLUSTER_NAME" --config .circleci/kind-config.yaml --image "kindest/node:$K8S_VERSION" --wait 60s + + docker_exec mkdir -p /root/.kube + + echo 'Copying kubeconfig to container...' + local kubeconfig + kubeconfig="$(kind get kubeconfig-path --name "$CLUSTER_NAME")" + docker cp "$kubeconfig" ct:/root/.kube/config + + docker_exec kubectl cluster-info + echo + + docker_exec kubectl get nodes + echo +} + +install_local_path_provisioner() { + docker_exec kubectl delete storageclass standard + docker_exec kubectl apply -f https://raw.githubusercontent.com/rancher/local-path-provisioner/master/deploy/local-path-storage.yaml +} + +install_tiller() { + echo 'Installing Tiller...' + docker_exec kubectl --namespace kube-system create sa tiller + docker_exec kubectl create clusterrolebinding tiller-cluster-rule --clusterrole=cluster-admin --serviceaccount=kube-system:tiller + docker_exec helm init --service-account tiller --upgrade --wait + echo +} + +install_charts() { + docker_exec ct install + echo +} + +main() { + run_ct_container + trap cleanup EXIT + + changed=$(docker_exec ct list-changed) + if [[ -z "$changed" ]]; then + echo 'No chart changes detected.' + return + fi + + echo 'Chart changes detected.' + create_kind_cluster + install_local_path_provisioner + install_tiller + install_charts +} + +main diff --git a/.circleci/kind-config.yaml b/.circleci/kind-config.yaml new file mode 100644 index 00000000..3c696b75 --- /dev/null +++ b/.circleci/kind-config.yaml @@ -0,0 +1,6 @@ +kind: Cluster +apiVersion: kind.sigs.k8s.io/v1alpha3 +nodes: + - role: control-plane + - role: worker + - role: worker