From 2619e02988688183a169aefc2ce5112491f9400a Mon Sep 17 00:00:00 2001 From: Mahmoud Rahbar Azad Date: Thu, 25 Oct 2018 22:32:22 +0200 Subject: [PATCH] replaced .travis.yml with multistage Docker build --- .travis.yml | 27 --------------------------- Dockerfile | 20 ++++++++++++++++++++ build.sh | 4 ++++ 3 files changed, 24 insertions(+), 27 deletions(-) delete mode 100644 .travis.yml create mode 100644 Dockerfile create mode 100644 build.sh diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 1339ed5..0000000 --- a/.travis.yml +++ /dev/null @@ -1,27 +0,0 @@ -language: go - -# Force-enable Go modules. This will be unnecessary when Go 1.12 lands. -env: -- GO111MODULE=on - -# You don't need to test on very old version of the Go compiler. It's the user's -# responsibility to keep their compilers up to date. -go: -- 1.11.x - -# Only clone the most recent commit. -git: - depth: 1 - -# Skip the install step. Don't `go get` dependencies. Only build with the code -# in vendor/ -install: true - -notifications: - email: false - -before_script: -- go install -mod vendor github.com/mitchellh/gox - -script: -- gox -output="hetzner-sb-notifier_{{.OS}}_{{.Arch}}" \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d9263ba --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM golang:alpine as builder + +RUN apk update && apk add git && apk add ca-certificates +RUN adduser -D -g '' appuser +RUN mkdir /hetzner-sb-notifier +COPY . /hetzner-sb-notifier/ +WORKDIR /hetzner-sb-notifier + +ENV VERSION=1.0 +RUN chmod +x build.sh + +RUN /hetzner-sb-notifier/build.sh linux + +FROM scratch +COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ +COPY --from=builder /etc/passwd /etc/passwd +COPY --from=builder /hetzner-sb-notifier/build/hetzner-sb-notifier_linux_amd64 /hetzner-sb-notifier +RUN chmod +x hetzner-sb-notifier +USER appuser +ENTRYPOINT ["/hetzner-sb-notifier"] \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..2f5274d --- /dev/null +++ b/build.sh @@ -0,0 +1,4 @@ +GO111MODULE=on +go get github.com/mitchellh/gox +go get ./... +gox -output="build/hetzner-sb-notifier_{{.OS}}_{{.Arch}}_${VERSION}" -osarch=$1/amd64 \ No newline at end of file