diff --git a/.gitignore b/.gitignore index c14a297..c2caa08 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ -go.sum \ No newline at end of file +go.sum +build/ +.idea/* +*.iml \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index d9263ba..9e93d32 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,20 +1,4 @@ -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 - +FROM centurylink/ca-certs 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 +ADD ./build/hetzner-sb-notifier_linux_amd64_1.0 / +ENTRYPOINT ["/hetzner-sb-notifier_linux_amd64_1.0"] \ No newline at end of file diff --git a/Dockerfile_with_build b/Dockerfile_with_build new file mode 100644 index 0000000..9ae0f43 --- /dev/null +++ b/Dockerfile_with_build @@ -0,0 +1,14 @@ +FROM golang:1.11-stretch as builder + +RUN mkdir /hetzner-sb-notifier +COPY . /hetzner-sb-notifier/ +WORKDIR /hetzner-sb-notifier + +RUN chmod +x build.sh + +RUN /hetzner-sb-notifier/build.sh linux +RUN ls -lth /hetzner-sb-notifier/builds + +FROM centurylink/ca-certs +COPY --from=builder /hetzner-sb-notifier/builds /root +ENTRYPOINT ["/root/hetzner-sb-notifier_linux_amd64_1.0"] \ No newline at end of file diff --git a/Readme.md b/Readme.md index 952cc9f..7f1f48d 100644 --- a/Readme.md +++ b/Readme.md @@ -42,4 +42,8 @@ Got 545 offers. Filtered offers: 3 ## Build -The Go project uses Go Modules \ No newline at end of file +The Go project uses Go Modules and can be easily build with the wrapper script build.sh: +```` +chmod +x build.sh +./build.sh +```` \ No newline at end of file diff --git a/build.sh b/build.sh index 2f5274d..efb16b5 100644 --- a/build.sh +++ b/build.sh @@ -1,4 +1,12 @@ +VERSION=1.0 GO111MODULE=on -go get github.com/mitchellh/gox +CGO_ENABLED=0 +GOOS=linux +GOARCH=amd64 + +echo "Fetching dependencies" go get ./... -gox -output="build/hetzner-sb-notifier_{{.OS}}_{{.Arch}}_${VERSION}" -osarch=$1/amd64 \ No newline at end of file +echo "Building project" +mkdir builds +go build -a -installsuffix cgo -o ./builds/hetzner-sb-notifier_${GOOS}_${GOARCH}_${VERSION} . +echo "Done" diff --git a/go.mod b/go.mod index 189b1b4..df68788 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,8 @@ require ( cloud.google.com/go v0.31.0 github.com/golang/protobuf v1.2.0 github.com/googleapis/gax-go v2.0.0+incompatible // indirect + github.com/mitchellh/gox v0.4.0 // indirect + github.com/mitchellh/iochan v1.0.0 // indirect go.opencensus.io v0.18.0 // indirect golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519 // indirect google.golang.org/api v0.0.0-20181021000519-a2651947f503 // indirect