diff --git a/.gitignore b/.gitignore index 2ab4eb2..200a727 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /s6-cli /coverage.out +/s6-cli* diff --git a/Makefile b/Makefile index 4a7f536..77c921f 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,4 @@ +BINARY_NAME=s6-cli S6_PATH := ./examples/s6-overlay/s6-rc.d ARGS := -p $(S6_PATH) @@ -9,9 +10,6 @@ help: @echo 'Usage:' @sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /' - - - # ==================================================================================== # # QUALITY CONTROL # ==================================================================================== # @@ -31,10 +29,6 @@ audit: go run golang.org/x/vuln/cmd/govulncheck@latest ./... go test -race -buildvcs -vet=off ./... -coverage: - @go test -coverprofile=coverage.out -v ./... - @go tool cover -html=coverage.out - # ==================================================================================== # # DEVELOPMENT # ==================================================================================== # @@ -43,11 +37,22 @@ coverage: no-dirty: git diff --exit-code +.PHONY: dep +dep: + @go mod download + ## build: build binary file .PHONY: build build: - @go build -o s6-cli -v ./cmd/s6cli + @GOARCH=amd64 GOOS=linux go build -o ${BINARY_NAME} -v ./cmd/s6cli + +## clean: clean binary file +.PHONY: clean +clean: + @go clean + @rm -f ${BINARY_NAME} +## run: run binary file with good args .PHONY: run run: @go run ./cmd/s6cli $(ARGS) @@ -57,6 +62,12 @@ run: test: @go test -v ./... +## test-coverage: run all tests with coverage +.PHONY: test-coverage +test-coverage: + @go test -coverprofile=coverage.out -v ./... + @go tool cover -html=coverage.out + ## nix: build binary file with nix .PHONY: nix nix: @@ -66,7 +77,7 @@ nix: # RUN COMMANDS OF CLI WITH DEFAULT ARGS # ==================================================================================== # -## lint: lint s6-overlay folders and files +## lint: lint s6-overlay directories and files .PHONY: lint lint: @go run ./cmd/s6cli $(ARGS) lint diff --git a/README.md b/README.md index cc4a039..f53ec63 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,119 @@ -# s6-cli: A cli for s6-overlay -This cli tool can be used to help you setup your projects s6-overlay files and directories +# s6-cli: CLI for s6-overlay +This cli tool can be used to help you setup your projects s6-overlay files and directories. It can also be used to create, remove and lint services. + +## s6-overlay +> s6-overlay is an easy-to-install (just extract a tarball or two!) set of scripts and utilities allowing you to use existing Docker images while using s6 as a pid 1 for your container and process supervisor for your services. +To know more about s6-overlay visit [github.com/just-containers/s6-overlay](https://github.com/just-containers/s6-overlay). + + +## Setup + +```bash +git clone git@github.com:dazz/s6-cli.git +cd s6-cli +make help +``` + +There is a Makefile that you can use to execute helpful commands. Following is a small list for some more important targets. +Run `make` or `make help` to see all possible targets. + +## Build + There are a few options here how you can install the executable on the target system. + +### Go +Builds the executable and places it in the current directory +```bash +make build +``` + +### Nix shell +If you have nix-shell you can run the following command to get a shell with the cli installed +```bash +make nix +``` + +### Docker +Creates a docker image with the cli installed +```bash +make docker +``` + +### In Dockerfile +If you want to use the cli in a Dockerfile you can copy it from the docker image +```dockerfile +COPY --from=hakindazz/s6-cli:latest /app/s6-cli /usr/local/bin/s6-cli +``` + +## Usage + +There is a help command that you can use to get more info about the commands in the cli. Run it with +```bash +./s6-cli help +``` +### The option `--rootPath {path}, -p {path}` +All commands need the `rootPath` to be specified. It must point to the directory where services will be defined. +Default is set to `/etc/s6-overlay/s6-rc.d` + +### Create +There are three types of services that can be created: Oneshot, Longrun and Background. +Read more about them [here](https://skarnet.org/software/s6-rc/s6-rc-compile.html) + +```bash +./s6-cli --rootPath {path} create {o|l|b} {service} +``` + +### Remove +If the service is not needed anymore it can be removed with the following command. + +```bash +./s6-cli remove {service} +``` + +### Lint + +```bash +./s6-cli lint +``` + + + +### Mermaid +This command will generate a mermaid graph of the services. + +```bash +./s6-cli mermaid > mermaid.md +``` + +Or pipe it directly to a markdown file +```bash +./s6-cli mermaid > mermaid.md +``` + +The output will look something like this: +```bash +```mermaid +graph TD; + user --> prepare-directory + user --> nginx + nginx --> php-fpm + php-fpm --> create-directories +``` + +which will be rendered to this: + +```mermaid +graph TD; + user --> prepare-directory + user --> nginx + nginx --> php-fpm + php-fpm --> create-directories +``` + ## todo -* [ ] write tests with https://github.com/stretchr/testify -* [ ] find pattern for testcase names -* [ ] add `s6-cli update` command -* [ ] add `s6-cli init` command -* [ ] style output with color https://github.com/charmbracelet/glamour \ No newline at end of file +* create dependencies between services +* add `s6-cli update` command +* add `s6-cli init` command +* add `s6-cli ci` command +* style output with color https://github.com/charmbracelet/glamour +* tui with https://github.com/charmbracelet/bubbletea \ No newline at end of file diff --git a/cmd/s6cli/main.go b/cmd/s6cli/main.go index ca5310c..215755f 100644 --- a/cmd/s6cli/main.go +++ b/cmd/s6cli/main.go @@ -19,7 +19,7 @@ func main() { rootPath := "/etc/s6-overlay/s6-rc.d" app := &cli.App{ Name: "s6-cli", - Version: "0.0.1", + Version: "0.0.2", Compiled: time.Now(), Authors: []*cli.Author{ {