diff --git a/Dockerfile b/Dockerfile index 6352dd3..d806122 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,7 @@ FROM golang:1.12-alpine3.9 as builder RUN apk update RUN apk add dep git -ENV GOOS linux +ENV GOOS=linux ENV GOARCH=386 WORKDIR /go/src/github.com/ipedrazas/drone-helm @@ -22,30 +22,18 @@ FROM alpine:3.9 as final MAINTAINER Ivan Pedrazas COPY --from=builder /go/src/github.com/ipedrazas/drone-helm/drone-helm /bin/ - -# Helm version: can be passed at build time -ARG VERSION -ENV VERSION ${VERSION:-v2.14.1} -ENV FILENAME helm-${VERSION}-linux-amd64.tar.gz - -ARG KUBECTL -ENV KUBECTL ${KUBECTL:-v1.14.3} +COPY *.sh /bin/ +COPY kubeconfig /root/.kube/kubeconfig RUN set -ex \ - && apk add --no-cache curl ca-certificates \ - && curl -o /tmp/${FILENAME} http://storage.googleapis.com/kubernetes-helm/${FILENAME} \ - && curl -o /tmp/kubectl https://storage.googleapis.com/kubernetes-release/release/${KUBECTL}/bin/linux/amd64/kubectl \ + && apk add --no-cache curl ca-certificates bash \ && curl -o /tmp/aws-iam-authenticator https://amazon-eks.s3-us-west-2.amazonaws.com/1.10.3/2018-07-26/bin/linux/amd64/aws-iam-authenticator \ - && tar -zxvf /tmp/${FILENAME} -C /tmp \ - && mv /tmp/linux-amd64/helm /bin/helm \ - && chmod +x /tmp/kubectl \ - && mv /tmp/kubectl /bin/kubectl \ && chmod +x /tmp/aws-iam-authenticator \ - && mv /tmp/aws-iam-authenticator /bin/aws-iam-authenticator \ - && rm -rf /tmp/* + && mv /tmp/aws-iam-authenticator /bin/aws-iam-authenticator +RUN /bin/setup-environments.sh +RUN rm -rf /tmp/* LABEL description="Kubectl and Helm." LABEL base="alpine" -COPY kubeconfig /root/.kube/kubeconfig -ENTRYPOINT [ "/bin/drone-helm" ] +ENTRYPOINT [ "/bin/entrypoint.sh" ] diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..a170c9f --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,28 @@ +#!/bin/sh + +function error { + echo "$1" + exit 1 +} + +# Will symlink `helm` and `kubectl` binaries based on the `$HELM_VERSION` and +# `$KUBECTL_VERSION` env variables into `$PREFIX/bin`, add `$PREFIX/bin` to +# the `$PATH` and delegate further execution to `/bin/drone-helm` +# See `set-environments.sh` for baked in versions. + +HELM_VERSION="${HELM_VERSION:-v2.14.1}" +KUBECTL_VERSION="${KUBECTL_VERSION:-v1.14.3}" + +mkdir -p ~/.local/bin +ln -s -f ~/.local/lib/helm-${HELM_VERSION}/helm ~/.local/bin +ln -s -f ~/.local/lib/kubectl-${KUBECTL_VERSION}/kubectl ~/.local/bin + +export PATH=~/.local/bin:$PATH + +echo "Using helm Version: ${HELM_VERSION} installed into ~/.local/bin" +echo "Using kubectl Version: ${KUBECTL_VERSION} installed into ~/.local/bin" + +helm version --client || error "Helm installation is not functional" +kubectl version --client || error "Kubectl installation is not functional" + +/bin/drone-helm "$@" diff --git a/plugin/plugin.go b/plugin/plugin.go index c83c964..94b3508 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -12,7 +12,9 @@ import ( "text/template" ) -var HELM_BIN = "/bin/helm" +// use $PATH to locate the currently activated helm binary +// do not harcode the full binary path +var HELM_BIN = "helm" var KUBECONFIG = "/root/.kube/kubeconfig" type ( diff --git a/setup-environments.sh b/setup-environments.sh new file mode 100755 index 0000000..038a802 --- /dev/null +++ b/setup-environments.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# will populate ~/.local/lib/helm-$version/ with helm and tiller binaries +helm_arch="linux-amd64" +helm_versions=(v2.14.1 v2.13.1 v2.12.3) + +for version in "${helm_versions[@]}" +do + curl http://storage.googleapis.com/kubernetes-helm/helm-${version}-${helm_arch}.tar.gz > /tmp/${version}.tar.gz + mkdir -p ~/.local/lib/helm-${version}/ + tar -C ~/.local/lib/helm-${version}/ -xvf /tmp/${version}.tar.gz --strip 1 +done + +# will populate ~/.local/lib/kubectl-$version/ with kubectl binaries +kubectl_arch="linux/amd64" +kubectl_versions=(v1.14.3 v1.13.7 v1.12.9) + +for version in "${kubectl_versions[@]}" +do + mkdir -p ~/.local/lib/kubectl-${version}/ + curl https://storage.googleapis.com/kubernetes-release/release/${version}/bin/${kubectl_arch}/kubectl > ~/.local/lib/kubectl-${version}/kubectl + chmod +x ~/.local/lib/kubectl-${version}/kubectl +done