Add Makefile

Signed-off-by: Julien Riou <julien@riou.xyz>
This commit is contained in:
Julien Riou 2021-03-17 12:25:35 +01:00
parent d4fefd8176
commit b2a45c3aba
No known key found for this signature in database
GPG key ID: FF42D23B580C89F7
7 changed files with 78 additions and 17 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
bin/

19
Makefile Normal file
View file

@ -0,0 +1,19 @@
BINARY := pgterminate
GOOS := linux
GOARCH := amd64
APPVERSION := $(shell cat ./VERSION)
GOVERSION := $(shell go version | awk '{print $$3}')
GITCOMMIT := $(shell git log -1 --oneline | awk '{print $$1}')
LDFLAGS = -X main.AppVersion=${APPVERSION} -X main.GoVersion=${GOVERSION} -X main.GitCommit=${GITCOMMIT}
.PHONY: clean
build:
go build -ldflags "${LDFLAGS}" -o bin/${BINARY} cmd/${BINARY}/main.go
release:
go build -ldflags "${LDFLAGS}" -o bin/${BINARY} cmd/${BINARY}/main.go
(cd bin && tar czf ${BINARY}-${APPVERSION}-${GOOS}-${GOARCH}.tar.gz ${BINARY})
clean:
rm -rf bin

View file

@ -30,6 +30,23 @@ There's two ways to configure `pgterminate`:
Configuration file options **override** command-line arguments
# Build
Create binary:
```
make
```
Create release tarball:
```
make release
```
Cleanup:
```
make clean
```
# Usage
Connect to a remote instance and prompt for password:
```

View file

@ -1,16 +0,0 @@
#!/bin/bash
BINARY=pgterminate
VERSION=$(cat VERSION)
BUILD_PATH=/tmp/${BINARY}-${VERSION}
ldflags="-X main.AppVersion=${VERSION}"
GOOS=linux
GOARCH=amd64
export GOOS
export GOARCH
go build -ldflags "$ldflags" -o ${BUILD_PATH}/${BINARY} cmd/${BINARY}/main.go
(cd ${BUILD_PATH} && tar czf ${BINARY}-${VERSION}-${GOOS}-${GOARCH}.tar.gz ${BINARY})
echo "Archive created:"
ls -l ${BUILD_PATH}/${BINARY}-${VERSION}-${GOOS}-${GOARCH}.tar.gz

View file

@ -20,6 +20,15 @@ import (
// AppVersion stores application version at compilation time
var AppVersion string
// AppName to store application name
var AppName string = "pgterminate"
// GitCommit to set git commit at compilation time (can be empty)
var GitCommit string
// GoVersion to set Go version at compilation time
var GoVersion string
func main() {
var err error
config := base.NewConfig()
@ -68,7 +77,7 @@ func main() {
if AppVersion == "" {
AppVersion = "unknown"
}
fmt.Println(AppVersion)
showVersion()
return
}
@ -179,3 +188,10 @@ func removePid(file string) {
base.Panic(err)
}
}
func showVersion() {
if GitCommit != "" {
AppVersion = fmt.Sprintf("%s-%s", AppVersion, GitCommit)
}
fmt.Printf("%s version %s (compiled with %s)\n", AppName, AppVersion, GoVersion)
}

9
go.mod Normal file
View file

@ -0,0 +1,9 @@
module github.com/jouir/pgterminate
go 1.13
require (
github.com/lib/pq v1.10.0
golang.org/x/crypto v0.0.0-20210314154223-e6e6c4f2bb5b
gopkg.in/yaml.v2 v2.4.0
)

15
go.sum Normal file
View file

@ -0,0 +1,15 @@
github.com/lib/pq v1.10.0 h1:Zx5DJFEYQXio93kgXnQ09fXNiUKsqv4OUEu2UtGcB1E=
github.com/lib/pq v1.10.0/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
golang.org/x/crypto v0.0.0-20210314154223-e6e6c4f2bb5b h1:wSOdpTq0/eI46Ez/LkDwIsAKA71YP2SRKBODiRWM0as=
golang.org/x/crypto v0.0.0-20210314154223-e6e6c4f2bb5b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=