From a338cf58d01cbe5e049f847ce0a9036786a2c465 Mon Sep 17 00:00:00 2001 From: Knut Ahlers Date: Tue, 10 Apr 2018 13:15:41 +0200 Subject: [PATCH] Replace bash dockerfile generator with go version Signed-off-by: Knut Ahlers --- .config/gen-dockerfile.tpl | 31 +++++++++++++++ .config/gotools.yml | 1 + bin/gen-dockerfile-1.6 | 77 -------------------------------------- 3 files changed, 32 insertions(+), 77 deletions(-) create mode 100755 .config/gen-dockerfile.tpl delete mode 100755 bin/gen-dockerfile-1.6 diff --git a/.config/gen-dockerfile.tpl b/.config/gen-dockerfile.tpl new file mode 100755 index 0000000..e11c33c --- /dev/null +++ b/.config/gen-dockerfile.tpl @@ -0,0 +1,31 @@ +FROM golang:alpine as builder + +ADD . /go/src/{{ .package }} +WORKDIR /go/src/{{ .package }} + +RUN set -ex \ + && apk add --update git \ + && go install -ldflags "-X main.version=\$(git describe --tags || git rev-parse --short HEAD || echo dev)" + +FROM alpine:latest + +LABEL maintainer "{{ .git_name }} <{{ .git_mail }}>" + +RUN set -ex \ + {{ if ne .timezone "" -}} + && apk --no-cache add tzdata \ + && cp /usr/share/zoneinfo/{{ .timezone }} /etc/localtime \ + && echo "{{ .timezone }}" > /etc/timezone \ + && apk --no-cache del --purge tzdata \ + {{- end -}} + && apk --no-cache add ca-certificates + +COPY --from=builder /go/bin/{{ .binary }} /usr/local/bin/{{ .binary }} + +{{ if .expose }}EXPOSE{{ range .expose }} {{.}}{{ end }}{{end}} +{{ if ne .volumes `""` }}VOLUME [{{ .volumes }}]{{ end }} + +ENTRYPOINT ["/usr/local/bin/{{ .binary }}"] +CMD ["--"] + +# vim: set ft=Dockerfile: diff --git a/.config/gotools.yml b/.config/gotools.yml index 979c436..a9b7f6b 100644 --- a/.config/gotools.yml +++ b/.config/gotools.yml @@ -25,6 +25,7 @@ packages: - name: github.com/github/hub - name: github.com/hashicorp/packer - name: github.com/hetznercloud/terraform-provider-hcloud + - name: github.com/Luzifer/gen-dockerfile - name: github.com/Luzifer/git-changerelease - name: github.com/Luzifer/password - name: github.com/Luzifer/share diff --git a/bin/gen-dockerfile-1.6 b/bin/gen-dockerfile-1.6 deleted file mode 100755 index ffde29a..0000000 --- a/bin/gen-dockerfile-1.6 +++ /dev/null @@ -1,77 +0,0 @@ -#!/bin/bash - -PWD=$(pwd) -PACKAGE=${PWD/${GOPATH}\/src\//} -BINARY=$(basename ${PACKAGE}) - -GIT_NAME=$(git config --get user.name) -GIT_MAIL=$(git config --get user.email) - -if [ -e "${PWD}/Godeps/_workspace/src" ]; then - OVERRIDE_GOPATH="/go:/go/src/${PACKAGE}/Godeps/_workspace" -fi - -EXPOSE="EXPOSE" - -while getopts ":e:t:v:" opt; do - case $opt in - e) - EXPOSE="${EXPOSE} ${OPTARG}" - ;; - t) - TIMEZONE=${OPTARG} - ;; - v) - VOLUME="${VOLUME}, \"${OPTARG}\"" - ;; - :) - echo "Option -$OPTARG requires an argument." >&2 - exit 1 - ;; - esac -done - -# Header -cat <" - -EOF - -# Support old (pre-1.6) Godep style -[ -z "${OVERRIDE_GOPATH}" ] || echo -e "ENV GOPATH ${OVERRIDE_GOPATH}\n" - -# Allow setting timezone using `-t Europe/Berlin` -[ -z "${TIMEZONE}" ] || cat < /etc/timezone \\ - && apk del --purge tzdata - -EOF - -# Build binary -cat <