diff --git a/Dockerfile b/Dockerfile index d806122..6352dd3 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,18 +22,30 @@ FROM alpine:3.9 as final MAINTAINER Ivan Pedrazas COPY --from=builder /go/src/github.com/ipedrazas/drone-helm/drone-helm /bin/ -COPY *.sh /bin/ -COPY kubeconfig /root/.kube/kubeconfig + +# 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} RUN set -ex \ - && apk add --no-cache curl ca-certificates bash \ + && 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 \ && 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 -RUN /bin/setup-environments.sh -RUN rm -rf /tmp/* + && mv /tmp/aws-iam-authenticator /bin/aws-iam-authenticator \ + && rm -rf /tmp/* LABEL description="Kubectl and Helm." LABEL base="alpine" +COPY kubeconfig /root/.kube/kubeconfig -ENTRYPOINT [ "/bin/entrypoint.sh" ] +ENTRYPOINT [ "/bin/drone-helm" ] diff --git a/entrypoint.sh b/entrypoint.sh deleted file mode 100755 index a170c9f..0000000 --- a/entrypoint.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/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 94b3508..c83c964 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -12,9 +12,7 @@ import ( "text/template" ) -// use $PATH to locate the currently activated helm binary -// do not harcode the full binary path -var HELM_BIN = "helm" +var HELM_BIN = "/bin/helm" var KUBECONFIG = "/root/.kube/kubeconfig" type ( diff --git a/setup-environments.sh b/setup-environments.sh deleted file mode 100755 index 038a802..0000000 --- a/setup-environments.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/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