Skip to content

Commit 2b9e9c8

Browse files
committed
Initial commit
0 parents  commit 2b9e9c8

2,281 files changed

Lines changed: 661689 additions & 0 deletions

File tree

Some content is hidden

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

.github/workflows/ci.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: ci
2+
on:
3+
push:
4+
branches: [main]
5+
pull_request:
6+
branches: [main]
7+
permissions:
8+
contents: read
9+
jobs:
10+
check:
11+
runs-on: ubuntu-latest
12+
env:
13+
GOFLAGS: -mod=vendor
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
17+
- name: Set up Go
18+
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
19+
with:
20+
go-version-file: go.mod
21+
cache: true
22+
- name: Check formatting
23+
run: |
24+
unformatted=$(gofmt -l $(find . -name '*.go' -not -path './vendor/*'))
25+
if [ -n "$unformatted" ]; then
26+
echo "The following files are not gofmt'd:"
27+
echo "$unformatted"
28+
exit 1
29+
fi
30+
- name: Vet
31+
run: go vet ./...
32+
- name: Install staticcheck
33+
env:
34+
GOFLAGS: ""
35+
run: go install honnef.co/go/tools/cmd/staticcheck@latest
36+
- name: Staticcheck
37+
run: staticcheck ./...
38+
- name: Test
39+
run: go test -race -cover -short ./...
40+
- name: Build
41+
run: go build ./...

.github/workflows/release.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: release
2+
on:
3+
push:
4+
tags:
5+
- "v*"
6+
permissions:
7+
contents: write
8+
packages: write
9+
jobs:
10+
goreleaser:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
15+
with:
16+
fetch-depth: 0
17+
- name: Set up Go
18+
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
19+
with:
20+
go-version-file: go.mod
21+
cache: true
22+
- name: Log in to GHCR
23+
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0
24+
with:
25+
registry: ghcr.io
26+
username: ${{ github.actor }}
27+
password: ${{ secrets.GITHUB_TOKEN }}
28+
- name: Run GoReleaser
29+
uses: goreleaser/goreleaser-action@e24998b8b67b290c2fa8b7c14fcfa7de2c5c9b8c # v7.1.0
30+
with:
31+
distribution: goreleaser
32+
version: "~> v2"
33+
args: release --clean
34+
env:
35+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# If you prefer the allow list template instead of the deny list, see community template:
2+
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
3+
#
4+
# Binaries for programs and plugins
5+
*.exe
6+
*.exe~
7+
*.dll
8+
*.so
9+
*.dylib
10+
11+
# Test binary, built with `go test -c`
12+
*.test
13+
14+
/bin/
15+
16+
# Code coverage profiles and other test artifacts
17+
*.out
18+
coverage.*
19+
*.coverprofile
20+
profile.cov
21+
22+
# Dependency directories (remove the comment below to include it)
23+
# vendor/
24+
25+
# Go workspace file
26+
go.work
27+
go.work.sum
28+
29+
# env file
30+
.env
31+
32+
# Editor/IDE
33+
.idea/
34+
.vscode/
35+

