Postgres-exporter Dockerfile多阶段构建

266 阅读1分钟

Postgres-exporter Dockerfile多阶段构建

在多个pg-exporter探针在一套环境构建时候如何保证版本一致性

cat Dockerfile

ARG VERSION
FROM bitnami/postgres-exporter:${VERSION:-latest} AS base
LABEL changelog="add custom metrics"

ENTRYPOINT ["postgres_exporter", "--extend.query-path=/opt/bitnami/custom-metrics.yaml"]

FROM base AS sit_postgres_metrics
COPY ./metrics/sit/custom-metrics.yaml /opt/bitnami/custom-metrics.yaml

FROM base AS poc_postgres_metrics
COPY ./metrics/poc/custom-metrics.yaml /opt/bitnami/custom-metrics.yaml

构建脚本如下:

cat build.sh

#!/bin/bash

custom_metrics=(
sit
poc
)

arg_verison=0.10.0
version=1.10.0

for custom_merics in ${custom_metrics[@]}
do
   artifacts_image=docker.io/postgres-exporter:${custom_merics}-${version}
   docker build --build-arg VERSION=${arg_verison} --target ${custom_metrics}_postgres_metrics -t ${artifacts_image} .
   
done