Skip to content

Instantly share code, notes, and snippets.

@tankakatan
Last active April 10, 2020 08:43
Show Gist options
  • Save tankakatan/ef9dd579238234559c3ba8f4f7bf1038 to your computer and use it in GitHub Desktop.
Save tankakatan/ef9dd579238234559c3ba8f4f7bf1038 to your computer and use it in GitHub Desktop.
An example of how to build grafana tanka image and use it as a standalone out of the box tanka cli convenient for CI automation.
# https://stackoverflow.com/questions/56645546/from-as-in-dockerfile-not-working-as-i-expect
# Installing jsonnet-bundler
FROM golang:alpine AS go_jb
RUN apk --no-cache add git
RUN go get -u github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb
# Installing docker & kubectl
FROM docker:latest
RUN apk --no-cache add curl git
# Copying jsonnet-bundler
RUN mkdir -p /go/bin
COPY --from=go_jb /go/bin/jb /go/bin/
ENV PATH="/go/bin:${PATH}"
# Installing kubctl & tanka
RUN curl -L -o /usr/local/bin/kubectl "https://storage.googleapis.com/kubernetes-release/release/`curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt`/bin/linux/amd64/kubectl" \
&& chmod a+x /usr/local/bin/kubectl
RUN curl -L -o /usr/local/bin/tk "https://github.com/grafana/tanka/releases/download/v0.8.0/tk-linux-amd64" \
&& chmod a+x /usr/local/bin/tk
ENTRYPOINT [ "/usr/local/bin/tk" ]
#!/bin/bash
image="tanka:alpine"
cmd=''
path=$(pwd)
for arg in "$@"; do
case $arg in
-b | --build ) build=true; shift ;;
-p* | --path* )
path="${arg#*=}";
path="$(cd $(dirname $path)/$(basename $path) && pwd)";
shift
;;
* ) cmd="$cmd $1"; shift ;;
esac
done
if [[ $build == true ]]; then
docker build --rm -f Dockerfile.tanka -t $image .
docker rmi -f $(docker images -qa -f 'dangling=true') # cleanup
fi
if [[ $cmd != '' ]]; then
config='/data/.cluster.config'
docker run \
--rm \
--net=host \
--name tanka \
-v $path:/data:rw \
-w /data \
-e KUBECONFIG="$config" \
-e PAGER="more" \
-it \
$image \
$cmd
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment