Skip to content

Commit 16291b6

Browse files
committed
Improve multi-stage build
1 parent c47bc0a commit 16291b6

3 files changed

Lines changed: 33 additions & 21 deletions

File tree

prometheus/Dockerfile

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
1-
FROM stefanscherer/chocolatey AS tar
2-
RUN choco install -y 7zip
1+
# escape=`
2+
FROM microsoft/windowsservercore AS tar
3+
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
4+
RUN Invoke-WebRequest 'http://www.7-zip.org/a/7z1604-x64.msi' -OutFile '7z.msi' -UseBasicParsing
5+
RUN Start-Process msiexec.exe -ArgumentList '/i', '7z.msi', '/quiet', '/norestart' -NoNewWindow -Wait
6+
37
ENV PROMETHEUS_VERSION 1.6.1
4-
RUN Invoke-WebRequest $('https://github.com/prometheus/prometheus/releases/download/v{0}/prometheus-{0}.windows-amd64.tar.gz' -f $env:PROMETHEUS_VERSION) -OutFile 'prometheus.tar.gz' -UseBasicParsing ; \
5-
& 'C:\Program Files\7-Zip\7z.exe' x prometheus.tar.gz ; \
6-
& 'C:\Program Files\7-Zip\7z.exe' x prometheus.tar ; \
7-
Rename-Item -Path $('C:\prometheus-{0}.windows-amd64' -f $env:PROMETHEUS_VERSION) -NewName 'C:\download'
8+
9+
RUN Invoke-WebRequest $('https://github.com/prometheus/prometheus/releases/download/v{0}/prometheus-{0}.windows-amd64.tar.gz' -f $env:PROMETHEUS_VERSION) -OutFile 'prometheus.tar.gz' -UseBasicParsing
10+
RUN & 'C:\Program Files\7-Zip\7z.exe' x prometheus.tar.gz
11+
RUN & 'C:\Program Files\7-Zip\7z.exe' x prometheus.tar
12+
RUN Rename-Item -Path $('C:\prometheus-{0}.windows-amd64' -f $env:PROMETHEUS_VERSION) -NewName 'C:\download'
813

914
FROM microsoft/nanoserver
1015

11-
COPY --from tar /download/prometheus.exe /bin/prometheus.exe
12-
COPY --from tar /download/promtool.exe /bin/promtool.exe
13-
COPY --from tar /download/prometheus.yml /etc/prometheus/prometheus.yml
14-
COPY --from tar /download/console_libraries/ /etc/prometheus/
15-
COPY --from tar /download/consoles/ /etc/prometheus/
16+
COPY --from=tar /download/prometheus.exe /bin/prometheus.exe
17+
COPY --from=tar /download/promtool.exe /bin/promtool.exe
18+
COPY --from=tar /download/prometheus.yml /etc/prometheus/prometheus.yml
19+
COPY --from=tar /download/console_libraries/ /etc/prometheus/
20+
COPY --from=tar /download/consoles/ /etc/prometheus/
1621

1722
EXPOSE 9090
18-
VOLUME [ "/prometheus" ]
19-
WORKDIR /prometheus
23+
VOLUME C:\prometheus
24+
WORKDIR C:\prometheus
2025
ENTRYPOINT [ "C:\\bin\\prometheus.exe" ]
21-
CMD [ "-config.file=/etc/prometheus/prometheus.yml", \
22-
"-storage.local.path=/prometheus", \
23-
"-web.console.libraries=/etc/prometheus/console_libraries", \
26+
CMD [ "-config.file=/etc/prometheus/prometheus.yml", `
27+
"-storage.local.path=/prometheus", `
28+
"-web.console.libraries=/etc/prometheus/console_libraries", `
2429
"-web.console.templates=/etc/prometheus/consoles" ]

prometheus/push.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
docker tag prometheus stefanscherer/prometheus-windows:1.6.1
1+
$version=$(select-string -Path Dockerfile -Pattern "ENV PROMETHEUS_VERSION").ToString().split()[-1]
2+
docker tag prometheus stefanscherer/prometheus-windows:$version
23
docker tag prometheus stefanscherer/prometheus-windows:latest
3-
docker push stefanscherer/prometheus-windows:1.6.1
4+
docker push stefanscherer/prometheus-windows:$version
45
docker push stefanscherer/prometheus-windows:latest

prometheus/test.ps1

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1-
docker run -d -p 9090:9090 prometheus
2-
Start-Sleep 10
3-
docker logs $(docker ps -ql)
1+
docker run --name caddy -d -p 9090:9090 prometheus
2+
Start-Sleep -Seconds 5
3+
$req = Invoke-WebRequest http://$(docker inspect -f '{{ .NetworkSettings.Networks.nat.IPAddress }}' prometheus):9090/graph -UseBasicParsing
4+
$code = $req.statuscode
5+
$content = $req.content
6+
if($code -ne 200 -or !($content.Contains('prometheus.io'))){
7+
throw "Prometheus test failed!"
8+
}
9+
docker logs prometheus

0 commit comments

Comments
 (0)