This repository has been archived by the owner on Oct 25, 2022. It is now read-only.
forked from dreyau/bareos_exporter
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from barcus/dsn-using-var
Ease usage with docker entrypoint and env vars
- Loading branch information
Showing
3 changed files
with
82 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,32 @@ | ||
FROM golang as builder | ||
COPY . /go/src/github.com/vierbergenlars/bareos_exporter | ||
FROM golang:1.18.0 as builder | ||
|
||
RUN apt-get update \ | ||
&& apt-get install -y upx | ||
|
||
WORKDIR /go/src/github.com/vierbergenlars/bareos_exporter | ||
COPY . . | ||
|
||
RUN go get -v . | ||
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o bareos_exporter . | ||
RUN upx bareos_exporter | ||
|
||
FROM busybox:latest | ||
|
||
FROM busybox:1.34.1 | ||
WORKDIR /bareos_exporter | ||
COPY --from=builder /go/src/github.com/vierbergenlars/bareos_exporter/bareos_exporter bareos_exporter | ||
COPY entrypoint.sh /entrypoint.sh | ||
RUN chmod u+x /entrypoint.sh | ||
|
||
ENV PORT 9625 | ||
ENV DB_TYPE postgres | ||
ENV DB_HOST localhost | ||
ENV DB_PORT 5432 | ||
ENV DB_NAME bareos | ||
ENV DB_USER bareos | ||
ENV SSL_MODE disable | ||
ENV ENDPOINT /metrics | ||
ENV JOB_DAYS 7 | ||
ENV WAIT_FOR_DB 0 | ||
|
||
ENTRYPOINT ["./bareos_exporter"] | ||
EXPOSE $port | ||
EXPOSE $PORT | ||
ENTRYPOINT ["/entrypoint.sh"] | ||
CMD ["./bareos_exporter"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/env sh | ||
#set -x | ||
|
||
# Wait for DB (default 0) | ||
sleep ${WAIT_FOR_DB} | ||
|
||
# Run Dockerfile CMD | ||
if [ "$1" == './bareos_exporter' ]; then | ||
if [ -z "${DB_TYPE}" ]; then | ||
echo 'Error: DB_TYPE is empty' | ||
exit 1 | ||
fi | ||
if [ -z "${DB_PASSWORD}" ]; then | ||
echo 'Warning: DB_PASSWORD is empty' | ||
fi | ||
if [ "${DB_TYPE}" == 'postgres' ]; then | ||
exec ./bareos_exporter -endpoint ${ENDPOINT} -job-discovery-days ${JOB_DAYS} -port ${PORT} -dsn "${DB_TYPE}://host=${DB_HOST} dbname=${DB_NAME} sslmode=${SSL_MODE} user=${DB_USER} password=${DB_PASSWORD} port=${DB_PORT}" | ||
fi | ||
if [ "${DB_TYPE}" == 'mysql' ]; then | ||
exec ./bareos_exporter -endpoint ${ENDPOINT} -job-discovery-days ${JOB_DAYS} -port ${PORT} -dsn "${DB_TYPE}://${DB_USER}:${DB_PASSWORD}@tcp(${DB_HOST}:${DB_PORT})/${DB_NAME}?parseTime=true" | ||
fi | ||
else | ||
exec ./bareos_exporter "$@" | ||
fi |