Skip to content

Commit

Permalink
Add Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
Clivern committed Mar 6, 2021
1 parent 3b94d92 commit 6697951
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 19 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
- Review existing issues and provide feedback or react to them.

- With pull requests:
- Open your pull request against `master`
- Open your pull request against `main`
- Your pull request should have no more than two commits, if not you should squash them.
- It should pass all tests in the available continuous integrations systems such as TravisCI.
- You should add/modify tests to cover your proposed code changes.
Expand Down
26 changes: 26 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM golang:1.16.0

ARG PENGUIN_VERSION=0.0.2

ENV GO111MODULE=on

RUN mkdir -p /app/configs
RUN mkdir -p /app/var/logs
RUN apt-get update

WORKDIR /app

RUN curl -sL https://github.com/Clivern/Penguin/releases/download/v${PENGUIN_VERSION}/penguin_${PENGUIN_VERSION}_Linux_x86_64.tar.gz | tar xz
RUN rm LICENSE
RUN rm README.md

COPY ./config.dist.yml /app/configs/

EXPOSE 8000

VOLUME /app/configs
VOLUME /app/var

RUN ./penguin version

CMD ["./penguin", "run", "-c", "/app/configs/config.dist.yml"]
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<p align="center">
<a href="https://github.com/Clivern/Penguin/actions"><img src="https://github.com/Clivern/Penguin/workflows/Build/badge.svg"></a>
<a href="https://github.com/Clivern/Penguin/actions"><img src="https://github.com/Clivern/Penguin/workflows/Release/badge.svg"></a>
<a href="https://github.com/Clivern/Penguin/releases"><img src="https://img.shields.io/badge/Version-0.0.1-red.svg"></a>
<a href="https://goreportcard.com/report/github.com/Clivern/Penguin"><img src="https://goreportcard.com/badge/github.com/Clivern/Penguin?v=0.0.1"></a>
<a href="https://github.com/Clivern/Penguin/releases"><img src="https://img.shields.io/badge/Version-0.0.2-red.svg"></a>
<a href="https://goreportcard.com/report/github.com/Clivern/Penguin"><img src="https://goreportcard.com/badge/github.com/Clivern/Penguin?v=0.0.2"></a>
<a href="https://github.com/Clivern/Penguin/blob/main/LICENSE"><img src="https://img.shields.io/badge/LICENSE-MIT-orange.svg"></a>
</p>
</p>
Expand All @@ -32,7 +32,7 @@ inputs:
http:
enabled: on
mode: prod
port: 8080
port: 8000
tls:
status: off
pemPath: cert/server.pem
Expand All @@ -42,15 +42,15 @@ inputs:

# Log files to watch
log:
enabled: on
enabled: off
paths:
- /app/logs/metrics_1.log
- /app/logs/metrics_2.log

# Metrics Cache Driver
cache:
type: memory
enabled: on
enabled: off

drivers:
memory:
Expand Down Expand Up @@ -79,7 +79,6 @@ log:
output: stdout
# Format can be json
format: json

```

Run Penguin
Expand All @@ -101,10 +100,10 @@ Send metrics to penguin HTTP endpoint
```bash
curl -X POST \
-d '{"type":"counter","name":"penguin_orders","help":"the amount of orders.","method":"inc","value":1,"labels":{"type":"trousers"}}' \
http://127.0.0.1:8080
http://127.0.0.1:8000
```
Configure prometheus to scrape this URL `http://127.0.0.1:8080/metrics`
Configure prometheus to scrape this URL `http://127.0.0.1:8000/metrics`
## Versioning
Expand Down
8 changes: 4 additions & 4 deletions cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ var runCmd = &cobra.Command{

go controller.Daemon(messages)

// If http input not enabled
if !viper.GetBool("inputs.http.enabled") {
// If http input not enabled & log watcher enabled
if !viper.GetBool("inputs.http.enabled") && viper.GetBool("inputs.log.enabled") {
controller.Watcher(messages)
return
} else if viper.GetBool("inputs.log.enabled") {
go controller.Watcher(messages)
}

go controller.Watcher(messages)

r := gin.Default()

r.Use(middleware.Correlation())
Expand Down
8 changes: 4 additions & 4 deletions config.dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ inputs:
http:
enabled: on
mode: prod
port: 8080
port: 8000
tls:
status: off
pemPath: cert/server.pem
Expand All @@ -14,15 +14,15 @@ inputs:

# Log files to watch
log:
enabled: on
enabled: off
paths:
- /app/logs/metrics_1.log
- /app/logs/metrics_2.log

# Metrics Cache Driver
cache:
type: memory
enabled: on
enabled: off

drivers:
memory:
Expand All @@ -47,7 +47,7 @@ output:
log:
# Log level, it can be debug, info, warn, error, panic, fatal
level: info
# output can be stdout or abs path to log file /var/logs/beetle.log
# output can be stdout or abs path to log file /var/logs/penguin.log
output: stdout
# Format can be json
format: json
11 changes: 9 additions & 2 deletions core/controller/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package controller

import (
"fmt"
"sync"

"github.com/clivern/penguin/core/model"

Expand All @@ -17,14 +18,16 @@ import (
// Watcher function
func Watcher(messages chan<- string) {
paths := viper.GetStringSlice("inputs.log.paths")
var wg sync.WaitGroup

for _, path := range paths {

log.WithFields(log.Fields{
"log_file": path,
}).Info("Watch log file")
wg.Add(1)

go func(file string, channel chan<- string) {
go func(swg *sync.WaitGroup, file string, channel chan<- string) {
t, err := tail.TailFile(
file,
tail.Config{Follow: true, ReOpen: true},
Expand All @@ -48,6 +51,10 @@ func Watcher(messages chan<- string) {

channel <- message
}
}(path, messages)

defer swg.Done()
}(&wg, path, messages)
}

wg.Wait()
}
53 changes: 53 additions & 0 deletions deployment/docker-compose/configs/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Metrics Input
inputs:
# HTTP endpoint for metrics collection
http:
enabled: on
mode: prod
port: 8080
tls:
status: off
pemPath: cert/server.pem
keyPath: cert/server.key
path: /
api_key: ""

# Log files to watch
log:
enabled: off
paths:
- /app/logs/metrics_1.log
- /app/logs/metrics_2.log

# Metrics Cache Driver
cache:
type: memory
enabled: on

drivers:
memory:
buffer_size: 10

# Metrics Output
output:
# Output metrics to console
console:
enabled: on

# Expose to prometheus
prometheus:
enabled: on
endpoint: /metrics

# TODO: Support Graphite
graphite:
enabled: off

# Log configs
log:
# Log level, it can be debug, info, warn, error, panic, fatal
level: info
# output can be stdout or abs path to log file /var/logs/beetle.log
output: stdout
# Format can be json
format: json
11 changes: 11 additions & 0 deletions deployment/docker-compose/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: '3'

services:
penguin:
image: 'clivern/penguin:release-v0.0.2'
ports:
- "8000:8000"
command: '/app/penguin run -c /app/configs/config.yml'
volumes:
- './configs/:/app/configs'
restart: unless-stopped

0 comments on commit 6697951

Please sign in to comment.