Skip to content

Commit 93fdcad

Browse files
committed
update repo and deps
1 parent 6592c4e commit 93fdcad

25 files changed

+303
-389
lines changed

.dockerignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
*.log
2+
.dockerignore
23
.git
34
.gitignore
45
.idea
56
LICENSE
6-
README*
7+
README.md
8+
Makefile
79
tinysyslog-bin

.github/workflows/lint.yaml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: golangci-lint
2+
on:
3+
push:
4+
branches:
5+
- master
6+
- main
7+
pull_request:
8+
9+
permissions:
10+
# Required: allow read access to the content for analysis.
11+
contents: read
12+
# Optional: allow read access to pull request. Use with `only-new-issues` option.
13+
pull-requests: read
14+
# Optional: Allow write access to checks to allow the action to annotate code in the PR.
15+
checks: write
16+
17+
jobs:
18+
unit:
19+
name: lint
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Fetch Repository
23+
uses: actions/checkout@v4
24+
25+
- name: Install Go
26+
uses: actions/setup-go@v5
27+
with:
28+
go-version: '1.23.x'
29+
30+
- name: golangci-lint
31+
uses: golangci/golangci-lint-action@v7
32+
with:
33+
version: v2.0.2

.github/workflows/pre-commit.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: pre-commit
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- main
8+
pull_request:
9+
10+
jobs:
11+
unit:
12+
name: pre-commit
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Fetch Repository
16+
uses: actions/checkout@v4
17+
18+
- name: Install Python
19+
uses: actions/setup-python@v5
20+
with:
21+
python-version: '3.13'
22+
23+
- name: Install pre-commit
24+
uses: pre-commit/action@v3.0.1

.github/workflows/test.yaml

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,35 @@
1-
name: Test and coverage
1+
name: test
22

3-
on: [push, pull_request]
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- main
8+
pull_request:
49

510
jobs:
6-
build:
7-
runs-on: ubuntu-latest
11+
unit:
12+
strategy:
13+
matrix:
14+
go-version: [ '1.23.x', '1.24.x' ]
15+
os: [ macos-latest, ubuntu-latest]
16+
runs-on: ${{ matrix.os }}
817
steps:
9-
- uses: actions/checkout@v4
10-
with:
11-
fetch-depth: 2
12-
- uses: actions/setup-go@v5
18+
- name: Fetch Repository
19+
uses: actions/checkout@v4
20+
21+
- name: Install Go
22+
uses: actions/setup-go@v5
1323
with:
14-
go-version: '1.22'
15-
- name: Run coverage
16-
run: go test -race -coverprofile=coverage.out -covermode=atomic ./...
17-
- name: Upload coverage to Codecov
18-
uses: codecov/codecov-action@v4
24+
go-version: ${{ matrix.go-version }}
25+
26+
- name: Test
27+
run: go run gotest.tools/gotestsum@latest -f testname -- ./... -race -count=1 -coverprofile=coverage.txt -covermode=atomic -shuffle=on
28+
29+
- name: Upload coverage reports to Codecov
30+
if: ${{ matrix.os == 'ubuntu-latest' && matrix.go-version == '1.23.x' }}
31+
uses: codecov/codecov-action@v5.4.0
1932
with:
2033
token: ${{ secrets.CODECOV_TOKEN }}
34+
file: ./coverage.txt
35+
flags: unittests

.gitignore

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,27 @@
1-
# Compiled Object files, Static and Dynamic libs (Shared Objects)
2-
*.o
3-
*.a
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
48
*.so
9+
*.dylib
510

6-
# Folders
7-
_obj
8-
_test
9-
10-
# Architecture specific extensions/prefixes
11-
*.[568vq]
12-
[568vq].out
11+
# Test binary, built with `go test -c`
12+
*.test
1313

