mirror of https://github.com/status-im/fathom.git
move cmd into pkg/cli and simplify entry point. add goreleaser configuration for automated dist releases.
This commit is contained in:
parent
e6704faa66
commit
02c2eb93f2
|
@ -3,6 +3,7 @@ node_modules
|
|||
!.env.example
|
||||
coverage.out
|
||||
build
|
||||
dist
|
||||
*.db
|
||||
fathom
|
||||
!cmd/fathom
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
# This is an example goreleaser.yaml file with some sane defaults.
|
||||
# Make sure to check the documentation at http://goreleaser.com
|
||||
# Documentation http://goreleaser.com
|
||||
before:
|
||||
hooks:
|
||||
- make assets/dist
|
||||
builds:
|
||||
-
|
||||
main: ./cmd/fathom/main.go
|
||||
main: main.go
|
||||
goos:
|
||||
- linux
|
||||
goarch:
|
||||
|
|
31
Makefile
31
Makefile
|
@ -1,37 +1,24 @@
|
|||
DIST := build
|
||||
EXECUTABLE := fathom
|
||||
LDFLAGS += -extldflags "-static" -X "main.Version=$(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')"
|
||||
MAIN_PKG := ./cmd/fathom
|
||||
LDFLAGS += -extldflags "-static" -X "main.version=$(shell git describe --tags --always | sed 's/-/+/' | sed 's/^v//')" -X "main.commit=$(shell git rev-parse HEAD)"
|
||||
MAIN_PKG := ./main.go
|
||||
PACKAGES ?= $(shell go list ./... | grep -v /vendor/)
|
||||
JS_SOURCES ?= $(shell find assets/src/. -name "*.js" -type f)
|
||||
ASSET_SOURCES ?= $(shell find assets/src/. -type f)
|
||||
GO_SOURCES ?= $(shell find . -name "*.go" -type f)
|
||||
SQL_SOURCES ?= $(shell find . -name "*.sql" -type f)
|
||||
ENV ?= $(shell export $(cat .env | xargs))
|
||||
GOPATH=$(shell go env GOPATH)
|
||||
|
||||
$(EXECUTABLE): $(GO_SOURCES) assets/build
|
||||
go build -o $@ $(MAIN_PKG)
|
||||
|
||||
.PHONY: all
|
||||
all: build
|
||||
|
||||
.PHONY: install
|
||||
install: $(wildcard *.go) $(GOPATH)/bin/packr
|
||||
$(GOPATH)/bin/packr install -v -ldflags '-w $(LDFLAGS)' $(MAIN_PKG)
|
||||
|
||||
.PHONY: build
|
||||
build: $(EXECUTABLE)
|
||||
|
||||
$(EXECUTABLE): $(GO_SOURCES) assets/build
|
||||
go build -o $@ $(MAIN_PKG)
|
||||
|
||||
.PHONY: docker
|
||||
docker: $(GO_SOURCES)
|
||||
GOOS=linux GOARCH=amd64 $(GOPATH)/bin/packr build -v -ldflags '-w $(LDFLAGS)' -o $(EXECUTABLE) $(MAIN_PKG)
|
||||
|
||||
.PHONY: dist
|
||||
dist: assets/dist
|
||||
GOOS=linux GOARCH=amd64 $(GOPATH)/bin/packr build -v -ldflags '-w $(LDFLAGS)' -o build/fathom-linux-amd64 $(MAIN_PKG)
|
||||
GOOS=linux GOARCH=arm64 $(GOPATH)/bin/packr build -v -ldflags '-w $(LDFLAGS)' -o build/fathom-linux-arm64 $(MAIN_PKG)
|
||||
GOOS=linux GOARCH=386 $(GOPATH)/bin/packr build -v -ldflags '-w $(LDFLAGS)' -o build/fathom-linux-386 $(MAIN_PKG)
|
||||
|
||||
$(GOPATH)/bin/packr:
|
||||
GOBIN=$(GOPATH)/bin go get github.com/gobuffalo/packr/...
|
||||
|
||||
|
@ -39,17 +26,17 @@ $(GOPATH)/bin/packr:
|
|||
npm:
|
||||
if [ ! -d "node_modules" ]; then npm install; fi
|
||||
|
||||
assets/build: $(JS_SOURCES) npm
|
||||
assets/build: $(ASSET_SOURCES) npm
|
||||
./node_modules/gulp/bin/gulp.js
|
||||
|
||||
assets/dist: $(JS_SOURCES) npm
|
||||
assets/dist: $(ASSET_SOURCES) npm
|
||||
NODE_ENV=production ./node_modules/gulp/bin/gulp.js
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
go clean -i ./...
|
||||
packr clean
|
||||
rm -rf $(EXECUTABLE) $(DIST)
|
||||
rm -rf $(EXECUTABLE)
|
||||
|
||||
.PHONY: fmt
|
||||
fmt:
|
||||
|
|
|
@ -24,10 +24,10 @@ For getting a development version of Fathom up & running, go through the followi
|
|||
|
||||
1. Ensure you have [Go](https://golang.org/doc/install#install) and [NPM](https://www.npmjs.com) installed
|
||||
1. Download the code: `git clone https://github.com/usefathom/fathom.git $GOPATH/src/github.com/usefathom/fathom`
|
||||
1. Compile the project: `make build`
|
||||
1. Compile the project into an executable: `make build`
|
||||
1. (Optional) Set [custom configuration values](docs/Configuration.md)
|
||||
1. (Optional) Register a user account: `fathom user add --email=<email> --password=<password>`
|
||||
1. Start the webserver: `fathom server` and then visit **http://localhost:8080** to access your analytics dashboard
|
||||
1. (Optional) Register a user account: `./fathom user add --email=<email> --password=<password>`
|
||||
1. Start the webserver: `./fathom server` and then visit **http://localhost:8080** to access your analytics dashboard
|
||||
|
||||
To install and run Fathom in production, [see the installation instructions](docs/Installation%20instructions.md).
|
||||
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/usefathom/fathom/pkg/cli"
|
||||
)
|
||||
|
||||
var (
|
||||
version = "dev"
|
||||
commit = "none"
|
||||
date = "unknown"
|
||||
)
|
||||
|
||||
func main() {
|
||||
err := cli.Run(version)
|
||||
if err != nil {
|
||||
fmt.Print(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
os.Exit(0)
|
||||
}
|
|
@ -6090,7 +6090,7 @@
|
|||
},
|
||||
"pretty-hrtime": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "http://registry.npmjs.org/pretty-hrtime/-/pretty-hrtime-1.0.3.tgz",
|
||||
"resolved": "https://registry.npmjs.org/pretty-hrtime/-/pretty-hrtime-1.0.3.tgz",
|
||||
"integrity": "sha1-t+PqQkNaTJsnWdmeDyAesZWALuE=",
|
||||
"dev": true
|
||||
},
|
||||
|
@ -6510,7 +6510,7 @@
|
|||
},
|
||||
"safe-regex": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "http://registry.npmjs.org/safe-regex/-/safe-regex-1.1.0.tgz",
|
||||
"resolved": "https://registry.npmjs.org/safe-regex/-/safe-regex-1.1.0.tgz",
|
||||
"integrity": "sha1-QKNmnzsHfR6UPURinhV91IAjvy4=",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package main
|
||||
package cli
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
@ -15,13 +15,10 @@ type App struct {
|
|||
config *config.Config
|
||||
}
|
||||
|
||||
// Version of build, supplied at compile time
|
||||
var Version = "latest-development"
|
||||
|
||||
// CLI application
|
||||
var app *App
|
||||
|
||||
func main() {
|
||||
func Run(v string) error {
|
||||
// force all times in UTC, regardless of server timezone
|
||||
os.Setenv("TZ", "")
|
||||
|
||||
|
@ -29,7 +26,7 @@ func main() {
|
|||
app = &App{cli.NewApp(), nil, nil}
|
||||
app.Name = "Fathom"
|
||||
app.Usage = "simple & transparent website analytics"
|
||||
app.Version = Version
|
||||
app.Version = v
|
||||
app.HelpName = "fathom"
|
||||
app.Flags = []cli.Flag{
|
||||
cli.StringFlag{
|
||||
|
@ -52,11 +49,10 @@ func main() {
|
|||
|
||||
err := app.Run(os.Args)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
os.Exit(1)
|
||||
return err
|
||||
}
|
||||
|
||||
os.Exit(0)
|
||||
return nil
|
||||
}
|
||||
|
||||
func before(c *cli.Context) error {
|
|
@ -1,4 +1,4 @@
|
|||
package main
|
||||
package cli
|
||||
|
||||
import (
|
||||
"net/http"
|
|
@ -1,4 +1,4 @@
|
|||
package main
|
||||
package cli
|
||||
|
||||
import (
|
||||
"encoding/json"
|
|
@ -1,4 +1,4 @@
|
|||
package main
|
||||
package cli
|
||||
|
||||
import (
|
||||
"errors"
|
Loading…
Reference in New Issue