From 5039853edcb49b53859167648c26b80f7577abba Mon Sep 17 00:00:00 2001 From: Brad Koehn Date: Wed, 21 Nov 2018 10:38:56 -0600 Subject: [PATCH 01/15] Updated Dockerfile to produce smaller image with minimum content and a few extra features; added .dockerignore --- .dockerignore | 1 + Dockerfile | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..9414382 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +Dockerfile diff --git a/Dockerfile b/Dockerfile index a2dd072..535b45d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.11.2-alpine3.8 +FROM golang:1.11.2-alpine3.8 as build RUN apk add --update nodejs nodejs-npm make git RUN npm install -g less @@ -11,5 +11,21 @@ RUN make install RUN make ui RUN make deps +RUN mkdir /stage && \ + cp -R /go/bin \ + /go/src/app/templates \ + /go/src/app/static \ + /go/src/app/schema.sql \ + /go/src/app/pages \ + /go/src/app/keys \ + /stage && ls -l /stage + +FROM golang:1.11.2-alpine3.8 + +COPY --from=build --chown=daemon:daemon /stage /go + +VOLUME /go/keys EXPOSE 8080 +USER daemon + CMD ["writefreely"] From f2a07db23ad56c90092da400ee04b5ef3de46609 Mon Sep 17 00:00:00 2001 From: Brad Koehn Date: Wed, 21 Nov 2018 12:51:37 -0600 Subject: [PATCH 02/15] switched to much smaller alpine image since golang not required at runtime --- Dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 535b45d..ddcfdf5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,12 +20,13 @@ RUN mkdir /stage && \ /go/src/app/keys \ /stage && ls -l /stage -FROM golang:1.11.2-alpine3.8 +FROM alpine:3.8 COPY --from=build --chown=daemon:daemon /stage /go +WORKDIR /go VOLUME /go/keys EXPOSE 8080 USER daemon -CMD ["writefreely"] +CMD ["bin/writefreely"] From aebad1ce54ffaf7106903d7723e0f6219b2b2803 Mon Sep 17 00:00:00 2001 From: Brad Koehn Date: Thu, 22 Nov 2018 06:56:29 -0600 Subject: [PATCH 03/15] added .git to make builds cache more effectively and run faster --- .dockerignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.dockerignore b/.dockerignore index 9414382..96f81bc 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,2 @@ Dockerfile +.git From 6f0c7aed66f6d136e3ca35ed2e02b0b8ff185d70 Mon Sep 17 00:00:00 2001 From: Brad Koehn Date: Thu, 22 Nov 2018 06:57:05 -0600 Subject: [PATCH 04/15] removed an unnecessary debugging statement --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index ddcfdf5..bbbedd0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,7 +18,7 @@ RUN mkdir /stage && \ /go/src/app/schema.sql \ /go/src/app/pages \ /go/src/app/keys \ - /stage && ls -l /stage + /stage FROM alpine:3.8 From 50a6a1ee40495f45bab0233872d11169bb607a83 Mon Sep 17 00:00:00 2001 From: koehn Date: Sat, 24 Nov 2018 17:49:52 +0000 Subject: [PATCH 05/15] added docker support to `make release` --- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 126bbb1..a899879 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,7 @@ GOBUILD=$(GOCMD) build $(LDFLAGS) GOTEST=$(GOCMD) test $(LDFLAGS) GOGET=$(GOCMD) get BINARY_NAME=writefreely +IMAGE_NAME=writeas/writefreely all : build @@ -53,7 +54,8 @@ release : clean ui rm build/$(BINARY_NAME) $(MAKE) build-windows cp cmd/writefreely/$(BINARY_NAME).exe build - cd build; zip -r ../$(BINARY_NAME)_$(GITREV)_windows_amd64.zip ./* + cd build; zip -r ../$(BINARY_NAME)_$(GITREV)_windows_amd64.zip ./*; cd .. + docker build -t $(IMAGE_NAME):latest -t $(IMAGE_NAME):$(GITREV) . ui : force_look cd less/; $(MAKE) $(MFLAGS) From 695bc796963916d48166e532cd08b5c027d4fbcf Mon Sep 17 00:00:00 2001 From: koehn Date: Sat, 24 Nov 2018 17:57:01 +0000 Subject: [PATCH 06/15] extracted docker command a la `go` and `make` --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index a899879..fa7989d 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,7 @@ GOBUILD=$(GOCMD) build $(LDFLAGS) GOTEST=$(GOCMD) test $(LDFLAGS) GOGET=$(GOCMD) get BINARY_NAME=writefreely +DOCKERCMD=docker IMAGE_NAME=writeas/writefreely all : build @@ -55,7 +56,7 @@ release : clean ui $(MAKE) build-windows cp cmd/writefreely/$(BINARY_NAME).exe build cd build; zip -r ../$(BINARY_NAME)_$(GITREV)_windows_amd64.zip ./*; cd .. - docker build -t $(IMAGE_NAME):latest -t $(IMAGE_NAME):$(GITREV) . + $(DOCKERCMD) build -t $(IMAGE_NAME):latest -t $(IMAGE_NAME):$(GITREV) . ui : force_look cd less/; $(MAKE) $(MFLAGS) From 402f66770e6fdca3f6bf49a49f978234fab2dd26 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Sat, 24 Nov 2018 14:11:39 -0500 Subject: [PATCH 07/15] Move docker build to `make build-docker` --- Makefile | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index fa7989d..cbe27f1 100644 --- a/Makefile +++ b/Makefile @@ -24,6 +24,9 @@ build-windows: deps build-darwin: deps cd cmd/writefreely; GOOS=darwin GOARCH=amd64 $(GOBUILD) -v +build-docker : + $(DOCKERCMD) build -t $(IMAGE_NAME):latest -t $(IMAGE_NAME):$(GITREV) . + test: $(GOTEST) -v ./... @@ -55,8 +58,8 @@ release : clean ui rm build/$(BINARY_NAME) $(MAKE) build-windows cp cmd/writefreely/$(BINARY_NAME).exe build - cd build; zip -r ../$(BINARY_NAME)_$(GITREV)_windows_amd64.zip ./*; cd .. - $(DOCKERCMD) build -t $(IMAGE_NAME):latest -t $(IMAGE_NAME):$(GITREV) . + cd build; zip -r ../$(BINARY_NAME)_$(GITREV)_windows_amd64.zip ./* + $(MAKE) build-docker ui : force_look cd less/; $(MAKE) $(MFLAGS) From 7bbc1b4b4717c64dc82cc3a4a8b8c23e40ef3049 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Sat, 24 Nov 2018 14:18:11 -0500 Subject: [PATCH 08/15] Add `make release-docker` --- Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Makefile b/Makefile index cbe27f1..33eb3ae 100644 --- a/Makefile +++ b/Makefile @@ -60,6 +60,10 @@ release : clean ui cp cmd/writefreely/$(BINARY_NAME).exe build cd build; zip -r ../$(BINARY_NAME)_$(GITREV)_windows_amd64.zip ./* $(MAKE) build-docker + $(MAKE) release-docker + +release-docker : + $(DOCKERCMD) push $(IMAGE_NAME) ui : force_look cd less/; $(MAKE) $(MFLAGS) From 6ed9fef88fb64d01ae17f4406adfc5007e985de0 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Sat, 24 Nov 2018 18:43:33 -0500 Subject: [PATCH 09/15] Add @koehn to AUTHORS --- AUTHORS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AUTHORS.md b/AUTHORS.md index bf363a6..b4ceb1e 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -5,4 +5,4 @@ WriteFreely is built by [Matt Baer](https://github.com/thebaer), with contributi * [Jean-Francois Arseneau](https://github.com/TheJF) * [Ben Overmyer](https://github.com/BenOvermyer) * [Marcel van der Boom](https://github.com/mrvdb) - +* [Brad Koehn](https://github.com/koehn) From f0250d501fbce80ffc700be7ecdb66ad543f83bf Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Mon, 26 Nov 2018 08:37:06 -0500 Subject: [PATCH 10/15] Move softwareVer to var() block --- app.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app.go b/app.go index d72ee49..3f92d53 100644 --- a/app.go +++ b/app.go @@ -36,12 +36,12 @@ const ( softwareURL = "https://writefreely.org" ) -// Software version can be set from git env using -ldflags -var softwareVer = "0.3" - var ( debugging bool + // Software version can be set from git env using -ldflags + softwareVer = "0.3" + // DEPRECATED VARS // TODO: pass app.cfg into GetCollection* calls so we can get these values // from Collection methods and we no longer need these. From 42a47258da674c70d10a8a1b2f2df96a6491526f Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Mon, 26 Nov 2018 08:37:36 -0500 Subject: [PATCH 11/15] Bump version to 0.4 --- app.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.go b/app.go index 3f92d53..5403610 100644 --- a/app.go +++ b/app.go @@ -40,7 +40,7 @@ var ( debugging bool // Software version can be set from git env using -ldflags - softwareVer = "0.3" + softwareVer = "0.4" // DEPRECATED VARS // TODO: pass app.cfg into GetCollection* calls so we can get these values From 94badbc83841d2185129d64e7e9aca454efe0b81 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Mon, 26 Nov 2018 08:39:15 -0500 Subject: [PATCH 12/15] Only log ActivityPub info when debugging --- activitypub.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/activitypub.go b/activitypub.go index 48be9f0..ad8f420 100644 --- a/activitypub.go +++ b/activitypub.go @@ -254,7 +254,9 @@ func handleFetchCollectionInbox(app *app, w http.ResponseWriter, r *http.Request // 2) Errors are propagated to res.Deserialize call below m["@context"] = []string{activitystreams.Namespace} b, _ := json.Marshal(m) - log.Info("Follow: %s", b) + if debugging { + log.Info("Follow: %s", b) + } _, followID := f.GetId() if followID == nil { @@ -287,7 +289,9 @@ func handleFetchCollectionInbox(app *app, w http.ResponseWriter, r *http.Request m["@context"] = []string{activitystreams.Namespace} b, _ := json.Marshal(m) - log.Info("Undo: %s", b) + if debugging { + log.Info("Undo: %s", b) + } a.AppendObject(u.Raw()) _, to = u.GetActor(0) From 543f6c9ae384bf133e4b4aaede66b5667378b0d3 Mon Sep 17 00:00:00 2001 From: Marcel van der Boom Date: Mon, 26 Nov 2018 16:50:36 +0100 Subject: [PATCH 13/15] Allow 'bind' in config to specify bind address Minimal changes, definitely WIP, to resolve: - how to support dualstack when not using localhost? - net/http package uses string, mentions IP address instead of bind, need info. --- app.go | 13 +++++++++---- config/config.go | 2 ++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/app.go b/app.go index 5403610..9019399 100644 --- a/app.go +++ b/app.go @@ -404,6 +404,10 @@ func Serve() { http.Handle("/", r) // Start web application server + var bindAddress = app.cfg.Server.Bind + if bindAddress == "" { + bindAddress = "localhost" + } if app.cfg.IsSecureStandalone() { log.Info("Serving redirects on http://localhost:80") go func() { @@ -413,13 +417,14 @@ func Serve() { log.Error("Unable to start redirect server: %v", err) }() - log.Info("Serving on https://localhost:443") + log.Info("Serving on %s:443", bindAddress) log.Info("---") - err = http.ListenAndServeTLS(":443", app.cfg.Server.TLSCertPath, app.cfg.Server.TLSKeyPath, nil) + err = http.ListenAndServeTLS( + fmt.Sprintf("%s:443", bindAddress), app.cfg.Server.TLSCertPath, app.cfg.Server.TLSKeyPath, nil) } else { - log.Info("Serving on http://localhost:%d\n", app.cfg.Server.Port) + log.Info("Serving on http://%s:%d\n", bindAddress, app.cfg.Server.Port) log.Info("---") - err = http.ListenAndServe(fmt.Sprintf(":%d", app.cfg.Server.Port), nil) + err = http.ListenAndServe(fmt.Sprintf("%s:%d", bindAddress, app.cfg.Server.Port), nil) } if err != nil { log.Error("Unable to start: %v", err) diff --git a/config/config.go b/config/config.go index 56d8848..50a904b 100644 --- a/config/config.go +++ b/config/config.go @@ -12,6 +12,7 @@ type ( ServerCfg struct { HiddenHost string `ini:"hidden_host"` Port int `ini:"port"` + Bind string `ini:"bind"` TLSCertPath string `ini:"tls_cert_path"` TLSKeyPath string `ini:"tls_key_path"` @@ -60,6 +61,7 @@ func New() *Config { return &Config{ Server: ServerCfg{ Port: 8080, + Bind: "localhost", /* IPV6 support when not using localhost? */ }, Database: DatabaseCfg{ Type: "mysql", From 875c758ba2d25390eb8430fa5c143dc1250008d3 Mon Sep 17 00:00:00 2001 From: Marcel van der Boom Date: Mon, 26 Nov 2018 18:32:18 +0100 Subject: [PATCH 14/15] Also use bind address on standalone redirect --- app.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app.go b/app.go index 9019399..96c610b 100644 --- a/app.go +++ b/app.go @@ -409,11 +409,12 @@ func Serve() { bindAddress = "localhost" } if app.cfg.IsSecureStandalone() { - log.Info("Serving redirects on http://localhost:80") + log.Info("Serving redirects on http://%s:80", bindAddress) go func() { - err = http.ListenAndServe(":80", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - http.Redirect(w, r, app.cfg.App.Host, http.StatusMovedPermanently) - })) + err = http.ListenAndServe( + fmt.Sprintf("%s:80", bindAddress), http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + http.Redirect(w, r, app.cfg.App.Host, http.StatusMovedPermanently) + })) log.Error("Unable to start redirect server: %v", err) }() From fe78d6d47fb83393635dd41a15ec796856f91c62 Mon Sep 17 00:00:00 2001 From: Matt Baer Date: Tue, 27 Nov 2018 10:55:43 -0500 Subject: [PATCH 15/15] Re-add https in log message --- app.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.go b/app.go index 96c610b..4052639 100644 --- a/app.go +++ b/app.go @@ -418,7 +418,7 @@ func Serve() { log.Error("Unable to start redirect server: %v", err) }() - log.Info("Serving on %s:443", bindAddress) + log.Info("Serving on https://%s:443", bindAddress) log.Info("---") err = http.ListenAndServeTLS( fmt.Sprintf("%s:443", bindAddress), app.cfg.Server.TLSCertPath, app.cfg.Server.TLSKeyPath, nil)