14-
*.cgo1.go
15-
*.cgo2.c
16-
_cgo_defun.c
17-
_cgo_gotypes.go
18-
_cgo_export.*
14+
# Output of the go coverage tool, specifically when used with LiteIDE
15+
*.out
1916

20-
_testmain.go
17+
# Dependency directories (remove the comment below to include it)
18+
# vendor/
2119

22-
*.exe
23-
*.test
24-
*.prof
20+
# Go workspace file
21+
go.work
2522

26-
*.out
27-
*.log
23+
# GoLand
2824
.idea
25+
26+
# binary
2927
tinysyslog-bin

.golangci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
version: "2"
2+
formatters:
3+
enable:
4+
- gofumpt

.pre-commit-config.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v5.0.0
4+
hooks:
5+
- id: check-case-conflict
6+
- id: check-json
7+
- id: check-merge-conflict
8+
- id: check-toml
9+
- id: check-yaml
10+
args: ["--allow-multiple-documents"]
11+
- id: end-of-file-fixer
12+
- id: fix-byte-order-marker
13+
- id: mixed-line-ending
14+
args: ["--fix=lf"]
15+
- id: pretty-format-json
16+
args: ["--autofix", "--indent=2", "--no-sort-keys"]
17+
files: \.json$
18+
- id: trailing-whitespace

Dockerfile

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
1-
FROM golang:1.22.2-alpine3.19 as builder
2-
MAINTAINER Alexandre Ferland <me@alexferl.com>
1+
FROM golang:1.24.2-alpine as builder
2+
LABEL maintainer="Alexandre Ferland <me@alexferl.com>"
33

44
WORKDIR /build
55

66
RUN apk add --no-cache git
7+
RUN adduser -D -u 1337 tinysyslog
78

8-
COPY go.mod .
9-
COPY go.sum .
10-
9+
COPY go.mod go.sum ./
1110
RUN go mod download
1211

1312
COPY . .
1413

1514
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ./cmd/tinysyslogd
1615

1716
FROM scratch
17+
COPY --from=builder /etc/passwd /etc/passwd
1818
COPY --from=builder /build/tinysyslogd /tinysyslogd
1919

20-
EXPOSE 5140 5140/udp
20+
USER tinysyslog
21+
22+
EXPOSE 5140/tcp 5140/udp
2123

2224
ENTRYPOINT ["/tinysyslogd", "--bind-addr", "0.0.0.0:5140"]

Makefile

Lines changed: 43 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,38 @@
1-
.PHONY: dev run test cover cover-html fmt pre-commit docker-build docker-run
1+
.PHONY: dev audit cover cover-html fmt lint pre-commit run test tidy update-deps docker-build docker-run
22

33
.DEFAULT: help
44
help:
55
@echo "make dev"
66
@echo " setup development environment"
7-
@echo "make run"
8-
@echo " run app"
9-
@echo "make test"
10-
@echo " run go test"
7+
@echo "make audit"
8+
@echo " conduct quality checks"
119
@echo "make cover"
12-
@echo " run go test with -cover"
10+
@echo " generate coverage report"
1311
@echo "make cover-html"
14-
@echo " run go test with -cover and show HTML"
15-
@echo "make tidy"
16-
@echo " run go mod tidy"
12+
@echo " generate coverage HTML report"
1713
@echo "make fmt"
18-
@echo " run gofumpt"
14+
@echo " fix code format issues"
15+
@echo "make lint"
16+
@echo " run lint checks"
1917
@echo "make pre-commit"
2018
@echo " run pre-commit hooks"
19+
@echo "make run"
20+
@echo " run application"
21+
@echo "make test"
22+
@echo " execute all tests"
23+
@echo "make tidy"
24+
@echo " clean and tidy dependencies"
25+
@echo "make update-deps"
26+
@echo " update dependencies"
2127
@echo "make docker-build"
2228
@echo " build docker image"
2329
@echo "make docker-run"
2430
@echo " run docker image"
2531

