Skip to content

Commit 6a57323

Browse files
committed
makefile, goreleaser and so on
1 parent 35d13b8 commit 6a57323

97 files changed

Lines changed: 16738 additions & 7 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
wait-for-pg

.goreleaser.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
before:
2+
hooks:
3+
- go mod download
4+
builds:
5+
- env:
6+
- CGO_ENABLED=0
7+
goos:
8+
- linux
9+
goarch:
10+
- amd64
11+
checksum:
12+
name_template: 'checksums.txt'
13+
snapshot:
14+
name_template: "{{ .Tag }}"
15+
changelog:
16+
sort: asc
17+
filters:
18+
exclude:
19+
- '^docs:'
20+
- '^test:'

Dockerfile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FROM golang:1.13.4-alpine3.10 as builder
2+
3+
ENV GO111MODULE=on
4+
5+
WORKDIR /go/src/github.com/mxssl/wait-for-pg
6+
COPY . .
7+
8+
# Install external dependcies
9+
RUN apk add --no-cache \
10+
ca-certificates \
11+
curl \
12+
git
13+
14+
# Compile binary
15+
RUN CGO_ENABLED=0 \
16+
GOOS=`go env GOHOSTOS` \
17+
GOARCH=`go env GOHOSTARCH` \
18+
go build -o wait-for-pg
19+
20+
# Copy compiled binary to clear Alpine Linux image
21+
FROM alpine:3.10.3
22+
WORKDIR /
23+
RUN apk add --no-cache ca-certificates
24+
COPY --from=builder /go/src/github.com/mxssl/wait-for-pg/wait-for-pg /usr/local/bin/wait-for-pg
25+
RUN chmod +x /usr/local/bin/wait-for-pg

Makefile

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
BINARY_NAME=wait-for-pg
2+
CURRENT_DIR=$(shell pwd)
3+
TAG=$(shell git name-rev --tags --name-only $(git rev-parse HEAD))
4+
DOCKER_REGISTRY=mxssl
5+
export GO111MODULE=on
6+
7+
.PHONY: all build clean lint test init github-release-dry github-release docker-release
8+
9+
all: build
10+
11+
build:
12+
go build -o ${BINARY_NAME} -v
13+
14+
clean:
15+
rm -f ${BINARY_NAME}
16+
17+
lint:
18+
golangci-lint run -v
19+
20+
test:
21+
go test -v ./...
22+
23+
init:
24+
go mod init
25+
26+
tidy:
27+
go mod tidy
28+
29+
github-release-dry:
30+
echo -e "TAG: ${TAG}"
31+
goreleaser release --rm-dist --snapshot --skip-publish
32+
33+
github-release:
34+
echo -e "TAG: ${TAG}"
35+
goreleaser release --rm-dist
36+
37+
docker-release:
38+
echo -e "Registry: ${DOCKER_REGISTRY}"
39+
echo -e "TAG: ${TAG}"
40+
docker build --tag ${DOCKER_REGISTRY}/${BINARY_NAME}:${TAG} .
41+
docker push ${DOCKER_REGISTRY}/${BINARY_NAME}:${TAG}

README.md

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# wait-for-pg
22

3-
## install
3+
Simple app that checks if PostgreSQL database is ready or not.
4+
5+
## Install and usage
6+
7+
### Option 1: use binary
48

59
```sh
6-
wget https://github.com/mxssl/wait-for-pg/releases/download/v0.0.1/wait-for-pg -O /usr/local/bin/wait-for-pg
10+
wget https://github.com/mxssl/wait-for-pg/releases/download/v0.0.2/wait-for-pg -O /usr/local/bin/wait-for-pg
711

812
chmod +x /usr/local/bin/wait-for-pg
9-
```
1013

11-
## usage
12-
13-
```sh
1414
wait-for-pg check \
1515
--host postgres.domain.com \
1616
--port 5432 \
@@ -21,5 +21,22 @@ wait-for-pg check \
2121
--sleep 2
2222
```
2323

24+
### Option 2: use docker container
25+
26+
```sh
27+
docker container \
28+
run \
29+
--rm \
30+
mxssl/wait-for-pg:0.0.2 \
31+
wait-for-pg check \
32+
--host postgres.domain.com \
33+
--port 5432 \
34+
--user pguser \
35+
--password pgpass \
36+
--dbname dbname \
37+
--retry 10 \
38+
--sleep 2
39+
```
40+
2441
- If PG is ready then app returns exit code 0
2542
- If PG isn't ready then app returns exit code 1

cmd/check.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ func check(c config) {
8484
log.Printf("Error: %s", err.Error())
8585
continue
8686
}
87-
} else if db == nil {
87+
}
88+
if db == nil {
8889
log.Printf("Error: %s", err.Error())
8990
continue
9091
}

go.mod

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module github.com/mxssl/wait-for-pg
2+
3+
go 1.13
4+
5+
require (
6+
github.com/bombsimon/wsl v1.2.8 // indirect
7+
github.com/go-critic/go-critic v0.4.0 // indirect
8+
github.com/gogo/protobuf v1.3.1 // indirect
9+
github.com/golangci/gocyclo v0.0.0-20180528144436-0a533e8fa43d // indirect
10+
github.com/golangci/golangci-lint v1.21.0 // indirect
11+
github.com/golangci/revgrep v0.0.0-20180812185044-276a5c0a1039 // indirect
12+
github.com/gostaticanalysis/analysisutil v0.0.3 // indirect
13+
github.com/konsorten/go-windows-terminal-sequences v1.0.2 // indirect
14+
github.com/lib/pq v1.2.0
15+
github.com/mattn/go-isatty v0.0.10 // indirect
16+
github.com/pelletier/go-toml v1.6.0 // indirect
17+
github.com/securego/gosec v0.0.0-20191119104125-df484bfa9e9f // indirect
18+
github.com/spf13/afero v1.2.2 // indirect
19+
github.com/spf13/cobra v0.0.5
20+
github.com/spf13/jwalterweatherman v1.1.0 // indirect
21+
github.com/spf13/viper v1.5.0 // indirect
22+
github.com/uudashr/gocognit v1.0.0 // indirect
23+
golang.org/x/sys v0.0.0-20191128015809-6d18c012aee9 // indirect
24+
golang.org/x/tools v0.0.0-20191127201027-ecd32218bd7f // indirect
25+
gopkg.in/yaml.v2 v2.2.7 // indirect
26+
mvdan.cc/unparam v0.0.0-20191111180625-960b1ec0f2c2 // indirect
27+
sourcegraph.com/sqs/pbtypes v1.0.0 // indirect
28+
)

go.sum

Lines changed: 375 additions & 0 deletions
Large diffs are not rendered by default.

vendor/github.com/inconshreveable/mousetrap/LICENSE

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/inconshreveable/mousetrap/README.md

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)