.goreleaser.yaml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
version: 2
2+
3+
project_name: service-wait
4+
5+
before:
6+
hooks:
7+
- go mod tidy
8+
9+
builds:
10+
- id: service-wait
11+
main: ./cmd/service-wait
12+
binary: service-wait
13+
env:
14+
- CGO_ENABLED=0
15+
flags:
16+
- -trimpath
17+
ldflags:
18+
- -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}}
19+
goos:
20+
- linux
21+
- darwin
22+
goarch:
23+
- amd64
24+
- arm64
25+
26+
archives:
27+
- id: service-wait
28+
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
29+
formats: [tar.gz]
30+
files:
31+
- README.md
32+
- LICENSE*
33+
34+
checksum:
35+
name_template: "checksums.txt"
36+
37+
kos:
38+
- id: service-wait
39+
build: service-wait
40+
base_image: docker:cli
41+
repositories:
42+
- ghcr.io/ororatech/service-wait
43+
tags:
44+
- "{{.Version}}"
45+
- "v{{.Version}}"
46+
- "{{if not .Prerelease}}latest{{end}}"
47+
bare: true
48+
preserve_import_paths: false
49+
platforms:
50+
- linux/amd64
51+
- linux/arm64
52+
sbom: spdx
53+
creation_time: "{{.CommitTimestamp}}"
54+
ko_data_creation_time: "{{.CommitTimestamp}}"
55+
56+
snapshot:
57+
version_template: "{{ incpatch .Version }}-next"
58+
59+
changelog:
60+
sort: asc
61+
use: github
62+
filters:
63+
exclude:
64+
- "^docs:"
65+
- "^chore:"
66+
- "^test:"
67+
- "Merge pull request"
68+
- "Merge branch"
69+
groups:
70+
- title: Features
71+
regexp: '^.*?feat(\([[:word:]]+\))??!?:.+$'
72+
order: 0
73+
- title: Bug fixes
74+
regexp: '^.*?fix(\([[:word:]]+\))??!?:.+$'
75+
order: 1
76+
- title: Other
77+
order: 999
78+
79+
release:
80+
draft: false
81+
prerelease: auto

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2026 Maximilian Fischer
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
BINARY := service-wait
2+
PKG := github.com/ororatech/service-wait/cmd/service-wait
3+
BIN := bin/$(BINARY)
4+
PREFIX ?= $(HOME)/.local
5+
6+
GO ?= go
7+
GOFLAGS ?=
8+
VERSION ?= $(shell git describe --tags --always --dirty 2>/dev/null || printf dev)
9+
COMMIT ?= $(shell git rev-parse --short HEAD 2>/dev/null || printf none)
10+
DATE ?= $(shell date -u +%Y-%m-%dT%H:%M:%SZ 2>/dev/null || printf unknown)
11+
LDFLAGS ?= -s -w -X main.version=$(VERSION) -X main.commit=$(COMMIT) -X main.date=$(DATE)
12+
13+
.PHONY: all build install uninstall run fmt vet tidy test clean help
14+
15+
all: build
16+
17+
build:
18+
@mkdir -p bin
19+
$(GO) build $(GOFLAGS) -ldflags "$(LDFLAGS)" -o $(BIN) $(PKG)
20+
21+
run: build
22+
./$(BIN) $(ARGS)
23+
24+
install: build
25+
@mkdir -p $(PREFIX)/bin
26+
install -m 0755 $(BIN) $(PREFIX)/bin/$(BINARY)
27+
28+
uninstall:
29+
rm -f $(PREFIX)/bin/$(BINARY)
30+
31+
test:
32+
$(GO) test -v -timeout 120s ./...
33+
34+
fmt:
35+
$(GO) fmt ./...
36+
37+
vet:
38+
$(GO) vet ./...
39+
40+
staticcheck:
41+
$(GO) run honnef.co/go/tools/cmd/staticcheck@latest ./...
42+
43+
tidy:
44+
$(GO) mod tidy

