Merge branch '2-build-docker-image' into 'main'

Resolve "Build docker image"

Closes #2

See merge request hectorjsmith/fail2ban-prometheus-exporter!7
This commit is contained in:
Hector 2021-02-07 13:11:16 +00:00
commit b1c70da101
4 changed files with 30 additions and 3 deletions

10
Dockerfile Normal file
View File

@ -0,0 +1,10 @@
# Using golang:latest instead of alpine because of issues with sqlite3
FROM golang:latest
WORKDIR /app
COPY dist/fail2ban-prometheus-exporter_linux_amd64/fail2ban-prometheus-exporter /app
COPY docker/run.sh /app
RUN chmod +x /app/*
ENTRYPOINT /app/run.sh

View File

@ -22,3 +22,9 @@ build/snapshot:
build/release: build/release:
./tools/goreleaser_linux_amd64 --rm-dist --skip-publish ./tools/goreleaser_linux_amd64 --rm-dist --skip-publish
build/docker:
docker build -t registry.gitlab.com/hectorjsmith/fail2ban-prometheus-exporter:latest .
build/docker-tag:
docker build -t registry.gitlab.com/hectorjsmith/fail2ban-prometheus-exporter:$(shell git describe --tags) .

View File

@ -70,8 +70,10 @@ func (db *Fail2BanDB) RunJailNameToCountQuery(query string) (map[string]int, err
} }
func (db *Fail2BanDB) mustCloseStatement(stmt *sql.Stmt) { func (db *Fail2BanDB) mustCloseStatement(stmt *sql.Stmt) {
err := stmt.Close() if stmt != nil {
if err != nil { err := stmt.Close()
log.Fatal(err) if err != nil {
log.Fatal(err)
}
} }
} }

9
docker/run.sh Normal file
View File

@ -0,0 +1,9 @@
#/bin/sh
# Print version to logs for debugging purposes
/app/fail2ban-prometheus-exporter -version
# Start the exporter (use exec to support graceful shutdown)
# Inspired by: https://akomljen.com/stopping-docker-containers-gracefully/
exec /app/fail2ban-prometheus-exporter \
-db /app/fail2ban.sqlite3