Skip to content

Commit

Permalink
Add Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
guptarohit committed Feb 27, 2022
1 parent b45cd40 commit c605530
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 18 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ jobs:
- uses: actions/setup-go@v2
with:
go-version: ~1.17
- uses: docker/setup-qemu-action@v1
- uses: docker/setup-buildx-action@v1
- uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
Expand Down
14 changes: 14 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,17 @@ release:
# If set to true, will not auto-publish the release.
# Default is false.
draft: true
dockers:
- image_templates:
- 'ghcr.io/guptarohit/asciigraph:{{ .Version }}'
dockerfile: Dockerfile
build_flag_templates:
- '--label=org.opencontainers.image.title={{ .ProjectName }}'
- '--label=org.opencontainers.image.name={{ .ProjectName }}'
- '--label=org.opencontainers.image.description=Go package to make lightweight line graphs ╭┈╯ in CLI'
- '--label=org.opencontainers.image.url=https://github.com/guptarohit/asciigraph'
- '--label=org.opencontainers.image.source=https://github.com/guptarohit/asciigraph'
- '--label=org.opencontainers.image.version={{ .Version }}'
- '--label=org.opencontainers.image.created={{ .Date }}'
- '--label=org.opencontainers.image.revision={{ .FullCommit }}'
- '--label=org.opencontainers.image.licenses=BSD-3-Clause'
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM golang:1.17-alpine AS builder
WORKDIR /app
COPY cmd ./cmd
COPY go.mod ./
COPY *.go ./
RUN GOOS=linux GOARCH=amd64 go build -ldflags="-w -s" -o /app/asciigraph ./cmd/asciigraph/main.go

FROM scratch
COPY --from=builder /app/asciigraph /asciigraph
ENTRYPOINT ["/asciigraph"]
76 changes: 58 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,37 +48,77 @@ Running this example would render the following graph:
## Command line interface

This package also brings a small utility for command line usage.
Assuming `$GOPATH/bin` is in your `$PATH`, simply `go get` it then
install CLI.
``` bash ✘ 0|125  16:19:23
> asciigraph --help
Usage of asciigraph:
asciigraph [options]
Options:
-b buffer
data points buffer when realtime graph enabled, default equal to `width`
-c caption
caption for the graph
-f fps
set fps to control how frequently graph to be rendered when realtime graph enabled (default 24)
-h height
height in text rows, 0 for auto-scaling
-o offset
offset in columns, for the label (default 3)
-p precision
precision of data point labels along the y-axis (default 2)
-r realtime
enables realtime graph for data stream
-w width
width in columns, 0 for auto-scaling
asciigraph expects data points from stdin. Invalid values are logged to stderr.
```

### CLI Installation
Assuming `$GOPATH/bin` is in your `$PATH`, simply `go get` it then
install CLI with following command:
``` bash
go install github.com/guptarohit/asciigraph/cmd/asciigraph
```

or pull Docker image:
``` bash
docker pull ghcr.io/guptarohit/asciigraph:latest
```

or download binaries from the [releases][] page.


### CLI Usage

Feed it data points via stdin:
``` bash
$ seq 1 72 | asciigraph -h 10 -c "plot data from stdin"
72.00 ┼
65.55 ┤ ╭────
59.09 ┤ ╭──────╯
52.64 ┤ ╭──────╯
46.18 ┤ ╭──────╯
39.73 ┤ ╭──────╯
33.27 ┤ ╭───────╯
26.82 ┤ ╭──────╯
20.36 ┤ ╭──────╯
13.91 ┤ ╭──────╯
7.45 ┤ ╭──────╯
1.00 ┼──╯
plot data from stdin
seq 1 72 | asciigraph -h 10 -c "plot data from stdin"
```

or use Docker image:
``` bash
seq 1 72 | docker run -i --rm ghcr.io/guptarohit/asciigraph -h 10 -c "plot data from stdin"
```

Output:

``` bash
72.00 ┤ ╭────
64.90 ┤ ╭──────╯
57.80 ┤ ╭──────╯
50.70 ┤ ╭──────╯
43.60 ┤ ╭──────╯
36.50 ┤ ╭───────╯
29.40 ┤ ╭──────╯
22.30 ┤ ╭──────╯
15.20 ┤ ╭──────╯
8.10 ┤ ╭──────╯
1.00 ┼──╯
plot data from stdin
```

Realtime graph for data points via stdin:
Example of real-time graph for data points stream via stdin:
``` bash
$ ping -i.2 google.com | grep -oP '(?<=time=).*(?=ms)' --line-buffered | asciigraph -r -h 10 -w 40 -c "realtime plot data (google ping in ms) from stdin"
ping -i.2 google.com | grep -oP '(?<=time=).*(?=ms)' --line-buffered | asciigraph -r -h 10 -w 40 -c "realtime plot data (google ping in ms) from stdin"
```
[![asciinema][]][7]

Expand Down

0 comments on commit c605530

Please sign in to comment.