From 40b556d4bdffb7df96651b52d77b35805d3c303e Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 10 Oct 2019 21:21:55 +0200 Subject: [PATCH 1/5] Add go modules support --- Dockerfile.build | 2 +- go.mod | 17 +++++++++++++++++ main.go | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 go.mod diff --git a/Dockerfile.build b/Dockerfile.build index 749e08b0..8a03eee1 100644 --- a/Dockerfile.build +++ b/Dockerfile.build @@ -11,7 +11,7 @@ RUN go get -v \ github.com/jteeuwen/go-bindata/... \ github.com/dustin/go-humanize \ github.com/julienschmidt/httprouter \ - github.com/Sirupsen/logrus \ + github.com/sirupsen/logrus \ github.com/gorilla/securecookie \ golang.org/x/crypto/acme/autocert \ golang.org/x/time/rate \ diff --git a/go.mod b/go.mod new file mode 100644 index 00000000..e7fc4df7 --- /dev/null +++ b/go.mod @@ -0,0 +1,17 @@ +module github.com/subspacecloud/subspace + +require ( + github.com/beevik/etree v1.1.0 // indirect + github.com/crewjam/saml v0.0.0-20190521120225-344d075952c9 + github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect + github.com/dustin/go-humanize v1.0.0 + github.com/gorilla/securecookie v1.1.1 + github.com/jonboulle/clockwork v0.1.0 // indirect + github.com/julienschmidt/httprouter v1.3.0 + github.com/russellhaering/goxmldsig v0.0.0-20180430223755-7acd5e4a6ef7 // indirect + github.com/sirupsen/logrus v1.4.2 + github.com/skip2/go-qrcode v0.0.0-20190110000554-dc11ecdae0a9 + golang.org/x/crypto v0.0.0-20191010185427-af544f31c8ac + golang.org/x/net v0.0.0-20191009170851-d66e71096ffb + gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df +) diff --git a/main.go b/main.go index 1508483a..37313511 100644 --- a/main.go +++ b/main.go @@ -19,7 +19,7 @@ import ( "github.com/julienschmidt/httprouter" - log "github.com/Sirupsen/logrus" + log "github.com/sirupsen/logrus" "github.com/crewjam/saml" "github.com/crewjam/saml/samlsp" "github.com/gorilla/securecookie" From 09c161f336489ab47dec2b8a5db9dbc340a05d62 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 10 Oct 2019 22:22:12 +0200 Subject: [PATCH 2/5] Fix Docker build with Go modules --- Dockerfile.build | 22 ++++------------------ assets.go | 7 +++++++ go.mod | 3 +++ 3 files changed, 14 insertions(+), 18 deletions(-) create mode 100644 assets.go diff --git a/Dockerfile.build b/Dockerfile.build index 8a03eee1..20c4b76e 100644 --- a/Dockerfile.build +++ b/Dockerfile.build @@ -5,23 +5,10 @@ RUN apt-get update \ && apt-get install -y git \ && rm -rf /var/lib/apt/lists/* -WORKDIR /go/src/github.com/subspacecloud/subspace - -RUN go get -v \ - github.com/jteeuwen/go-bindata/... \ - github.com/dustin/go-humanize \ - github.com/julienschmidt/httprouter \ - github.com/sirupsen/logrus \ - github.com/gorilla/securecookie \ - golang.org/x/crypto/acme/autocert \ - golang.org/x/time/rate \ - golang.org/x/crypto/bcrypt \ - go.uber.org/zap \ - gopkg.in/gomail.v2 \ - github.com/crewjam/saml \ - github.com/dgrijalva/jwt-go \ - github.com/skip2/go-qrcode +WORKDIR /src +# go.mod and go.sum if exists +COPY go.* ./ COPY *.go ./ COPY static ./static COPY templates ./templates @@ -30,9 +17,8 @@ COPY email ./email ARG BUILD_VERSION=unknown ENV GODEBUG="netdns=go http2server=0" -ENV GOPATH="/go" -RUN go-bindata --pkg main static/... templates/... email/... \ +RUN go generate \ && go fmt \ && go vet --all diff --git a/assets.go b/assets.go new file mode 100644 index 00000000..4ea9fafc --- /dev/null +++ b/assets.go @@ -0,0 +1,7 @@ +package main + +import ( + _ "github.com/jteeuwen/go-bindata" +) + +//go:generate go run github.com/jteeuwen/go-bindata/go-bindata --pkg main static/... templates/... email/... diff --git a/go.mod b/go.mod index e7fc4df7..5749da15 100644 --- a/go.mod +++ b/go.mod @@ -7,11 +7,14 @@ require ( github.com/dustin/go-humanize v1.0.0 github.com/gorilla/securecookie v1.1.1 github.com/jonboulle/clockwork v0.1.0 // indirect + github.com/jteeuwen/go-bindata v3.0.8-0.20180305030458-6025e8de665b+incompatible github.com/julienschmidt/httprouter v1.3.0 + github.com/kr/pretty v0.1.0 // indirect github.com/russellhaering/goxmldsig v0.0.0-20180430223755-7acd5e4a6ef7 // indirect github.com/sirupsen/logrus v1.4.2 github.com/skip2/go-qrcode v0.0.0-20190110000554-dc11ecdae0a9 golang.org/x/crypto v0.0.0-20191010185427-af544f31c8ac golang.org/x/net v0.0.0-20191009170851-d66e71096ffb + gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df ) From a5c9b640a135227c7a2dcb86f77b403b38ab1849 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 10 Oct 2019 22:35:13 +0200 Subject: [PATCH 3/5] gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..d50d4e4b --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +subspace-linux-amd64 +bindata.go From 4d35944692a61325251a7d65c84db4089ac4f7b5 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 10 Oct 2019 22:35:40 +0200 Subject: [PATCH 4/5] go fmt --- main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.go b/main.go index 37313511..21b202ec 100644 --- a/main.go +++ b/main.go @@ -19,10 +19,10 @@ import ( "github.com/julienschmidt/httprouter" - log "github.com/sirupsen/logrus" "github.com/crewjam/saml" "github.com/crewjam/saml/samlsp" "github.com/gorilla/securecookie" + log "github.com/sirupsen/logrus" "golang.org/x/crypto/acme/autocert" ) From e0d3692329c2557826109c204c9bc61d9628abcc Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Thu, 10 Oct 2019 22:48:15 +0200 Subject: [PATCH 5/5] Decouple build logic with the container build, but reuse it --- Dockerfile.build | 11 ++++------- Makefile | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 Makefile diff --git a/Dockerfile.build b/Dockerfile.build index 20c4b76e..850ba25e 100644 --- a/Dockerfile.build +++ b/Dockerfile.build @@ -2,11 +2,12 @@ FROM golang:1.11.5 MAINTAINER github.com/subspacecloud/subspace RUN apt-get update \ - && apt-get install -y git \ + && apt-get install -y git make \ && rm -rf /var/lib/apt/lists/* WORKDIR /src +COPY Makefile ./ # go.mod and go.sum if exists COPY go.* ./ COPY *.go ./ @@ -18,9 +19,5 @@ ARG BUILD_VERSION=unknown ENV GODEBUG="netdns=go http2server=0" -RUN go generate \ - && go fmt \ - && go vet --all - -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \ - go build -v --compiler gc --ldflags "-extldflags -static -s -w -X main.version=${BUILD_VERSION}" -o /usr/bin/subspace-linux-amd64 +RUN make BUILD_VERSION=${BUILD_VERSION} +RUN mv subspace-linux-amd64 /usr/bin/subspace-linux-amd64 diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..4100cab1 --- /dev/null +++ b/Makefile @@ -0,0 +1,15 @@ +all: subspace-linux-amd64 + +BUILD_VERSION?=unknown + +subspace-linux-amd64: + go generate \ + && go fmt \ + && go vet --all + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \ + go build -v --compiler gc --ldflags "-extldflags -static -s -w -X main.version=${BUILD_VERSION}" -o subspace-linux-amd64 + +clean: + rm -f subspace-linux-amd64 bindata.go + +.PHONY: clean