diff options
| author | mo khan <mo@mokhan.ca> | 2025-07-08 13:11:59 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2025-07-21 15:20:39 -0600 |
| commit | 2ddcc34ca455973598f5693d64103deea41d8d79 (patch) | |
| tree | 0b3a42aa97bca93c15c67a679c903611e5ab60c1 /vendor/github.com/xlgmokha | |
| parent | 16c27cd885b9c0d1241dfead3120643f0e8c556c (diff) | |
chore: use minit to start processes from Procfile
Diffstat (limited to 'vendor/github.com/xlgmokha')
| -rw-r--r-- | vendor/github.com/xlgmokha/minit/LICENSE | 21 | ||||
| -rw-r--r-- | vendor/github.com/xlgmokha/minit/README.md | 71 | ||||
| -rw-r--r-- | vendor/github.com/xlgmokha/minit/main.go | 65 |
3 files changed, 157 insertions, 0 deletions
diff --git a/vendor/github.com/xlgmokha/minit/LICENSE b/vendor/github.com/xlgmokha/minit/LICENSE new file mode 100644 index 0000000..a9ea45c --- /dev/null +++ b/vendor/github.com/xlgmokha/minit/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 mo khan + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/vendor/github.com/xlgmokha/minit/README.md b/vendor/github.com/xlgmokha/minit/README.md new file mode 100644 index 0000000..6fcc536 --- /dev/null +++ b/vendor/github.com/xlgmokha/minit/README.md @@ -0,0 +1,71 @@ +# minit + +A minimal Procfile-based process supervisor for Docker containers. + +## Features + +- **Zero dependencies**: Works in scratch containers without shells or external tools +- **Procfile support**: Run multiple processes from a single configuration file +- **Signal forwarding**: Graceful shutdown with SIGTERM propagation +- **Process groups**: Uses `setpgid` for proper signal handling +- **Clean logs**: Direct stdout/stderr streaming without buffering + +## Usage + +```bash +# Run (reads Procfile from current directory) +./minit +``` + +## Procfile Format + +``` +web: ./server -port 8080 +worker: ./worker -queue tasks +redis: redis-server --port 6379 +scheduler: ./scheduler -interval 60s +``` + +## Installation + +```dockerfile +FROM golang:alpine AS minit-builder +RUN go install github.com/xlgmokha/minit@latest +``` + +## Docker Example +Combine minit with [dumb-init](https://github.com/Yelp/dumb-init) for proper PID 1 signal handling: + +```dockerfile +# syntax=docker/dockerfile:1 + +# Build stage for minit +FROM golang:alpine AS minit-builder +RUN go install github.com/xlgmokha/minit@latest + +# Build stage for dumb-init +FROM debian:bookworm-slim AS dumb-init-builder +RUN apt-get update && apt-get install -y wget && \ + wget -O /usr/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v1.2.5/dumb-init_1.2.5_x86_64 && \ + chmod +x /usr/bin/dumb-init + +# Final stage +FROM gcr.io/distroless/base-debian12:nonroot +COPY --from=minit-builder /go/bin/minit /bin/minit +COPY --from=dumb-init-builder /usr/bin/dumb-init /usr/bin/dumb-init +COPY Procfile /Procfile +COPY your-app /your-app + +ENTRYPOINT ["/usr/bin/dumb-init", "--"] +CMD ["/bin/minit"] +``` + +### Why use dumb-init? +- **PID 1 responsibilities**: Zombie reaping, proper signal handling +- **Graceful shutdown**: Ensures all processes terminate cleanly +- **Container compatibility**: Works with all container runtimes +- **Security**: Runs as non-root user with distroless base + +## License + +MIT diff --git a/vendor/github.com/xlgmokha/minit/main.go b/vendor/github.com/xlgmokha/minit/main.go new file mode 100644 index 0000000..f155bc4 --- /dev/null +++ b/vendor/github.com/xlgmokha/minit/main.go @@ -0,0 +1,65 @@ +package main + +import ( + "bufio" + "os" + "os/exec" + "os/signal" + "strings" + "sync" + "syscall" +) + +func main() { + file, _ := os.Open("Procfile") + defer file.Close() + + var cmds []*exec.Cmd + var wg sync.WaitGroup + + scanner := bufio.NewScanner(file) + for scanner.Scan() { + line := strings.TrimSpace(scanner.Text()) + if line == "" || strings.HasPrefix(line, "#") { + continue + } + + parts := strings.SplitN(line, ":", 2) + if len(parts) != 2 { + continue + } + + args := strings.Fields(strings.TrimSpace(parts[1])) + if len(args) == 0 { + continue + } + + cmd := exec.Command(args[0], args[1:]...) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true} + + cmds = append(cmds, cmd) + + wg.Add(1) + go func(c *exec.Cmd) { + defer wg.Done() + c.Start() + c.Wait() + }(cmd) + } + + sigChan := make(chan os.Signal, 1) + signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM) + + go func() { + <-sigChan + for _, cmd := range cmds { + if cmd.Process != nil { + syscall.Kill(-cmd.Process.Pid, syscall.SIGTERM) + } + } + }() + + wg.Wait() +} |
