Skip to content

Commit 4171311

Browse files
Improve build process and restructure project
The build process now allows for reproducable builds resulting in the same checksums every time the build pipeline is executed. This is achieved by overwriting the timestamps of build targets in zip-files with the timestamp of the latest git commit. The latest commit hash of the git repository is used to provide a reproducable build identifier. To allow the standard go install routine to install goad the goad.go file is moved into a separate package. Allowing for a main.go calling the cli in the project root. These changes facilitate the creation of a recipe for the homebrew package manager. Also we update the base image within the docker file since we are using a newer version of git to format the date in this new build process. The old base image contained an older version of git.
1 parent 2275f8a commit 4171311

File tree

9 files changed

+116
-32
lines changed

9 files changed

+116
-32
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM golang:1.8
1+
FROM golang:1.8.1-stretch
22

33
RUN apt-get update
44
RUN apt-get install -y zip

Makefile

Lines changed: 78 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,94 @@
1+
SHELL := /bin/bash
2+
3+
# name of the binary created
4+
TARGET := goad
5+
6+
# Prepend our vendor directory to the system GOPATH
7+
# so that import path resolution will prioritize
8+
# our third party snapshots.
9+
GOPATH := ${PWD}/vendor:${GOPATH}
10+
export GOPATH
11+
12+
# These will be provided to the target
13+
VERSION := 1.3.0
14+
BUILD := `git rev-parse HEAD`
15+
16+
# Timestamp of last commit to allow for reproducable builds
17+
TIMESTAMP := `git log -1 --date=format:%Y%m%d%H%M --pretty=format:%cd`
18+
19+
# Use linker flags to provide version/build settings to the target
20+
LDFLAGS = -ldflags "-X=github.com/goadapp/goad/version.version=$(VERSION) -X=github.com/goadapp/goad/version.build=$(BUILD)"
21+
22+
# go source files, ignore vendor directory
23+
SRC = $(shell find . -type f -name '*.go' -not -path "./vendor/*")
24+
25+
# go source folders to test
26+
TEST = $(shell go list ./... | grep -v /vendor/)
27+
28+
# $(GO-BUILD) command
29+
GO-BUILD = go build $(LDFLAGS)
30+
31+
# $(ZIP) command ignoring timestamps and using UTC timezone
32+
ZIP = TZ=UTC zip -jrX
33+
34+
.PHONY: lambda bindata clean all-zip all linux osx windows check fmt test install uninstall
35+
136
all: osx linux windows
237

3-
test:
4-
go test ./...
38+
test: bindata
39+
@go test $(TEST)
540

641
lambda:
7-
GOOS=linux GOARCH=amd64 go build -o data/lambda/goad-lambda ./lambda
8-
zip -jr data/lambda data/lambda
42+
@GOOS=linux GOARCH=amd64 $(GO-BUILD) -o data/lambda/goad-lambda ./lambda
43+
@find data/lambda -exec touch -t $(TIMESTAMP) {} \; # strip timestamp
44+
@$(ZIP) data/lambda data/lambda
945

1046
bindata: lambda
11-
go get github.com/jteeuwen/go-bindata/...
12-
go-bindata -nocompress -pkg infrastructure -o infrastructure/bindata.go data/lambda.zip
47+
@go get -u github.com/jteeuwen/go-bindata/...
48+
@go-bindata -modtime $(TIMESTAMP) -nocompress -pkg infrastructure -o infrastructure/bindata.go data/lambda.zip
1349

1450
linux: bindata
15-
GOOS=linux GOARCH=amd64 go build -o ./build/linux/x86-64/goad ./cli
16-
GOOS=linux GOARCH=386 go build -o ./build/linux/x86/goad ./cli
51+
@GOOS=linux GOARCH=amd64 $(GO-BUILD) -o build/linux/x86-64/$(TARGET)
52+
@GOOS=linux GOARCH=386 $(GO-BUILD) -o build/linux/x86/$(TARGET)
1753

1854
osx: bindata
19-
GOOS=darwin GOARCH=amd64 go build -o ./build/osx/x86-64/goad ./cli
55+
@GOOS=darwin GOARCH=amd64 $(GO-BUILD) -o build/osx/x86-64/$(TARGET)
2056

2157
windows: bindata
22-
GOOS=windows GOARCH=amd64 go build -o ./build/windows/x86-64/goad ./cli
23-
GOOS=windows GOARCH=386 go build -o ./build/windows/x86/goad ./cli
58+
@GOOS=windows GOARCH=amd64 $(GO-BUILD) -o build/windows/x86-64/$(TARGET)
59+
@GOOS=windows GOARCH=386 $(GO-BUILD) -o build/windows/x86/$(TARGET)
2460

