From ab37e75b5c94edf20d94a92207ab9c586380a8c5 Mon Sep 17 00:00:00 2001 From: Kevin Tsai Date: Mon, 21 Aug 2017 18:18:20 +0900 Subject: [PATCH 01/21] upgrade helm to v2.6.0 --- Dockerfile | 4 ++-- README.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index c6b932b..61a4b79 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,9 +28,9 @@ RUN go build -v -o "/drone-helm" FROM alpine:3.6 MAINTAINER Ivan Pedrazas -# Helm version: can be passed at build time (default to v2.5.1) +# Helm version: can be passed at build time (default to v2.6.0) ARG VERSION -ENV VERSION ${VERSION:-v2.5.1} +ENV VERSION ${VERSION:-v2.6.0} ENV FILENAME helm-${VERSION}-linux-amd64.tar.gz ARG KUBECTL diff --git a/README.md b/README.md index f34f5df..45f64bd 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ This plugin allows to deploy a [Helm](https://github.com/kubernetes/helm) chart into a [Kubernetes](https://github.com/kubernetes/kubernetes) cluster. -* Current `helm` version: 2.5.1 +* Current `helm` version: 2.6.0 * Current `kubectl` version: 1.6.6 ## Drone Pipeline Usage From 7bcd5ddda46416f8ce5aeb0081fb8c0943420276 Mon Sep 17 00:00:00 2001 From: Ivan Pedrazas Date: Mon, 28 Aug 2017 23:06:41 +0100 Subject: [PATCH 02/21] drone file modified --- .drone.yml | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/.drone.yml b/.drone.yml index f676471..ee3cef0 100644 --- a/.drone.yml +++ b/.drone.yml @@ -22,14 +22,26 @@ pipeline: - DOCKER_HOST=tcp://127.0.0.1:2375 - TAG=${DRONE_BRANCH}-${DRONE_COMMIT_SHA:0:7} commands: - - docker login -u="${QUAY_USERNAME}" -p="${QUAY_PASSWORD}" quay.io + - docker login -u="$QUAY_USERNAME" -p="$QUAY_PASSWORD" quay.io + - docker build -t image . + - docker tag image quay.io/ipedrazas/drone-helm:${TAG} + - docker push quay.io/ipedrazas/drone-helm + secrets: ["quay_username", "quay_password"] + + build_docker_latest: + image: docker:17.05 + environment: + - DOCKER_HOST=tcp://127.0.0.1:2375 + - TAG=${DRONE_BRANCH}-${DRONE_COMMIT_SHA:0:7} + commands: + - docker login -u="$QUAY_USERNAME" -p="$QUAY_PASSWORD" quay.io - docker build -t image . - docker tag image quay.io/ipedrazas/drone-helm:latest - docker tag image quay.io/ipedrazas/drone-helm:${TAG} - docker push quay.io/ipedrazas/drone-helm - # when: - # event: [push] - # branch: [master] + when: + event: [push] + branch: [master] slack: image: plugins/slack @@ -37,6 +49,7 @@ pipeline: username: drone template: > {{ build.author }} finished building ** of {{ repo.name }} with a {{ build.status }} status + secrets: ["slack_webhook"] services: From a5f3e7d2c42cf1c637ea60c50e9775e652987836 Mon Sep 17 00:00:00 2001 From: Ivan Pedrazas Date: Mon, 28 Aug 2017 23:11:06 +0100 Subject: [PATCH 03/21] drone file modified --- .drone.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.drone.yml b/.drone.yml index ee3cef0..61b55aa 100644 --- a/.drone.yml +++ b/.drone.yml @@ -20,11 +20,11 @@ pipeline: image: docker:17.05 environment: - DOCKER_HOST=tcp://127.0.0.1:2375 - - TAG=${DRONE_BRANCH}-${DRONE_COMMIT_SHA:0:7} + - TAG=$DRONE_BRANCH-$DRONE_COMMIT_SHA:0:7 commands: - docker login -u="$QUAY_USERNAME" -p="$QUAY_PASSWORD" quay.io - docker build -t image . - - docker tag image quay.io/ipedrazas/drone-helm:${TAG} + - docker tag image quay.io/ipedrazas/drone-helm:$TAG - docker push quay.io/ipedrazas/drone-helm secrets: ["quay_username", "quay_password"] @@ -32,12 +32,12 @@ pipeline: image: docker:17.05 environment: - DOCKER_HOST=tcp://127.0.0.1:2375 - - TAG=${DRONE_BRANCH}-${DRONE_COMMIT_SHA:0:7} + - TAG=$DRONE_BRANCH-$DRONE_COMMIT_SHA:0:7 commands: - docker login -u="$QUAY_USERNAME" -p="$QUAY_PASSWORD" quay.io - docker build -t image . - docker tag image quay.io/ipedrazas/drone-helm:latest - - docker tag image quay.io/ipedrazas/drone-helm:${TAG} + - docker tag image quay.io/ipedrazas/drone-helm:$TAG - docker push quay.io/ipedrazas/drone-helm when: event: [push] From 4e7c9a88c0bcf0269bb8b7909fa97767f86fbe1b Mon Sep 17 00:00:00 2001 From: Ivan Pedrazas Date: Mon, 28 Aug 2017 23:12:40 +0100 Subject: [PATCH 04/21] drone file modified --- .drone.yml | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/.drone.yml b/.drone.yml index 61b55aa..43079d1 100644 --- a/.drone.yml +++ b/.drone.yml @@ -17,7 +17,7 @@ pipeline: build_docker_image: - image: docker:17.05 + image: docker:17.05-dind environment: - DOCKER_HOST=tcp://127.0.0.1:2375 - TAG=$DRONE_BRANCH-$DRONE_COMMIT_SHA:0:7 @@ -29,7 +29,7 @@ pipeline: secrets: ["quay_username", "quay_password"] build_docker_latest: - image: docker:17.05 + image: docker:17.05-dind environment: - DOCKER_HOST=tcp://127.0.0.1:2375 - TAG=$DRONE_BRANCH-$DRONE_COMMIT_SHA:0:7 @@ -51,15 +51,6 @@ pipeline: {{ build.author }} finished building ** of {{ repo.name }} with a {{ build.status }} status secrets: ["slack_webhook"] - -services: - dind: - image: docker:17.05-dind - privileged: true - command: - - "-s" - - "overlay" - plugin: name: drone-helm desc: Execute helm to From f4885a737fa7c654fe58e5f430e93d54e9817eec Mon Sep 17 00:00:00 2001 From: Ivan Pedrazas Date: Mon, 28 Aug 2017 23:14:48 +0100 Subject: [PATCH 05/21] drone file modified --- .drone.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.drone.yml b/.drone.yml index 43079d1..dfd4947 100644 --- a/.drone.yml +++ b/.drone.yml @@ -27,6 +27,8 @@ pipeline: - docker tag image quay.io/ipedrazas/drone-helm:$TAG - docker push quay.io/ipedrazas/drone-helm secrets: ["quay_username", "quay_password"] + volumes: + - /var/run/docker.sock:/var/run/docker.sock build_docker_latest: image: docker:17.05-dind @@ -39,6 +41,8 @@ pipeline: - docker tag image quay.io/ipedrazas/drone-helm:latest - docker tag image quay.io/ipedrazas/drone-helm:$TAG - docker push quay.io/ipedrazas/drone-helm + volumes: + - /var/run/docker.sock:/var/run/docker.sock when: event: [push] branch: [master] From 76efe53e688cb27834ddb7ea36fed3e036af23e6 Mon Sep 17 00:00:00 2001 From: Ivan Pedrazas Date: Mon, 28 Aug 2017 23:20:56 +0100 Subject: [PATCH 06/21] drone file modified --- .drone.yml | 69 ++++++++++++++++++++---------------------------------- 1 file changed, 25 insertions(+), 44 deletions(-) diff --git a/.drone.yml b/.drone.yml index dfd4947..041207f 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,51 +1,32 @@ -workspace: - base: /go - path: src/github.com/ipedrazas/drone-helm +# workspace: +# base: /go +# path: src/github.com/ipedrazas/drone-helm pipeline: - test: - image: golang:1.8 - commands: - - go get - - go test -cover -coverprofile=coverage.out + # test: + # image: golang:1.8 + # commands: + # - go get + # - go test -cover -coverprofile=coverage.out - compile: - image: golang:1.8 - commands: - - export PATH=$PATH:/go/bin - - go build -ldflags "-s -w -X main.build=$DRONE_BUILD_NUMBER" -a -tags netgo + # compile: + # image: golang:1.8 + # commands: + # - export PATH=$PATH:/go/bin + # - go build -ldflags "-s -w -X main.build=$DRONE_BUILD_NUMBER" -a -tags netgo - - build_docker_image: - image: docker:17.05-dind - environment: - - DOCKER_HOST=tcp://127.0.0.1:2375 - - TAG=$DRONE_BRANCH-$DRONE_COMMIT_SHA:0:7 - commands: - - docker login -u="$QUAY_USERNAME" -p="$QUAY_PASSWORD" quay.io - - docker build -t image . - - docker tag image quay.io/ipedrazas/drone-helm:$TAG - - docker push quay.io/ipedrazas/drone-helm - secrets: ["quay_username", "quay_password"] - volumes: - - /var/run/docker.sock:/var/run/docker.sock - - build_docker_latest: - image: docker:17.05-dind - environment: - - DOCKER_HOST=tcp://127.0.0.1:2375 - - TAG=$DRONE_BRANCH-$DRONE_COMMIT_SHA:0:7 - commands: - - docker login -u="$QUAY_USERNAME" -p="$QUAY_PASSWORD" quay.io - - docker build -t image . - - docker tag image quay.io/ipedrazas/drone-helm:latest - - docker tag image quay.io/ipedrazas/drone-helm:$TAG - - docker push quay.io/ipedrazas/drone-helm - volumes: - - /var/run/docker.sock:/var/run/docker.sock - when: - event: [push] - branch: [master] + docker-build: + # environment: + # - DOCKER_API_VERSION=1.24 + image: plugins/docker:17.05 + repo: quay.io/ipedrazas/drone-helm + tags: + - latest + - ${DRONE_BRANCH}-${DRONE_COMMIT_SHA:0:7} + registry: quay.io + email: "info@info.com" + debug: true + secrets: [ docker_username, docker_password ] slack: image: plugins/slack From 058d7f0fcad28976581376247db93e3f9979b8fa Mon Sep 17 00:00:00 2001 From: Ivan Pedrazas Date: Mon, 28 Aug 2017 23:29:04 +0100 Subject: [PATCH 07/21] cleanup --- .drone.yml | 30 ++++++++++++------------------ .drone.yml.sig | 1 - README.md | 2 ++ 3 files changed, 14 insertions(+), 19 deletions(-) delete mode 100644 .drone.yml.sig diff --git a/.drone.yml b/.drone.yml index 041207f..a6804ad 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,23 +1,16 @@ -# workspace: -# base: /go -# path: src/github.com/ipedrazas/drone-helm - pipeline: - # test: - # image: golang:1.8 - # commands: - # - go get - # - go test -cover -coverprofile=coverage.out - - # compile: - # image: golang:1.8 - # commands: - # - export PATH=$PATH:/go/bin - # - go build -ldflags "-s -w -X main.build=$DRONE_BUILD_NUMBER" -a -tags netgo docker-build: - # environment: - # - DOCKER_API_VERSION=1.24 + image: plugins/docker:17.05 + repo: quay.io/ipedrazas/drone-helm + tags: + - ${DRONE_BRANCH}-${DRONE_COMMIT_SHA:0:7} + registry: quay.io + email: "info@info.com" + debug: true + secrets: [ docker_username, docker_password ] + + docker-build-master: image: plugins/docker:17.05 repo: quay.io/ipedrazas/drone-helm tags: @@ -28,12 +21,13 @@ pipeline: debug: true secrets: [ docker_username, docker_password ] + slack: image: plugins/slack channel: deploys username: drone template: > - {{ build.author }} finished building ** of {{ repo.name }} with a {{ build.status }} status + {{ build.author }} finished building ** of {{ repo.name }} with a {{ build.status }} status secrets: ["slack_webhook"] plugin: diff --git a/.drone.yml.sig b/.drone.yml.sig deleted file mode 100644 index d5aced5..0000000 --- a/.drone.yml.sig +++ /dev/null @@ -1 +0,0 @@ -eyJhbGciOiJIUzI1NiJ9.d29ya3NwYWNlOgogIGJhc2U6IC9nbwogIHBhdGg6IHNyYy9naXRodWIuY29tL2lwZWRyYXphcy9kcm9uZS1oZWxtCgpwaXBlbGluZToKICB0ZXN0OgogICAgaW1hZ2U6IGdvbGFuZzoxLjgKICAgIGNvbW1hbmRzOgogICAgICAtIGdvIGdldAogICAgICAtIGdvIHRlc3QgLWNvdmVyIC1jb3ZlcnByb2ZpbGU9Y292ZXJhZ2Uub3V0CgogIGNvbXBpbGU6CiAgICBpbWFnZTogZ29sYW5nOjEuOAogICAgY29tbWFuZHM6CiAgICAgIC0gZXhwb3J0IFBBVEg9JFBBVEg6L2dvL2JpbgogICAgICAtIGdvIGJ1aWxkIC1sZGZsYWdzICItcyAtdyAtWCBtYWluLmJ1aWxkPSREUk9ORV9CVUlMRF9OVU1CRVIiIC1hIC10YWdzIG5ldGdvCgoKICBidWlsZF9kb2NrZXJfaW1hZ2U6CiAgICBpbWFnZTogZG9ja2VyOjEuMTIKICAgIGVudmlyb25tZW50OgogICAgICAtIERPQ0tFUl9IT1NUPXRjcDovLzEyNy4wLjAuMToyMzc1CiAgICAgIC0gVEFHPSR7RFJPTkVfQlJBTkNIfS0ke0RST05FX0NPTU1JVF9TSEE6MDo3fQogICAgY29tbWFuZHM6CiAgICAgIC0gZG9ja2VyIGxvZ2luIC11PSIke1FVQVlfVVNFUk5BTUV9IiAtcD0iJHtRVUFZX1BBU1NXT1JEfSIgcXVheS5pbwogICAgICAtIGRvY2tlciBidWlsZCAtdCBpbWFnZSAuCiAgICAgIC0gZG9ja2VyIHRhZyBpbWFnZSBxdWF5LmlvL2lwZWRyYXphcy9kcm9uZS1oZWxtOmxhdGVzdAogICAgICAtIGRvY2tlciB0YWcgaW1hZ2UgcXVheS5pby9pcGVkcmF6YXMvZHJvbmUtaGVsbToke1RBR30KICAgICAgLSBkb2NrZXIgcHVzaCBxdWF5LmlvL2lwZWRyYXphcy9kcm9uZS1oZWxtCiAgICAjIHdoZW46CiAgICAjICBldmVudDogW3B1c2hdCiAgICAjICBicmFuY2g6IFttYXN0ZXJdCgogIHNsYWNrOgogICAgaW1hZ2U6IHBsdWdpbnMvc2xhY2sKICAgIGNoYW5uZWw6IGRlcGxveXMKICAgIHVzZXJuYW1lOiBkcm9uZQogICAgdGVtcGxhdGU6ID4KICAgICAge3sgYnVpbGQuYXV0aG9yIH19IGZpbmlzaGVkIGJ1aWxkaW5nICAqPGh0dHA6Ly9kcm9uZS5zb2hvaG91c2VkaWdpdGFsLmNvbS9Tb2hvSG91c2Uve3sgcmVwby5uYW1lIH19L3t7IGJ1aWxkLm51bWJlciB9fXx7eyBidWlsZC5icmFuY2ggfX0gKHt7IGJ1aWxkLm51bWJlciB9fSk-KiBvZiB7eyByZXBvLm5hbWUgfX0gIHdpdGggYSB7eyBidWlsZC5zdGF0dXMgfX0gc3RhdHVzCgoKc2VydmljZXM6CiAgZGluZDoKICAgIGltYWdlOiBkb2NrZXI6MS4xMi1kaW5kCiAgICBwcml2aWxlZ2VkOiB0cnVlCiAgICBjb21tYW5kOgogICAgICAtICItcyIKICAgICAgLSAib3ZlcmxheSIKCnBsdWdpbjoKICBuYW1lOiBkcm9uZS1oZWxtCiAgZGVzYzogRXhlY3V0ZSBoZWxtIHRvCiAgdHlwZTogZGVwbG95CiAgaW1hZ2U6IHF1YXkuaW8vaXBlZHJhemFzL2Ryb25lLWhlbG0KICBsYWJlbHM6CiAgICAtIGRlcGxveQogICAgLSBrdWJlcm5ldGVzCiAgICAtIGhlbG0K.TUPmXe_ZEmQLVIFZeglBkqT-iru6H_TKxURXpM-adfU \ No newline at end of file diff --git a/README.md b/README.md index 45f64bd..4e12557 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Helm (Kubernetes) plugin for drone.io +[![Build Status](https://build.kube.camp/api/badges/ipedrazas/drone-helm/status.svg)](https://build.kube.camp/ipedrazas/drone-helm) + This plugin allows to deploy a [Helm](https://github.com/kubernetes/helm) chart into a [Kubernetes](https://github.com/kubernetes/kubernetes) cluster. * Current `helm` version: 2.6.0 From f8f1f5f910a5fe55423dcc03e2c08be9a4205257 Mon Sep 17 00:00:00 2001 From: Ivan Pedrazas Date: Mon, 28 Aug 2017 23:41:31 +0100 Subject: [PATCH 08/21] cleanup --- .drone.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.drone.yml b/.drone.yml index a6804ad..ed43a4e 100644 --- a/.drone.yml +++ b/.drone.yml @@ -7,7 +7,6 @@ pipeline: - ${DRONE_BRANCH}-${DRONE_COMMIT_SHA:0:7} registry: quay.io email: "info@info.com" - debug: true secrets: [ docker_username, docker_password ] docker-build-master: @@ -18,8 +17,9 @@ pipeline: - ${DRONE_BRANCH}-${DRONE_COMMIT_SHA:0:7} registry: quay.io email: "info@info.com" - debug: true secrets: [ docker_username, docker_password ] + when: + branch: [master] slack: From ebf9dec69fb1148fdfbf0c1db724326e478824b0 Mon Sep 17 00:00:00 2001 From: Ivan Pedrazas Date: Mon, 28 Aug 2017 23:53:59 +0100 Subject: [PATCH 09/21] chart added for testing latest plugin version --- .drone.yml | 9 +++++ charts/plugintest/.helmignore | 21 ++++++++++++ charts/plugintest/Chart.yaml | 4 +++ charts/plugintest/templates/NOTES.txt | 19 +++++++++++ charts/plugintest/templates/_helpers.tpl | 16 +++++++++ charts/plugintest/templates/deployment.yaml | 37 +++++++++++++++++++++ charts/plugintest/templates/ingress.yaml | 32 ++++++++++++++++++ charts/plugintest/templates/service.yaml | 19 +++++++++++ charts/plugintest/values.yaml | 37 +++++++++++++++++++++ 9 files changed, 194 insertions(+) create mode 100644 charts/plugintest/.helmignore create mode 100644 charts/plugintest/Chart.yaml create mode 100644 charts/plugintest/templates/NOTES.txt create mode 100644 charts/plugintest/templates/_helpers.tpl create mode 100644 charts/plugintest/templates/deployment.yaml create mode 100644 charts/plugintest/templates/ingress.yaml create mode 100644 charts/plugintest/templates/service.yaml create mode 100644 charts/plugintest/values.yaml diff --git a/.drone.yml b/.drone.yml index ed43a4e..3d60783 100644 --- a/.drone.yml +++ b/.drone.yml @@ -21,6 +21,15 @@ pipeline: when: branch: [master] + test_deploy: + image: quay.io/ipedrazas/drone-helm:latest + skip_tls_verify: true + chart: ./charts/plugintest + release: ${DRONE_BRANCH} + prefix: test + secrets: [ test_api_server, test_kubernetes_token] + when: + branch: [master] slack: image: plugins/slack diff --git a/charts/plugintest/.helmignore b/charts/plugintest/.helmignore new file mode 100644 index 0000000..f0c1319 --- /dev/null +++ b/charts/plugintest/.helmignore @@ -0,0 +1,21 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*~ +# Various IDEs +.project +.idea/ +*.tmproj diff --git a/charts/plugintest/Chart.yaml b/charts/plugintest/Chart.yaml new file mode 100644 index 0000000..98d23d8 --- /dev/null +++ b/charts/plugintest/Chart.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +description: A Helm chart for Kubernetes +name: plugintest +version: 0.1.0 diff --git a/charts/plugintest/templates/NOTES.txt b/charts/plugintest/templates/NOTES.txt new file mode 100644 index 0000000..ccfecb7 --- /dev/null +++ b/charts/plugintest/templates/NOTES.txt @@ -0,0 +1,19 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range .Values.ingress.hosts }} + http://{{ . }} +{{- end }} +{{- else if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ template "fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +{{- else if contains "LoadBalancer" .Values.service.type }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch the status of by running 'kubectl get svc -w {{ template "fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ template "fullname" . }} -o jsonpath='{.status.loadBalancer.ingress[0].ip}') + echo http://$SERVICE_IP:{{ .Values.service.externalPort }} +{{- else if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app={{ template "name" . }},release={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl port-forward $POD_NAME 8080:{{ .Values.service.externalPort }} +{{- end }} diff --git a/charts/plugintest/templates/_helpers.tpl b/charts/plugintest/templates/_helpers.tpl new file mode 100644 index 0000000..f0d83d2 --- /dev/null +++ b/charts/plugintest/templates/_helpers.tpl @@ -0,0 +1,16 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +*/}} +{{- define "fullname" -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} diff --git a/charts/plugintest/templates/deployment.yaml b/charts/plugintest/templates/deployment.yaml new file mode 100644 index 0000000..d15e0f3 --- /dev/null +++ b/charts/plugintest/templates/deployment.yaml @@ -0,0 +1,37 @@ +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: {{ template "fullname" . }} + labels: + app: {{ template "name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +spec: + replicas: {{ .Values.replicaCount }} + template: + metadata: + labels: + app: {{ template "name" . }} + release: {{ .Release.Name }} + spec: + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - containerPort: {{ .Values.service.internalPort }} + livenessProbe: + httpGet: + path: / + port: {{ .Values.service.internalPort }} + readinessProbe: + httpGet: + path: / + port: {{ .Values.service.internalPort }} + resources: +{{ toYaml .Values.resources | indent 12 }} + {{- if .Values.nodeSelector }} + nodeSelector: +{{ toYaml .Values.nodeSelector | indent 8 }} + {{- end }} diff --git a/charts/plugintest/templates/ingress.yaml b/charts/plugintest/templates/ingress.yaml new file mode 100644 index 0000000..b09eb90 --- /dev/null +++ b/charts/plugintest/templates/ingress.yaml @@ -0,0 +1,32 @@ +{{- if .Values.ingress.enabled -}} +{{- $serviceName := include "fullname" . -}} +{{- $servicePort := .Values.service.externalPort -}} +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: {{ template "fullname" . }} + labels: + app: {{ template "name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} + annotations: + {{- range $key, $value := .Values.ingress.annotations }} + {{ $key }}: {{ $value | quote }} + {{- end }} +spec: + rules: + {{- range $host := .Values.ingress.hosts }} + - host: {{ $host }} + http: + paths: + - path: / + backend: + serviceName: {{ $serviceName }} + servicePort: {{ $servicePort }} + {{- end -}} + {{- if .Values.ingress.tls }} + tls: +{{ toYaml .Values.ingress.tls | indent 4 }} + {{- end -}} +{{- end -}} diff --git a/charts/plugintest/templates/service.yaml b/charts/plugintest/templates/service.yaml new file mode 100644 index 0000000..f311d10 --- /dev/null +++ b/charts/plugintest/templates/service.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ template "fullname" . }} + labels: + app: {{ template "name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.externalPort }} + targetPort: {{ .Values.service.internalPort }} + protocol: TCP + name: {{ .Values.service.name }} + selector: + app: {{ template "name" . }} + release: {{ .Release.Name }} diff --git a/charts/plugintest/values.yaml b/charts/plugintest/values.yaml new file mode 100644 index 0000000..7eb5fff --- /dev/null +++ b/charts/plugintest/values.yaml @@ -0,0 +1,37 @@ +# Default values for plugintest. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. +replicaCount: 1 +image: + repository: nginx + tag: stable + pullPolicy: IfNotPresent +service: + name: nginx + type: ClusterIP + externalPort: 80 + internalPort: 80 +ingress: + enabled: false + # Used to create an Ingress record. + hosts: + - chart-example.local + annotations: + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + tls: + # Secrets must be manually created in the namespace. + # - secretName: chart-example-tls + # hosts: + # - chart-example.local +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi From f3b3ac395fd9b4695304b33f0afa5dc5c1151429 Mon Sep 17 00:00:00 2001 From: Ivan Pedrazas Date: Mon, 28 Aug 2017 23:54:42 +0100 Subject: [PATCH 10/21] chart added for testing latest plugin version --- .drone.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.drone.yml b/.drone.yml index 3d60783..172bbbc 100644 --- a/.drone.yml +++ b/.drone.yml @@ -28,8 +28,8 @@ pipeline: release: ${DRONE_BRANCH} prefix: test secrets: [ test_api_server, test_kubernetes_token] - when: - branch: [master] + # when: + # branch: [master] slack: image: plugins/slack From 10e06077a442e9fe34f79b310d0b80b99e0f412d Mon Sep 17 00:00:00 2001 From: Ivan Pedrazas Date: Mon, 28 Aug 2017 23:56:56 +0100 Subject: [PATCH 11/21] chart added for testing latest plugin version --- .drone.yml | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/.drone.yml b/.drone.yml index 172bbbc..4bab3cc 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,25 +1,25 @@ pipeline: - docker-build: - image: plugins/docker:17.05 - repo: quay.io/ipedrazas/drone-helm - tags: - - ${DRONE_BRANCH}-${DRONE_COMMIT_SHA:0:7} - registry: quay.io - email: "info@info.com" - secrets: [ docker_username, docker_password ] + # docker-build: + # image: plugins/docker:17.05 + # repo: quay.io/ipedrazas/drone-helm + # tags: + # - ${DRONE_BRANCH}-${DRONE_COMMIT_SHA:0:7} + # registry: quay.io + # email: "info@info.com" + # secrets: [ docker_username, docker_password ] - docker-build-master: - image: plugins/docker:17.05 - repo: quay.io/ipedrazas/drone-helm - tags: - - latest - - ${DRONE_BRANCH}-${DRONE_COMMIT_SHA:0:7} - registry: quay.io - email: "info@info.com" - secrets: [ docker_username, docker_password ] - when: - branch: [master] + # docker-build-master: + # image: plugins/docker:17.05 + # repo: quay.io/ipedrazas/drone-helm + # tags: + # - latest + # - ${DRONE_BRANCH}-${DRONE_COMMIT_SHA:0:7} + # registry: quay.io + # email: "info@info.com" + # secrets: [ docker_username, docker_password ] + # when: + # branch: [master] test_deploy: image: quay.io/ipedrazas/drone-helm:latest @@ -27,6 +27,7 @@ pipeline: chart: ./charts/plugintest release: ${DRONE_BRANCH} prefix: test + debug: true secrets: [ test_api_server, test_kubernetes_token] # when: # branch: [master] From ddb9cd285d6a5769c82551ad8d5bb1d181736cde Mon Sep 17 00:00:00 2001 From: Ivan Pedrazas Date: Mon, 28 Aug 2017 23:57:43 +0100 Subject: [PATCH 12/21] chart added for testing latest plugin version --- .drone.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 4bab3cc..6964954 100644 --- a/.drone.yml +++ b/.drone.yml @@ -26,7 +26,7 @@ pipeline: skip_tls_verify: true chart: ./charts/plugintest release: ${DRONE_BRANCH} - prefix: test + prefix: TEST debug: true secrets: [ test_api_server, test_kubernetes_token] # when: From b43110ed12d4896b54ee5f8328aab7f159fc8cf0 Mon Sep 17 00:00:00 2001 From: Ivan Pedrazas Date: Tue, 29 Aug 2017 00:10:06 +0100 Subject: [PATCH 13/21] chart added for testing latest plugin version --- .drone.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.drone.yml b/.drone.yml index 6964954..c3912eb 100644 --- a/.drone.yml +++ b/.drone.yml @@ -27,7 +27,6 @@ pipeline: chart: ./charts/plugintest release: ${DRONE_BRANCH} prefix: TEST - debug: true secrets: [ test_api_server, test_kubernetes_token] # when: # branch: [master] From 95fdd00d10a41641f6d8e979499c73702ec86521 Mon Sep 17 00:00:00 2001 From: Ivan Pedrazas Date: Tue, 29 Aug 2017 00:10:53 +0100 Subject: [PATCH 14/21] chart added for testing latest plugin version --- .drone.yml | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/.drone.yml b/.drone.yml index c3912eb..ff75bff 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,25 +1,25 @@ pipeline: - # docker-build: - # image: plugins/docker:17.05 - # repo: quay.io/ipedrazas/drone-helm - # tags: - # - ${DRONE_BRANCH}-${DRONE_COMMIT_SHA:0:7} - # registry: quay.io - # email: "info@info.com" - # secrets: [ docker_username, docker_password ] + docker-build: + image: plugins/docker:17.05 + repo: quay.io/ipedrazas/drone-helm + tags: + - ${DRONE_BRANCH}-${DRONE_COMMIT_SHA:0:7} + registry: quay.io + email: "info@info.com" + secrets: [ docker_username, docker_password ] - # docker-build-master: - # image: plugins/docker:17.05 - # repo: quay.io/ipedrazas/drone-helm - # tags: - # - latest - # - ${DRONE_BRANCH}-${DRONE_COMMIT_SHA:0:7} - # registry: quay.io - # email: "info@info.com" - # secrets: [ docker_username, docker_password ] - # when: - # branch: [master] + docker-build-master: + image: plugins/docker:17.05 + repo: quay.io/ipedrazas/drone-helm + tags: + - latest + - ${DRONE_BRANCH}-${DRONE_COMMIT_SHA:0:7} + registry: quay.io + email: "info@info.com" + secrets: [ docker_username, docker_password ] + when: + branch: [master] test_deploy: image: quay.io/ipedrazas/drone-helm:latest @@ -28,8 +28,8 @@ pipeline: release: ${DRONE_BRANCH} prefix: TEST secrets: [ test_api_server, test_kubernetes_token] - # when: - # branch: [master] + when: + branch: [master] slack: image: plugins/slack From e4a3014704a52cd2a7ff34be8b5ee3f8422f7fd7 Mon Sep 17 00:00:00 2001 From: Ivan Pedrazas Date: Tue, 29 Aug 2017 00:17:49 +0100 Subject: [PATCH 15/21] stop double docker building --- .drone.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.drone.yml b/.drone.yml index ff75bff..3016fbb 100644 --- a/.drone.yml +++ b/.drone.yml @@ -8,6 +8,9 @@ pipeline: registry: quay.io email: "info@info.com" secrets: [ docker_username, docker_password ] + when: + branch: + exclude: [ master] docker-build-master: image: plugins/docker:17.05 From 3a4276c3848e6eb16da5a3b9ba8bea2a09298aec Mon Sep 17 00:00:00 2001 From: Ivan Pedrazas Date: Mon, 4 Sep 2017 09:54:38 +0100 Subject: [PATCH 16/21] helm to 2.6.1 kubectl 1.7.5 --- .drone.yml | 2 ++ Dockerfile | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.drone.yml b/.drone.yml index 3016fbb..fb6ac8a 100644 --- a/.drone.yml +++ b/.drone.yml @@ -5,6 +5,7 @@ pipeline: repo: quay.io/ipedrazas/drone-helm tags: - ${DRONE_BRANCH}-${DRONE_COMMIT_SHA:0:7} + - k1.7.5-h2.6.1 registry: quay.io email: "info@info.com" secrets: [ docker_username, docker_password ] @@ -17,6 +18,7 @@ pipeline: repo: quay.io/ipedrazas/drone-helm tags: - latest + - k1.7.5-h2.6.1 - ${DRONE_BRANCH}-${DRONE_COMMIT_SHA:0:7} registry: quay.io email: "info@info.com" diff --git a/Dockerfile b/Dockerfile index 61a4b79..c3dfa38 100644 --- a/Dockerfile +++ b/Dockerfile @@ -30,11 +30,11 @@ MAINTAINER Ivan Pedrazas # Helm version: can be passed at build time (default to v2.6.0) ARG VERSION -ENV VERSION ${VERSION:-v2.6.0} +ENV VERSION ${VERSION:-v2.6.1} ENV FILENAME helm-${VERSION}-linux-amd64.tar.gz ARG KUBECTL -ENV KUBECTL ${KUBECTL:-v1.7.2} +ENV KUBECTL ${KUBECTL:-v1.7.5} RUN set -ex \ && apk add --no-cache curl ca-certificates \ From 52ced7ceff2b9725387b5747d6b55ded6813ea4a Mon Sep 17 00:00:00 2001 From: Danny Krainas Date: Mon, 16 Oct 2017 08:59:22 -0400 Subject: [PATCH 17/21] uppercase prefixed secrets during replacement --- plugin.go | 41 +++++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/plugin.go b/plugin.go index 0d97e47..e5d8ab3 100644 --- a/plugin.go +++ b/plugin.go @@ -191,6 +191,10 @@ func doHelmInit(p *Plugin) []string { // Exec default method func (p *Plugin) Exec() error { + if p.Config.Debug { + p.debugEnv() + } + // create /root/.kube/config file if not exists if _, err := os.Stat(p.Config.KubeConfig); os.IsNotExist(err) { resolveSecrets(p) @@ -200,6 +204,7 @@ func (p *Plugin) Exec() error { if p.Config.Token == "" { return fmt.Errorf("Error: Token is needed to deploy.") } + initialiseKubeconfig(&p.Config, KUBECONFIG, p.Config.KubeConfig) } @@ -220,6 +225,7 @@ func (p *Plugin) Exec() error { if p.Config.Debug { log.Println("adding helm repo: " + strings.Join(repoAdd[:], " ")) } + if err = runCommand(repoAdd); err != nil { return fmt.Errorf("Error adding helm repo: " + err.Error()) } @@ -234,10 +240,12 @@ func (p *Plugin) Exec() error { if p.Config.Debug { log.Println("helm command: " + strings.Join(p.Config.HelmCommand[:], " ")) } + err = runCommand(p.Config.HelmCommand) if err != nil { return fmt.Errorf("Error running helm command: " + strings.Join(p.Config.HelmCommand[:], " ")) } + return nil } @@ -265,10 +273,10 @@ func runCommand(params []string) error { } func resolveSecrets(p *Plugin) { - p.Config.Values = resolveEnvVar(p.Config.Values, p.Config.Prefix) - p.Config.APIServer = resolveEnvVar("${API_SERVER}", p.Config.Prefix) - p.Config.Token = resolveEnvVar("${KUBERNETES_TOKEN}", p.Config.Prefix) - p.Config.ServiceAccount = resolveEnvVar("${SERVICE_ACCOUNT}", p.Config.Prefix) + p.Config.Values = resolveEnvVar(p.Config.Values, p.Config.Prefix, p.Config.Debug) + p.Config.APIServer = resolveEnvVar("${API_SERVER}", p.Config.Prefix, p.Config.Debug) + p.Config.Token = resolveEnvVar("${KUBERNETES_TOKEN}", p.Config.Prefix, p.Config.Debug) + p.Config.ServiceAccount = resolveEnvVar("${SERVICE_ACCOUNT}", p.Config.Prefix, p.Config.Debug) if p.Config.ServiceAccount == "" { p.Config.ServiceAccount = "helm" } @@ -281,23 +289,30 @@ func getEnvVars(envvars string) [][]string { return extracted } -func resolveEnvVar(key string, prefix string) string { +func resolveEnvVar(key string, prefix string, debug bool) string { envvars := getEnvVars(key) - return replaceEnvvars(envvars, prefix, key) + return replaceEnvvars(envvars, prefix, key, debug) } -func replaceEnvvars(envvars [][]string, prefix string, s string) string { +func replaceEnvvars(envvars [][]string, prefix string, s string, debug bool) string { for _, envvar := range envvars { envvarName := envvar[0] envvarKey := envvar[2] - envval := os.Getenv(prefix + "_" + envvarKey) + prefixedKey := strings.ToUpper(prefix + "_" + envvarKey) + envval := os.Getenv(prefixedKey) + if debug { + fmt.Printf("-ReplVar: %s => %s-- %s\n", prefixedKey, envvarKey, envval) + } + if envval == "" { envval = os.Getenv(envvarKey) } + if strings.Contains(s, envvarName) { s = strings.Replace(s, envvarName, envval, -1) } } + return s } @@ -311,26 +326,28 @@ func unQuote(s string) string { return unquoted } -func (p *Plugin) debug() { - fmt.Println(p) +func (p *Plugin) debugEnv() { // debug env vars for _, e := range os.Environ() { fmt.Println("-Var:--", e) } +} + +func (p *Plugin) debug() { + fmt.Println(p) // debug plugin obj fmt.Printf("Api server: %s \n", p.Config.APIServer) fmt.Printf("Values: %s \n", p.Config.Values) fmt.Printf("Secrets: %s \n", p.Config.Secrets) fmt.Printf("Helm Repos: %s \n", p.Config.HelmRepos) fmt.Printf("ValuesFiles: %s \n", p.Config.ValuesFiles) - kubeconfig, err := ioutil.ReadFile(KUBECONFIG) if err == nil { fmt.Println(string(kubeconfig)) } + config, err := ioutil.ReadFile(p.Config.KubeConfig) if err == nil { fmt.Println(string(config)) } - } From 72dc20f4b5e08b68e94950692707d599424c4394 Mon Sep 17 00:00:00 2001 From: Ivan Pedrazas Date: Tue, 24 Oct 2017 15:45:28 +0100 Subject: [PATCH 18/21] updated kubectl and helm versions --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index c3dfa38..de0b2e3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -30,11 +30,11 @@ MAINTAINER Ivan Pedrazas # Helm version: can be passed at build time (default to v2.6.0) ARG VERSION -ENV VERSION ${VERSION:-v2.6.1} +ENV VERSION ${VERSION:-v2.7.0} ENV FILENAME helm-${VERSION}-linux-amd64.tar.gz ARG KUBECTL -ENV KUBECTL ${KUBECTL:-v1.7.5} +ENV KUBECTL ${KUBECTL:-v1.8.1} RUN set -ex \ && apk add --no-cache curl ca-certificates \ From c47f562846cb2bb01209a9372e376e47ad583067 Mon Sep 17 00:00:00 2001 From: Ivan Pedrazas Date: Tue, 24 Oct 2017 15:45:57 +0100 Subject: [PATCH 19/21] Update .drone.yml --- .drone.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.drone.yml b/.drone.yml index fb6ac8a..421f28e 100644 --- a/.drone.yml +++ b/.drone.yml @@ -5,7 +5,7 @@ pipeline: repo: quay.io/ipedrazas/drone-helm tags: - ${DRONE_BRANCH}-${DRONE_COMMIT_SHA:0:7} - - k1.7.5-h2.6.1 + - k1.8.1-h2.7.0 registry: quay.io email: "info@info.com" secrets: [ docker_username, docker_password ] @@ -18,7 +18,7 @@ pipeline: repo: quay.io/ipedrazas/drone-helm tags: - latest - - k1.7.5-h2.6.1 + - k1.8.1-h2.7.0 - ${DRONE_BRANCH}-${DRONE_COMMIT_SHA:0:7} registry: quay.io email: "info@info.com" From 7c83fbd5c0e4acc87ba4ea412be823e235e3c38c Mon Sep 17 00:00:00 2001 From: Danny Krainas Date: Fri, 27 Oct 2017 15:12:32 -0400 Subject: [PATCH 20/21] fix replaceEnvvars test and clear build --- plugin_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin_test.go b/plugin_test.go index 63f6a47..692a94e 100644 --- a/plugin_test.go +++ b/plugin_test.go @@ -204,7 +204,7 @@ func TestReplaceEnvvars(t *testing.T) { prefix := "MY" testText := "this should be ${TAG} now ${TAG}" result := getEnvVars(testText) - resolved := replaceEnvvars(result, prefix, testText) + resolved := replaceEnvvars(result, prefix, testText, false) if !strings.Contains(resolved, tag) { t.Errorf("EnvVar MY_TAG no replaced by %s -- %s \n", tag, resolved) } From e007b4ed9fbe74ca6f6c8b915c9fc25e79ddb47a Mon Sep 17 00:00:00 2001 From: Danny Krainas Date: Fri, 27 Oct 2017 15:14:51 -0400 Subject: [PATCH 21/21] fix mismatched flag keys --- main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 9015707..f4a5a6e 100644 --- a/main.go +++ b/main.go @@ -105,12 +105,12 @@ func main() { EnvVar: "PLUGIN_UPGRADE,UPGRADE", }, cli.BoolFlag{ - Name: "client-only", + Name: "canary-image", Usage: "if set, Helm will use the canary tiller image", EnvVar: "PLUGIN_CANARY_IMAGE,CANARY_IMAGE", }, cli.BoolFlag{ - Name: "canary-image", + Name: "client-only", Usage: "if set, it will initilises helm in the client side only", EnvVar: "PLUGIN_CLIENT_ONLY,CLIENT_ONLY", },