merge: add-manual-docker-multistep-build
* Merge branch 'add-manual-docker-multistep-build' into 'main' * See merge request hectorjsmith/fail2ban-prometheus-exporter!114 * Merged by: Hector <hector@hjs.dev>
This commit is contained in:
commit
581220c654
4 changed files with 36 additions and 4 deletions
|
@ -23,6 +23,7 @@ dockers:
|
||||||
extra_files:
|
extra_files:
|
||||||
- health
|
- health
|
||||||
use: buildx
|
use: buildx
|
||||||
|
dockerfile: Dockerfile.goreleaser
|
||||||
build_flag_templates:
|
build_flag_templates:
|
||||||
- "--pull"
|
- "--pull"
|
||||||
- "--platform=linux/amd64"
|
- "--platform=linux/amd64"
|
||||||
|
@ -42,6 +43,7 @@ dockers:
|
||||||
extra_files:
|
extra_files:
|
||||||
- health
|
- health
|
||||||
use: buildx
|
use: buildx
|
||||||
|
dockerfile: Dockerfile.goreleaser
|
||||||
build_flag_templates:
|
build_flag_templates:
|
||||||
- "--pull"
|
- "--pull"
|
||||||
- "--platform=linux/arm64"
|
- "--platform=linux/arm64"
|
||||||
|
|
21
Dockerfile
21
Dockerfile
|
@ -1,11 +1,26 @@
|
||||||
|
FROM golang:1.20-buster AS build
|
||||||
|
|
||||||
|
# Create build workspace folder
|
||||||
|
WORKDIR /workspace
|
||||||
|
ADD . /workspace
|
||||||
|
|
||||||
|
# Install updates and build tools
|
||||||
|
RUN apt update --yes && \
|
||||||
|
apt install --yes build-essential
|
||||||
|
|
||||||
|
# Build the actual binary
|
||||||
|
RUN make build
|
||||||
|
|
||||||
|
# -- -- -- -- -- --
|
||||||
|
|
||||||
|
# Set up image to run the tool
|
||||||
FROM alpine
|
FROM alpine
|
||||||
|
|
||||||
# Create main app folder to run from
|
# Create main app folder to run from
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Copy compiled binary to release image
|
# Copy built binary from build image
|
||||||
# (must build the binary before running docker build)
|
COPY --from=build /workspace/fail2ban_exporter /app
|
||||||
COPY fail2ban_exporter /app/fail2ban_exporter
|
|
||||||
|
|
||||||
# Setup a healthcheck
|
# Setup a healthcheck
|
||||||
COPY health /app/health
|
COPY health /app/health
|
||||||
|
|
15
Dockerfile.goreleaser
Normal file
15
Dockerfile.goreleaser
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
FROM alpine
|
||||||
|
|
||||||
|
# Create main app folder to run from
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy compiled binary to release image
|
||||||
|
# (must build the binary before running docker build)
|
||||||
|
COPY fail2ban_exporter /app/fail2ban_exporter
|
||||||
|
|
||||||
|
# Setup a healthcheck
|
||||||
|
COPY health /app/health
|
||||||
|
RUN apk add curl
|
||||||
|
HEALTHCHECK --interval=10s --timeout=4s --retries=3 CMD /app/health
|
||||||
|
|
||||||
|
ENTRYPOINT ["/app/fail2ban_exporter"]
|
2
Makefile
2
Makefile
|
@ -51,5 +51,5 @@ build:
|
||||||
|
|
||||||
# Build project docker container
|
# Build project docker container
|
||||||
.PHONY: build/docker
|
.PHONY: build/docker
|
||||||
build/docker: build
|
build/docker:
|
||||||
docker build -t fail2ban-prometheus-exporter .
|
docker build -t fail2ban-prometheus-exporter .
|
||||||
|
|
Loading…
Reference in a new issue