2561
clean:
26-
rm -rf data/lambda/goad-lambda
27-
rm -rf data/lambda.zip
28-
rm -rf build
62+
@rm -rf data/lambda/goad-lambda
63+
@rm -rf data/lambda.zip
64+
@rm -rf build
65+
@rm -rf infrastructure/bindata.go
66+
67+
build: bindata
68+
@$(GO-BUILD) $(LDFLAGS) -o build/$(TARGET)
69+
70+
install: bindata
71+
@go install $(LDFLAGS)
72+
73+
uninstall: clean
74+
@go clean -i
75+
76+
fmt:
77+
@gofmt -l -w $(SRC)
78+
79+
simplify:
80+
@gofmt -s -l -w $(SRC)
81+
82+
check:
83+
@test -z $(shell gofmt -l main.go | tee /dev/stderr) || echo "[WARN] Fix formatting issues with 'make fmt'"
84+
@for d in $$(go list ./... | grep -v /vendor/); do golint $${d}; done
85+
@go tool vet ${SRC}
2986

3087
all-zip: all
31-
mkdir ./build/zip
32-
zip -jr ./build/zip/goad-osx-x86-64 ./build/osx/x86-64/goad
33-
zip -jr ./build/zip/goad-linux-x86-64 ./build/linux/x86-64/goad
34-
zip -jr ./build/zip/goad-linux-x86 ./build/linux/x86/goad
35-
zip -jr ./build/zip/goad-windows-x86-64 ./build/windows/x86-64/goad
36-
zip -jr ./build/zip/goad-windows-x86 ./build/windows/x86/goad
37-
38-
.PHONY: lambda bindata
88+
@mkdir -p ./build/zip
89+
@find build -exec touch -t $(TIMESTAMP) {} \; # strip timestamp
90+
@$(ZIP) ./build/zip/goad-osx-x86-64 ./build/osx/x86-64/goad
91+
@$(ZIP) ./build/zip/goad-linux-x86-64 ./build/linux/x86-64/goad
92+
@$(ZIP) ./build/zip/goad-linux-x86 ./build/linux/x86/goad
93+
@$(ZIP) ./build/zip/goad-windows-x86-64 ./build/windows/x86-64/goad
94+
@$(ZIP) ./build/zip/goad-windows-x86 ./build/windows/x86/goad

cli/cli.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package cli
22

33
import (
44
"encoding/json"
@@ -18,7 +18,7 @@ import (
1818
ini "gopkg.in/ini.v1"
1919

2020
"github.com/dustin/go-humanize"
21-
"github.com/goadapp/goad"
21+
"github.com/goadapp/goad/goad"
2222
"github.com/goadapp/goad/queue"
2323
"github.com/goadapp/goad/version"
2424
"github.com/nsf/termbox-go"
@@ -51,9 +51,9 @@ var (
5151
const coldef = termbox.ColorDefault
5252
const nano = 1000000000
5353

54-
func main() {
54+
func Run() {
5555
app.HelpFlag.Short('h')
56-
app.Version(version.Version)
56+
app.Version(version.String())
5757
app.VersionFlag.Short('V')
5858

5959
config := aggregateConfiguration()

cli/ini_parser_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package main
1+
package cli
22

33
import (
44
"os"
File renamed without changes.

lambda/lambda.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func main() {
5757

5858
func parseLambdaSettings() LambdaSettings {
5959
app.HelpFlag.Short('h')
60-
app.Version(version.Version)
60+
app.Version(version.String())
6161
kingpin.MustParse(app.Parse(os.Args[1:]))
6262

6363
requestParameters := requestParameters{

main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package main
2+
3+
import "github.com/goadapp/goad/cli"
4+
5+
func main() {
6+
cli.Run()
7+
}

version/version.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,31 @@ package version
33
import "strings"
44

55
// Version describes the Goad version.
6-
const Version = "1.3.0"
6+
var (
7+
version string
8+
build string
9+
)
10+
11+
// Version returns the version
12+
func Version() string {
13+
return version
14+
}
15+
16+
// Build returns the build number
17+
func Build() string {
18+
if len(build) >= 8 {
19+
return build[0:8]
20+
}
21+
return build
22+
}
23+
24+
// String returns a composed string of version and build number
25+
func String() string {
26+
return Version() + "-" + Build()
27+
}
728

829
// LambdaVersion returns a version string that can be used as a Lambda function
930
// alias.
1031
func LambdaVersion() string {
11-
return "v" + strings.Replace(Version, ".", "-", -1)
32+
return "v" + strings.Replace(String(), ".", "-", -1)
1233
}

webapi/webapi.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"log"
88
"net/http"
99

10-
"github.com/goadapp/goad"
10+
"github.com/goadapp/goad/goad"
1111
"github.com/goadapp/goad/queue"
1212
"github.com/gorilla/websocket"
1313
)

0 commit comments

Comments
 (0)