README.md

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# Service Wait
2+
3+
A lightweight CLI tool that waits for HTTP, MongoDB, or PostgreSQL endpoints to become available before proceeding. Useful as an init container or entrypoint wrapper in containerised deployments.
4+
5+
## Features
6+
7+
- **HTTP** – probe one or multiple HTTP endpoints
8+
- **PostgreSQL** – wait for a Postgres database to accept connections
9+
- **MongoDB** – wait for a Mongo instance to respond to pings
10+
- Configurable timeout and polling interval
11+
- Configuration via CLI flags or environment variables
12+
13+
## Install
14+
15+
### Prerequisites
16+
17+
- [mise](https://mise.jdx.dev)
18+
19+
```bash
20+
mise trust
21+
mise install
22+
```
23+
24+
### Build from source
25+
26+
```bash
27+
make build # outputs bin/service-wait
28+
make install # installs to ~/.local/bin
29+
```
30+
31+
### Docker
32+
33+
```bash
34+
docker build -t service-wait .
35+
```
36+
37+
### Use in a Docker image (multi-stage)
38+
39+
Copy the binary into your own image using a multi-stage build:
40+
41+
```dockerfile
42+
FROM ghcr.io/ororatech/service-wait:v0.0.1@sha256:f76661dd68c5bfef49712400d8cd64d46e4f8ab932f644d628b4cee0294b1e28 AS service-wait
43+
44+
FROM alpine:3
45+
46+
COPY --from=service-wait /ko-app/service-wait /usr/local/bin/service-wait
47+
48+
ENTRYPOINT ["service-wait"]
49+
```
50+
51+
## Usage
52+
53+
```bash
54+
service-wait [flags]
55+
```
56+
57+
### Flags
58+
59+
| Flag | Short | EnvVar | Default | Description |
60+
|------|-------|--------|---------|-------------|
61+
| `--url` | `-u` | `SERVICE_WAIT_URL` | | HTTP endpoint to probe |
62+
| `--urls` | `-U` | `SERVICE_WAIT_URLS` | | Multiple HTTP endpoints (comma-separated) |
63+
| `--timeout` | `-t` | `SERVICE_WAIT_TIMEOUT` | `30s` | Max time to wait |
64+
| `--interval` | `-i` | `SERVICE_WAIT_INTERVAL` | `30s` | Polling interval |
65+
| `--psql-host` | `-H` | `SERVICE_WAIT_PSQL_HOST` / `PGHOST` | | PostgreSQL host |
66+
| `--psql-port` | `-p` | `SERVICE_WAIT_PSQL_PORT` / `PGPORT` | `5432` | PostgreSQL port |
67+
| `--psql-user` | | `SERVICE_WAIT_PSQL_USER` / `PGUSER` | | PostgreSQL user |
68+
| `--psql-password` | `-P` | `SERVICE_WAIT_PSQL_PASSWORD` / `PGPASSWORD` | | PostgreSQL password |
69+
| `--psql-database` | `-d` | `SERVICE_WAIT_PSQL_DATABASE` / `PGDATABASE` | | PostgreSQL database |
70+
| `--psql-sslmode` | `-s` | `SERVICE_WAIT_PSQL_SSLMODE` / `PGSSLMODE` | `disable` | PostgreSQL SSL mode |
71+
| `--psql-dsn` | | `SERVICE_WAIT_PSQL_DSN` | | PostgreSQL DSN (overrides individual flags) |
72+
| `--mongo-host` | | `SERVICE_WAIT_MONGO_HOST` | | MongoDB host |
73+
| `--mongo-port` | | `SERVICE_WAIT_MONGO_PORT` | `27017` | MongoDB port |
74+
| `--mongo-user` | | `SERVICE_WAIT_MONGO_USER` | | MongoDB user |
75+
| `--mongo-password` | | `SERVICE_WAIT_MONGO_PASSWORD` | | MongoDB password |
76+
| `--mongo-database` | | `SERVICE_WAIT_MONGO_DATABASE` | | MongoDB database |
77+
| `--mongo-auth-source` | | `SERVICE_WAIT_MONGO_AUTH_SOURCE` | | MongoDB auth source |
78+
| `--verbose` | `-V` | `SERVICE_WAIT_DEBUG` | `false` | Enable debug logging |
79+
80+
### Examples
81+
82+
Wait for an HTTP endpoint:
83+
84+
```bash
85+
service-wait --url http://localhost:8080/health --timeout 60s --interval 2s
86+
```
87+
88+
Wait for PostgreSQL:
89+
90+
```bash
91+
service-wait --psql-host localhost --psql-user postgres --psql-password secret --psql-database mydb
92+
```
93+
94+
Wait for MongoDB:
95+
96+
```bash
97+
service-wait --mongo-host localhost --mongo-user admin --mongo-password secret --mongo-database mydb
98+
```
99+
100+
Using environment variables:
101+
102+
```bash
103+
export SERVICE_WAIT_URL=http://localhost:8080/health
104+
export SERVICE_WAIT_TIMEOUT=60s
105+
service-wait
106+
```
107+
108+
## Development
109+
110+
```bash
111+
make build # compile
112+
make test # run tests (requires Docker for testcontainers)
113+
make fmt # format code
114+
make vet # run go vet
115+
make tidy # tidy go modules
116+
```
117+
118+
## License
119+
120+
[MIT](LICENSE)

0 commit comments

Comments
 (0)