Add Makefile
Signed-off-by: Julien Riou <julien@riou.xyz>
This commit is contained in:
parent
d4fefd8176
commit
b2a45c3aba
7 changed files with 78 additions and 17 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
bin/
|
19
Makefile
Normal file
19
Makefile
Normal 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
|
17
README.md
17
README.md
|
@ -30,6 +30,23 @@ There's two ways to configure `pgterminate`:
|
||||||
|
|
||||||
Configuration file options **override** command-line arguments
|
Configuration file options **override** command-line arguments
|
||||||
|
|
||||||
|
# Build
|
||||||
|
|
||||||
|
Create binary:
|
||||||
|
```
|
||||||
|
make
|
||||||
|
```
|
||||||
|
|
||||||
|
Create release tarball:
|
||||||
|
```
|
||||||
|
make release
|
||||||
|
```
|
||||||
|
|
||||||
|
Cleanup:
|
||||||
|
```
|
||||||
|
make clean
|
||||||
|
```
|
||||||
|
|
||||||
# Usage
|
# Usage
|
||||||
Connect to a remote instance and prompt for password:
|
Connect to a remote instance and prompt for password:
|
||||||
```
|
```
|
||||||
|
|
16
build.sh
16
build.sh
|
@ -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
|
|
|
@ -20,6 +20,15 @@ import (
|
||||||
// AppVersion stores application version at compilation time
|
// AppVersion stores application version at compilation time
|
||||||
var AppVersion string
|
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() {
|
func main() {
|
||||||
var err error
|
var err error
|
||||||
config := base.NewConfig()
|
config := base.NewConfig()
|
||||||
|
@ -68,7 +77,7 @@ func main() {
|
||||||
if AppVersion == "" {
|
if AppVersion == "" {
|
||||||
AppVersion = "unknown"
|
AppVersion = "unknown"
|
||||||
}
|
}
|
||||||
fmt.Println(AppVersion)
|
showVersion()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,3 +188,10 @@ func removePid(file string) {
|
||||||
base.Panic(err)
|
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
9
go.mod
Normal 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
15
go.sum
Normal 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=
|
Loading…
Reference in a new issue