26-
check-gofumpt:
27-
ifeq (, $(shell which gofumpt))
28-
$(error "gofumpt not in $(PATH), gofumpt (https://pkg.go.dev/mvdan.cc/gofumpt) is required")
29-
endif
32+
GOTESTSUM := go run gotest.tools/gotestsum@latest -f testname -- ./... -race -count=1
33+
TESTFLAGS := -shuffle=on
34+
COVERFLAGS := -covermode=atomic
35+
GOLANGCI_LINT := go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.0.2
3036

3137
check-pre-commit:
3238
ifeq (, $(shell which pre-commit))
@@ -36,33 +42,40 @@ endif
3642
dev: check-pre-commit
3743
pre-commit install
3844

39-
run:
40-
go build -o tinysyslog-bin ./cmd/tinysyslogd && ./tinysyslog-bin
41-
42-
build:
43-
go build -o tinysyslog-bin ./cmd/tinysyslogd
44-
45-
test:
46-
go test -v ./...
45+
audit:
46+
go mod verify
47+
go run golang.org/x/vuln/cmd/govulncheck@latest ./...
4748

4849
cover:
49-
go test -cover -v ./...
50+
$(GOTESTSUM) $(TESTFLAGS) $(COVERFLAGS)
5051

5152
cover-html:
52-
go test -v -coverprofile=coverage.out ./...
53+
$(GOTESTSUM) $(TESTFLAGS) $(COVERFLAGS) -coverprofile=coverage.out
5354
go tool cover -html=coverage.out
5455

55-
tidy:
56-
go mod tidy
56+
fmt:
57+
$(GOLANGCI_LINT) fmt
5758

58-
fmt: check-gofumpt
59-
gofumpt -l -w .
59+
lint:
60+
$(GOLANGCI_LINT) run
6061

6162
pre-commit: check-pre-commit
62-
pre-commit
63+
pre-commit run --all-files
64+
65+
run:
66+
go build -o tinysyslog-bin ./cmd/tinysyslogd && ./tinysyslog-bin
67+
68+
test:
69+
$(GOTESTSUM) $(TESTFLAGS)
70+
71+
tidy:
72+
go mod tidy -v
73+
74+
update-deps: tidy
75+
go get -u ./...
6376

6477
docker-build:
6578
docker build -t tinysyslog .
6679

6780
docker-run:
68-
docker run -p 5140:5140/udp --rm tinysyslog
81+
docker run --name tinysyslog --rm -p 5140:5140/udp tinysyslog

README.md

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# tinysyslog [![Go Report Card](https://goreportcard.com/badge/github.com/alexferl/tinysyslog)](https://goreportcard.com/report/github.com/alexferl/tinysyslog) [![codecov](https://codecov.io/gh/alexferl/tinysyslog/branch/master/graph/badge.svg)](https://codecov.io/gh/alexferl/tinysyslog)
22

