Skip to content
Permalink
Browse files

move cmd into pkg/cli and simplify entry point. add goreleaser config…

…uration for automated dist releases.
  • Loading branch information...
dannyvankooten committed Oct 30, 2018
1 parent e6704fa commit 02c2eb93f24c5013f2080ddb5715aa1575c5b96a
@@ -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:
@@ -1,55 +1,42 @@
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/...

.PHONY: npm
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).

24 main.go
@@ -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)
}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -1,4 +1,4 @@
package main
package cli

import (
"os"
@@ -15,21 +15,18 @@ 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", "")

// setup CLI app
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"

0 comments on commit 02c2eb9

Please sign in to comment.
You can’t perform that action at this time.