Merge branch 'build/compile-docker-version-of-tool' into 'main'

Build/compile docker version of tool

See merge request hectorjsmith/fail2ban-prometheus-exporter!10
This commit is contained in:
Hector 2021-02-08 19:54:02 +00:00
commit 542b853309
2 changed files with 22 additions and 4 deletions

View file

@ -1,10 +1,24 @@
# Using golang:latest instead of alpine because of issues with sqlite3
FROM golang:latest
# Create build folder to compile tool
WORKDIR /build
# Copy source files to build folder and link to the /go folder
COPY . /build
RUN ln -s /go/src/ /build/src
# Compile the tool using a Make command
RUN make build/docker
# Create main app folder to run from
WORKDIR /app
COPY dist/fail2ban-prometheus-exporter_linux_amd64/fail2ban-prometheus-exporter /app
COPY docker/run.sh /app
# Move compiled binary to app folder and delete build folder
RUN mv /build/src/exporter /app/fail2ban-prometheus-exporter
RUN rm -rf /build
# Copy init script into main app folder and set as entry point
COPY docker/run.sh /app/
RUN chmod +x /app/*
ENTRYPOINT /app/run.sh

View file

@ -24,7 +24,11 @@ build/release:
./tools/goreleaser_linux_amd64 --rm-dist --skip-publish
build/docker:
cd src/ && go build -o exporter \
-ldflags '-X main.version=$(shell git describe --tags) -X main.commit=${shell git rev-parse HEAD} -X "main.date=${shell date --rfc-3339=seconds}" -X main.builtBy=docker' exporter.go
docker/build-latest:
docker build -t registry.gitlab.com/hectorjsmith/fail2ban-prometheus-exporter:latest .
build/docker-tag:
docker/build-tag:
docker build -t registry.gitlab.com/hectorjsmith/fail2ban-prometheus-exporter:$(shell git describe --tags) .