1+ # build: docker build --no-cache --progress=plain --build-arg PHP_VERSION=8.4 -t tobi312/php:8.4-fpm-nginx-alpine-extended -f alpine.fpm_nginx.extended.git.Dockerfile .
12ARG PHP_VERSION=8.4
2- ARG ARCH="amd64"
3-
43FROM golang:alpine AS builder
5- ARG ARCH
64
7- ENV GOPATH /go
8- ENV CGO_ENABLED 0
9- ENV GO111MODULE on
10- ENV GOOS linux
11- ENV GOARCH ${ARCH}
5+ ENV GOPATH=/go
6+ ENV CGO_ENABLED=0
7+
8+ RUN apk add --no-cache git
9+
10+
11+ FROM builder AS build-nginxexporter
12+
13+ WORKDIR /go/src/nginx-prometheus-exporter
1214
15+ # NGINX Prometheus Exporter (latest release version) <https://github.com/nginxinc/nginx-prometheus-exporter>
16+ RUN \
17+ NGINX_EXPORTER_VERSION=$(wget -qO- https://api.github.com/repos/nginxinc/nginx-prometheus-exporter/releases/latest | grep 'tag_name' | cut -d '"' -f4) ; \
18+ echo "NGINX_EXPORTER_VERSION=${NGINX_EXPORTER_VERSION}" ; \
19+ BUILD_VERSION=$(echo ${NGINX_EXPORTER_VERSION} | sed 's/[^.0-9][^.0-9]*//g' ) ; \
20+ GOOS="$(go env GOOS)" GOARCH="$(go env GOARCH)" ; \
21+ wget -qO- https://github.com/nginxinc/nginx-prometheus-exporter/releases/download/${NGINX_EXPORTER_VERSION}/nginx-prometheus-exporter_${BUILD_VERSION}_${GOOS}_${GOARCH}.tar.gz | tar -xz -C "${GOPATH}/bin" nginx-prometheus-exporter ; \
22+ ${GOPATH}/bin/nginx-prometheus-exporter --version
23+
24+
25+ FROM builder AS build-phpfpmexporter
26+
27+ WORKDIR /go/src/php-fpm_exporter
28+
29+ # PHP-FPM Exporter (latest release version) <https://github.com/hipages/php-fpm_exporter>
1330RUN \
14- apk add --no-cache git ; \
15- cd /go ; \
1631 PHP_FPM_EXPORTER_VERSION=$(wget -qO- https://api.github.com/repos/hipages/php-fpm_exporter/releases/latest | grep 'tag_name' | cut -d '"' -f4) ; \
1732 echo "PHP_FPM_EXPORTER_VERSION=${PHP_FPM_EXPORTER_VERSION}" ; \
18- git clone --branch ${PHP_FPM_EXPORTER_VERSION} https://github.com/hipages/php-fpm_exporter.git ; \
19- cd php-fpm_exporter/ ; \
33+ git clone --branch ${PHP_FPM_EXPORTER_VERSION} --single-branch https://github.com/hipages/php-fpm_exporter.git . ; \
2034 BUILD_VERSION=$(echo ${PHP_FPM_EXPORTER_VERSION} | sed 's/[^.0-9][^.0-9]*//g' ) ; \
2135 VCS_REF=$(git rev-parse HEAD) ; \
2236 BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ' ) ; \
23- # go get -d -v ; \
24- go build -trimpath -a -v -ldflags "-X main.version=${BUILD_VERSION} -X main.commit=${VCS_REF} -X main.date=${BUILD_DATE}" -o "/go/bin/php-fpm-exporter" ; \
25- echo "php-fpm_exporter build finished!"
37+ rm go.mod go.sum && go mod init github.com/hipages/php-fpm_exporter && go mod tidy ; \
38+ GOOS="$(go env GOOS)" GOARCH="$(go env GOARCH)" \
39+ go build -trimpath -a -v -ldflags "-X main.version=${BUILD_VERSION} -X main.commit=${VCS_REF} -X main.date=${BUILD_DATE}" -o "${GOPATH}/bin/php-fpm_exporter" ; \
40+ ${GOPATH}/bin/php-fpm_exporter version
41+
2642
2743FROM tobi312/php:${PHP_VERSION}-fpm-nginx-alpine
2844ARG PHP_VERSION
29- ARG ARCH
3045
3146ARG VCS_REF
3247ARG BUILD_DATE
@@ -35,8 +50,6 @@ ARG BUILD_DATE
3550ENV ENABLE_NGINX_STATUS=1 \
3651 ENABLE_PHP_FPM_STATUS=1 \
3752 WWW_USER=www-data \
38- ARCH="${ARCH}" \
39- TARGETARCH="${ARCH}" \
4053 NGINX_EXPORTER="--nginx.scrape-uri='http://localhost/nginx_status' --web.listen-address=':9113' --web.telemetry-path='/metrics' --no-nginx.ssl-verify" \
4154 PHP_FPM_EXPORTER="server --phpfpm.scrape-uri='tcp://127.0.0.1:9000/php_fpm_status' --web.listen-address=':9253' --web.telemetry-path='/metrics' --log.level=info --phpfpm.fix-process-count=false"
4255
@@ -47,13 +60,12 @@ ENV ENABLE_NGINX_STATUS=1 \
4760# ca-certificates \
4861# tzdata
4962
50- # install Nginx Exporter (latest release version) <https://github.com/nginxinc/nginx-prometheus-exporter>
63+ # copy exporter
64+ COPY --from=build-nginxexporter /go/bin/nginx-prometheus-exporter /usr/local/bin/
65+ COPY --from=build-phpfpmexporter /go/bin/php-fpm_exporter /usr/local/bin/
66+
67+ # supervisord for exporter
5168RUN \
52- NGINX_EXPORTER_VERSION=$(curl -s https://api.github.com/repos/nginxinc/nginx-prometheus-exporter/releases/latest | grep 'tag_name' | cut -d '"' -f4) ; \
53- echo "NGINX_EXPORTER_VERSION=${NGINX_EXPORTER_VERSION}" ; \
54- curl -sSL https://github.com/nginxinc/nginx-prometheus-exporter/releases/download/${NGINX_EXPORTER_VERSION}/nginx-prometheus-exporter_$(echo ${NGINX_EXPORTER_VERSION} | sed 's/[^.0-9][^.0-9]*//g' )_linux_${TARGETARCH}.tar.gz | tar xvz -C /usr/local/bin ; \
55- chmod +x /usr/local/bin/nginx-prometheus-exporter \
56- ; \
5769 { \
5870 echo '' ; \
5971 echo '[program:exporter-nginx]' ; \
6577 echo 'stderr_logfile_maxbytes=0' ; \
6678 echo 'priority=30' ; \
6779 echo 'autorestart=unexpected' ; \
68- } >> /etc/supervisor.d/supervisord.ini
69-
70- # install PHP-FPM Exporter (latest release version) <https://github.com/hipages/php-fpm_exporter>
71- COPY --from=builder /go/bin/php-fpm-exporter /usr/local/bin/php-fpm-exporter
72- RUN \
73- chmod +x /usr/local/bin/php-fpm-exporter \
74- ; \
80+ } >> /etc/supervisor.d/supervisord.ini ; \
81+ \
7582 { \
7683 echo '' ; \
7784 echo '[program:exporter-phpfpm]' ; \
@@ -83,24 +90,11 @@ RUN \
8390 echo 'stderr_logfile_maxbytes=0' ; \
8491 echo 'priority=30' ; \
8592 echo 'autorestart=unexpected' ; \
86- } >> /etc/supervisor.d/supervisord.ini
87-
88- # envsubst for templating <https://github.com/nginxinc/docker-nginx/blob/master/stable/alpine-slim/Dockerfile#L86-L102>
89- RUN apk add --no-cache --virtual .gettext gettext ; \
90- mv /usr/bin/envsubst /tmp/ \
91- ; \
92- runDeps="$( \
93- scanelf --needed --nobanner /tmp/envsubst \
94- | awk '{ gsub(/,/, " \n so:", $2); print " so:" $2 }' \
95- | sort -u \
96- | xargs -r apk info --installed \
97- | sort -u \
98- )" \
99- ; \
100- apk add --no-cache $runDeps ; \
101- apk del .gettext ; \
102- mv /tmp/envsubst /usr/local/bin/ \
103- ; \
93+ } >> /etc/supervisor.d/supervisord.ini ; \
94+ echo "add exporter to /etc/supervisor.d/supervisord.ini done"
95+
96+ # envsubst for templating <https://github.com/nginx/docker-nginx/blob/master/stable/alpine-slim/Dockerfile#L86-L87>
97+ RUN apk add --no-cache gettext-envsubst ; \
10498 curl -sSL https://github.com/nginxinc/docker-nginx/raw/master/entrypoint/20-envsubst-on-templates.sh -o /entrypoint.d/20-envsubst-on-templates.sh ; \
10599 chmod +x /entrypoint.d/20-envsubst-on-templates.sh ; \
106100 mkdir /etc/nginx/templates
0 commit comments