From d3c8c94289162f7d3459586d287bb882c6c0bd77 Mon Sep 17 00:00:00 2001 From: Ezekiel Grave Date: Wed, 15 Sep 2021 10:03:00 -0700 Subject: [PATCH] A Docker image with kubectl/terraform/cloud-sdk/etc. --- Dockerfile | 66 ++++++++++++++++++++++++++++++++++++++++++++++ README.md | 10 +++++++ run/build | 3 +++ run/check-versions | 25 ++++++++++++++++++ run/push | 5 ++++ 5 files changed, 109 insertions(+) create mode 100644 Dockerfile create mode 100644 README.md create mode 100755 run/build create mode 100755 run/check-versions create mode 100755 run/push diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..894b6b8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,66 @@ +# https://hub.docker.com/r/hashicorp/terraform/tags +FROM hashicorp/terraform:latest as terraform + +# https://hub.docker.com/r/google/cloud-sdk/tags +FROM google/cloud-sdk:alpine as gcloud + +RUN gcloud components update \ + && gcloud components install kubectl + +FROM golang:alpine as gobuilder + +RUN apk add --no-cache --update git +RUN git clone --depth 1 https://github.com/abetterinternet/prio-server src/github.com/abetterinternet/prio-server +RUN cd src/github.com/abetterinternet/prio-server/deploy-tool && go build + + +FROM alpine:latest as builder +RUN apk add --no-cache --update bash curl gcc cmake make python3-dev libffi-dev musl-dev openssl openssl-dev \ + && ln -snf `which python3` /bin/python \ + && ln -snf `which pip3` /bin/pip + +RUN addgroup -g 1000 -S clouder && adduser -u 1000 -h /home/clouder -S clouder -G clouder +RUN mkdir -p /opt/clouder/bin && chown -cR clouder:clouder /opt/clouder +RUN mkdir -p /opt/aws-cli && chown -cR clouder:clouder /opt/aws-cli + +USER clouder +RUN python -mvenv /opt/aws-cli +RUN /opt/aws-cli/bin/pip install --upgrade pip setuptools wheel +RUN /opt/aws-cli/bin/pip install --upgrade --upgrade-strategy eager \ + https://github.com/boto/botocore/archive/v2.zip \ + https://github.com/aws/aws-cli/archive/v2.zip + +ENV DESIRED_VERSION=v3.6.3 +RUN curl --progress-bar -fSL https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 \ + | HELM_INSTALL_DIR=/opt/clouder/bin USE_SUDO=false PATH="${PATH}:/opt/clouder/bin" bash + +FROM alpine:latest +LABEL maintainer="Ezekiel Grave " + +RUN apk add --no-cache --update curl make git gnupg jq ncurses openssh-client openssl python3 \ + && ln -snf `which python3` /bin/python + +RUN addgroup -g 1000 -S clouder && adduser -u 1000 -h /home/clouder -S clouder -G clouder +RUN mkdir -p /opt/clouder/bin && chown -cR clouder:clouder /opt/clouder + +COPY --from=terraform --chown=clouder:clouder /bin/terraform /opt/clouder/bin/terraform +COPY --from=gcloud /google-cloud-sdk /opt/google-cloud-sdk +COPY --from=gobuilder --chown=clouder:clouder /go/src/github.com/abetterinternet/prio-server/deploy-tool/deploy-tool /opt/clouder/bin/deploy-tool +COPY --from=builder --chown=clouder:clouder /opt/clouder/bin /opt/clouder/bin +COPY --from=builder --chown=clouder:clouder /opt/aws-cli /opt/aws-cli + +RUN chown -cR clouder:clouder /opt/clouder \ + && chmod u+x /opt/clouder/bin/* + +ENV PATH="/opt/clouder/bin:${PATH}:/opt/google-cloud-sdk/bin:/opt/aws-cli/bin" +WORKDIR /home/clouder +USER clouder + +RUN helm repo add stable https://charts.helm.sh/stable +RUN gcloud config set core/disable_usage_reporting true \ + && gcloud config set component_manager/disable_update_check true \ + && gcloud config set metrics/environment github_docker_image \ + && gcloud --version + +VOLUME /home/clouder +CMD ["/bin/ash"] diff --git a/README.md b/README.md new file mode 100644 index 0000000..d3b128b --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +# Kubernetes Tools with Terraform and Cloud SDKs (gcp/aws) + +**To Build**: +`$ ./run/build` + +**To Review**: +`$ ./run/check-versions` + +### AWS cli version +The mechanism used to install AWS CLI is a dirty trick which may break. diff --git a/run/build b/run/build new file mode 100755 index 0000000..75cd209 --- /dev/null +++ b/run/build @@ -0,0 +1,3 @@ +#!/usr/bin/env bash + +docker build -t "hub.ici.de.com/kubeterracloud:latest" . diff --git a/run/check-versions b/run/check-versions new file mode 100755 index 0000000..b103886 --- /dev/null +++ b/run/check-versions @@ -0,0 +1,25 @@ +#!/usr/bin/env bash + +BIN_VER_PAIRS=( + "terraform@--version" + "kubectl@version" + "gcloud@--version" + "aws@--version" + "helm@version" + "python@--version" + "jq@--version" + "curl@--version" + "git@--version" + "openssl@version" +) + +time { + for bin_ver in "${BIN_VER_PAIRS[@]}"; do + bin="${bin_ver%%@*}" + ver="${bin_ver##*@}" + echo -n "Version report from ${bin}: " + docker run --rm \ + --interactive --tty "hub.ici.de.com/kubeterracloud:latest" ${bin} ${ver}\ + | awk 'NR!=1 { $0="\t"$0 }{ print }' + done +} diff --git a/run/push b/run/push new file mode 100755 index 0000000..5f89a10 --- /dev/null +++ b/run/push @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +docker login -u ezekiel hub.ici.de.com\ + && docker push "hub.ici.de.com/kubeterracloud:latest" +docker logout hub.ici.de.com