diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..96f81bc --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +Dockerfile +.git 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) diff --git a/Dockerfile b/Dockerfile index a2dd072..bbbedd0 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,22 @@ 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 + +FROM alpine:3.8 + +COPY --from=build --chown=daemon:daemon /stage /go + +WORKDIR /go +VOLUME /go/keys EXPOSE 8080 -CMD ["writefreely"] +USER daemon + +CMD ["bin/writefreely"] diff --git a/Makefile b/Makefile index 126bbb1..33eb3ae 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,8 @@ GOBUILD=$(GOCMD) build $(LDFLAGS) GOTEST=$(GOCMD) test $(LDFLAGS) GOGET=$(GOCMD) get BINARY_NAME=writefreely +DOCKERCMD=docker +IMAGE_NAME=writeas/writefreely all : build @@ -22,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 ./... @@ -54,6 +59,11 @@ release : clean ui $(MAKE) build-windows 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) 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) diff --git a/app.go b/app.go index d72ee49..4052639 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.4" + // DEPRECATED VARS // TODO: pass app.cfg into GetCollection* calls so we can get these values // from Collection methods and we no longer need these. @@ -404,22 +404,28 @@ 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") + 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) }() - log.Info("Serving on https://localhost:443") + log.Info("Serving on https://%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",