3-
A tiny and simple syslog server with log rotation. tinysyslog was born out of the need for a tiny, easy to set up and
4-
use syslog server that simply writes every incoming log (in [RFC 5424](https://datatracker.ietf.org/doc/html/rfc5424) format **only**) to a file that is automatically rotated,
5-
to stdout or stderr (mostly for Docker) and or to Elasticsearch.
3+
A tiny and simple syslog server with log rotation. tinysyslog was born out of the need for a tiny, easy to set up and
4+
use syslog server that simply writes every incoming log (in [RFC 5424](https://datatracker.ietf.org/doc/html/rfc5424) format **only**) to a file that is automatically rotated,
5+
to stdout or stderr (mostly for Docker).
66
tinysyslog is based on [go-syslog](https://github.com/mcuadros/go-syslog) and [lumberjack](https://github.com/natefinch/lumberjack).
77

88
## Quickstart
@@ -32,7 +32,7 @@ Download the image:
3232
```shell
3333
docker pull admiralobvious/tinysyslog
3434
```
35-
35+
3636
Start the container:
3737
```shell
3838
docker run --rm --name tinysyslog -p 5140:5140/udp -d admiralobvious/tinysyslog
@@ -85,27 +85,20 @@ You can now send logs from your app(s) to `tinysyslog:5140`.
8585
## Configuration
8686
```
8787
Usage of ./tinysyslogd:
88-
--app-name string The name of the application. (default "tinysyslog")
89-
--bind-addr string IP and port to listen on. (default "127.0.0.1:5140")
90-
--env-name string The environment of the application. Used to load the right configs file. (default "PROD")
91-
--filter string Filter to filter logs with. Valid filters: [regex]
92-
--filter-regex string Regex to filter with.
93-
--log-level string The granularity of log outputs. Valid levels: [PANIC FATAL ERROR WARN INFO DISABLED TRACE DISABLED] (default "INFO")
94-
--log-output string The output to write to. Valid outputs: [stdout stderr] (default "stdout")
95-
--log-writer string The log writer. Valid writers: [console json] (default "console")
96-
--mutator string Mutator type to use. Valid mutators: [text json] (default "text")
97-
--sink-console-output string Console to output to. Valid outputs: [stdout stderr] (default "stdout")
98-
--sink-elasticsearch-addresses strings Elasticsearch server addresses.
99-
--sink-elasticsearch-api-key string Elasticsearch api key.
100-
--sink-elasticsearch-cloud-id string Elasticsearch cloud id.
101-
--sink-elasticsearch-index-name string Elasticsearch index name. (default "tinysyslog")
102-
--sink-elasticsearch-password string Elasticsearch password.
103-
--sink-elasticsearch-service-token string Elasticsearch service token.
104-
--sink-elasticsearch-username string Elasticsearch username.
105-
--sink-filesystem-filename string File path to write incoming logs to. (default "syslog.log")
106-
--sink-filesystem-max-age int Maximum age (in days) before a log is deleted. (default 30)
107-
--sink-filesystem-max-backups int Maximum backups to keep. (default 10)
108-
--sink-filesystem-max-size int Maximum log size (in megabytes) before it's rotated. (default 100)
109-
--sinks strings Sinks to save syslogs to. Valid sinks: [console elasticsearch filesystem] (default [console])
110-
--socket-type string Type of socket to use, TCP or UDP. If no type is specified, both are used.
88+
--app-name string The name of the application. (default "tinysyslog")
89+
--bind-addr string IP and port to listen on. (default "127.0.0.1:5140")
90+
--env-name string The environment of the application. Used to load the right configs file. (default "PROD")
91+
--filter string Filter to filter logs with. Valid filters: [noop regex]
92+
--filter-regex string Regex to filter with.
93+
--log-level string The granularity of log outputs. Valid levels: [PANIC FATAL ERROR WARN INFO DISABLED TRACE DISABLED] (default "INFO")
94+
--log-output string The output to write to. Valid outputs: [stdout stderr] (default "stdout")
95+
--log-writer string The log writer. Valid writers: [console json] (default "console")
96+
--mutator string Mutator type to use. Valid mutators: [text json] (default "text")
97+
--sink-console-output string Console to output to. Valid outputs: [stdout stderr] (default "stdout")
98+
--sink-filesystem-filename string File path to write incoming logs to. (default "syslog.log")
99+
--sink-filesystem-max-age int Maximum age (in days) before a log is deleted. (default 30)
100+
--sink-filesystem-max-backups int Maximum backups to keep. (default 10)
101+
--sink-filesystem-max-size int Maximum log size (in megabytes) before it's rotated. (default 100)
102+
--sinks strings Sinks to save syslogs to. Valid sinks: [console filesystem] (default [console])
103+
--socket-type string Type of socket to use, TCP or UDP. If no type is specified, both are used.
111104
```

0 commit comments

Comments
 (0)