OP#176 edit Dockerfile and start.sh
This commit is contained in:
28
Dockerfile
28
Dockerfile
@@ -6,33 +6,37 @@ RUN apk add --no-cache git make gcc musl-dev
|
|||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
# Fix missing go.sum entries
|
|
||||||
RUN go mod tidy
|
RUN go mod tidy
|
||||||
|
|
||||||
# Build (default target = all)
|
|
||||||
RUN make
|
RUN make
|
||||||
|
|
||||||
# Verify binary exists and is executable — no --version check
|
# Verify binary
|
||||||
RUN ls -la postgresql-prometheus-adapter && \
|
RUN ls -la postgresql-prometheus-adapter && \
|
||||||
./postgresql-prometheus-adapter --help > /dev/null
|
./postgresql-prometheus-adapter --help > /dev/null
|
||||||
|
|
||||||
|
|
||||||
# ───── Stage 2: Runtime (Alpine = has glibc + loader) ─────
|
# ───── Stage 2: Runtime (Alpine for glibc/loader) ─────
|
||||||
FROM alpine:3.20
|
FROM alpine:3.20
|
||||||
|
|
||||||
# Install only what the binary needs (tiny)
|
RUN apk add --no-cache libc6-compat bash # bash for start.sh, libc for binary
|
||||||
RUN apk add --no-cache libc6-compat
|
|
||||||
|
|
||||||
|
# Copy binary
|
||||||
COPY --from=builder /src/postgresql-prometheus-adapter /usr/local/bin/postgresql-prometheus-adapter
|
COPY --from=builder /src/postgresql-prometheus-adapter /usr/local/bin/postgresql-prometheus-adapter
|
||||||
|
|
||||||
# Make sure it's executable (just in case)
|
|
||||||
RUN chmod +x /usr/local/bin/postgresql-prometheus-adapter
|
RUN chmod +x /usr/local/bin/postgresql-prometheus-adapter
|
||||||
|
|
||||||
USER 1001:1001
|
# Copy and make start.sh executable
|
||||||
|
COPY start.sh /usr/local/bin/start.sh
|
||||||
|
RUN chmod +x /usr/local/bin/start.sh
|
||||||
|
|
||||||
|
# Non-root user
|
||||||
|
RUN addgroup -g 1001 -S appgroup && \
|
||||||
|
adduser -S -D -H -u 1001 -h /home/app -s /bin/bash -G appgroup -g appuser appuser
|
||||||
|
USER appuser
|
||||||
|
|
||||||
|
WORKDIR /home/app
|
||||||
|
|
||||||
EXPOSE 9201
|
EXPOSE 9201
|
||||||
|
|
||||||
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
||||||
CMD ["wget", "--spider", "-q", "http://127.0.0.1:9201/health"] || exit 1
|
CMD wget --no-verbose --tries=1 --spider http://localhost:9201/health || exit 1
|
||||||
|
|
||||||
ENTRYPOINT ["/usr/local/bin/postgresql-prometheus-adapter"]
|
ENTRYPOINT ["/usr/local/bin/start.sh"]
|
||||||
57
start.sh
57
start.sh
@@ -1,6 +1,8 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
if [[ "${DATABASE_URL}" == "" ]]; then
|
set -e
|
||||||
|
|
||||||
|
if [[ "${DATABASE_URL}" = "" ]]; then
|
||||||
echo 'Missing DATABASE_URL'
|
echo 'Missing DATABASE_URL'
|
||||||
echo 'example -e DATABASE_URL="user=<db user> password=<db user password> host=<db host> port=<db port> database=<db name>"'
|
echo 'example -e DATABASE_URL="user=<db user> password=<db user password> host=<db host> port=<db port> database=<db name>"'
|
||||||
exit 1
|
exit 1
|
||||||
@@ -12,38 +14,39 @@ function shutdown() {
|
|||||||
pkill -SIGINT postgresql-prometheus-adapter
|
pkill -SIGINT postgresql-prometheus-adapter
|
||||||
}
|
}
|
||||||
|
|
||||||
adapter_send_timeout=${adapter_send_timeout:-'30s'}
|
adapter_send_timeout="${adapter_send_timeout:-'30s'}"
|
||||||
web_listen_address="${web_listen_address:-':9201'}"
|
web_listen_address="${web_listen_address:-':9201'}"
|
||||||
web_telemetry_path="${web_telemetry_path:-'/metrics'}"
|
web_telemetry_path="${web_telemetry_path:-'/metrics'}"
|
||||||
log_level="${log_level:-'info'}"
|
log_level="${log_level:-'info'}"
|
||||||
log_format="${log_format:-'logfmt'}"
|
log_format="${log_format:-'logfmt'}"
|
||||||
pg_partition="${pg_partition:-'hourly'}"
|
pg_partition="${pg_partition:-'hourly'}"
|
||||||
pg_commit_secs=${pg_commit_secs:-30}
|
pg_commit_secs="${pg_commit_secs:-30}"
|
||||||
pg_commit_rows=${pg_commit_rows:-20000}
|
pg_commit_rows="${pg_commit_rows:-20000}"
|
||||||
pg_threads="${pg_threads:-1}"
|
pg_threads="${pg_threads:-1}"
|
||||||
parser_threads="${parser_threads:-5}"
|
parser_threads="${parser_threads:-5}"
|
||||||
|
|
||||||
echo /postgresql-prometheus-adapter \
|
echo "/usr/local/bin/postgresql-prometheus-adapter \
|
||||||
--adapter-send-timeout=${adapter_send_timeout} \
|
--adapter-send-timeout=${adapter_send_timeout} \
|
||||||
--web-listen-address=${web_listen_address} \
|
--web-listen-address=${web_listen_address} \
|
||||||
--web-telemetry-path=${web_telemetry_path} \
|
--web-telemetry-path=${web_telemetry_path} \
|
||||||
--log.level=${log_level} \
|
--log.level=${log_level} \
|
||||||
--log.format=${log_format} \
|
--log.format=${log_format} \
|
||||||
--pg-partition=${pg_partition} \
|
--pg-partition=${pg_partition} \
|
||||||
--pg-commit-secs=${pg_commit_secs} \
|
--pg-commit-secs=${pg_commit_secs} \
|
||||||
--pg-commit-rows=${pg_commit_rows} \
|
--pg-commit-rows=${pg_commit_rows} \
|
||||||
--pg-threads=${pg_threads} \
|
--pg-threads=${pg_threads} \
|
||||||
--parser-threads=${parser_threads}
|
--parser-threads=${parser_threads} \
|
||||||
|
--database-url=${DATABASE_URL}"
|
||||||
/postgresql-prometheus-adapter \
|
|
||||||
--adapter-send-timeout=${adapter_send_timeout} \
|
|
||||||
--web-listen-address=${web_listen_address} \
|
|
||||||
--web-telemetry-path=${web_telemetry_path} \
|
|
||||||
--log.level=${log_level} \
|
|
||||||
--log.format=${log_format} \
|
|
||||||
--pg-partition=${pg_partition} \
|
|
||||||
--pg-commit-secs=${pg_commit_secs} \
|
|
||||||
--pg-commit-rows=${pg_commit_rows} \
|
|
||||||
--pg-threads=${pg_threads} \
|
|
||||||
--parser-threads=${parser_threads}
|
|
||||||
|
|
||||||
|
/usr/local/bin/postgresql-prometheus-adapter \
|
||||||
|
--adapter-send-timeout="${adapter_send_timeout}" \
|
||||||
|
--web-listen-address="${web_listen_address}" \
|
||||||
|
--web-telemetry-path="${web_telemetry_path}" \
|
||||||
|
--log.level="${log_level}" \
|
||||||
|
--log.format="${log_format}" \
|
||||||
|
--pg-partition="${pg_partition}" \
|
||||||
|
--pg-commit-secs="${pg_commit_secs}" \
|
||||||
|
--pg-commit-rows="${pg_commit_rows}" \
|
||||||
|
--pg-threads="${pg_threads}" \
|
||||||
|
--parser-threads="${parser_threads}" \
|
||||||
|
--database-url="${DATABASE_URL}"
|
||||||
Reference in New Issue
Block a user