diff --git a/Dockerfile b/Dockerfile index 7332a96..61bcd90 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/Makefile b/Makefile index 3f57577..a48b4bb 100644 --- a/Makefile +++ b/Makefile @@ -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) .