Replace bash dockerfile generator with go version

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2018-04-10 13:15:41 +02:00
parent 7e4e0f8551
commit a338cf58d0
Signed by: luzifer
GPG Key ID: DC2729FDD34BE99E
3 changed files with 32 additions and 77 deletions

31
.config/gen-dockerfile.tpl Executable file
View File

@ -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:

View File

@ -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

View File

@ -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
FROM golang:alpine
LABEL maintainer "${GIT_NAME} <${GIT_MAIL}>"
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 <<EOF
RUN set -ex \\
&& apk add --update tzdata \\
&& cp /usr/share/zoneinfo/${TIMEZONE} /etc/localtime \\
&& echo "${TIMEZONE}" > /etc/timezone \\
&& apk del --purge tzdata
EOF
# Build binary
cat <<EOF
ADD . /go/src/${PACKAGE}
WORKDIR /go/src/${PACKAGE}
RUN set -ex \\
&& apk add --update git ca-certificates \\
&& go install -ldflags "-X main.version=\$(git describe --tags || git rev-parse --short HEAD || echo dev)" \\
&& apk del --purge git
EOF
# Allow exposing ports using `-e 3000`
(test "EXPOSE" != "${EXPOSE}") && echo -e "${EXPOSE}\n"
# Allow
[ -z "${VOLUME}" ] || echo -e "VOLUME [${VOLUME/, /}]\n"
# Execution information
cat <<EOF
ENTRYPOINT ["/go/bin/${BINARY}"]
CMD ["--"]
EOF