Skip to content

Dockerfile improvements#636

Merged
discordianfish merged 2 commits intoprometheus:masterfrom
sdurrheimer:master
Apr 14, 2015
Merged

Dockerfile improvements#636
discordianfish merged 2 commits intoprometheus:masterfrom
sdurrheimer:master

Conversation

@sdurrheimer
Copy link
Copy Markdown
Contributor

Hi,

Here are some improvements on weight and build's speed of the docker image.

apt-get clean is useless because debian base image is already configured to remove the package cache after eachapt-get install. (/etc/apt/apt.conf.d/docker-clean).

However, image can be lightened with rm -rf /var/lib/apt/lists/*. Anyway, this change fixes the following error when extending prom/promtheus image :

W: Size of file /var/lib/apt/lists/http.debian.net_debian_dists_jessie_main_binary-amd64_Packages.gz is not what the server reported 9037866 9039181

Here a picture to illustrate this change :
prometheus_dockerfile_improvement_1

Finally gcc and mercurial package are already installed by inherited images.

In my opinion, there are more ways to optimise this image. Presently it's pretty heavy. A lot of this heavyness is coming from the golang base image. Maybe can we find a way to build this from a base image like gliderlabs/alpine in the way others golang programs does like gliderlabs/registrator or gliderlabs/logspout.
Although maybe can we, in the first place, find a way to replace xxd usage in order to remove the vim-common package, adding 59MB to the image.

Hope this helps.

@beorn7 @juliusv @discordianfish

Signed-off-by: Steve Durrheimer <[email protected]>
… buildpack-deps:jessie-scm, gcc => golang:1.4)

Signed-off-by: Steve Durrheimer <[email protected]>
@juliusv
Copy link
Copy Markdown
Member

juliusv commented Apr 14, 2015

👍 from my limited knowledge about Docker best practices. @discordianfish, opinion about the base image change?

@discordianfish
Copy link
Copy Markdown
Member

@sdurrheimer Thanks! Looks good.

On the long term, we want to build really small images based on the binary builds of prometheus. Unfortunatly that isn't ready yet. @grobie IIRC you wanted to work on this. Do you have an ETA?

discordianfish added a commit that referenced this pull request Apr 14, 2015
@discordianfish discordianfish merged commit defcafb into prometheus:master Apr 14, 2015
@sdurrheimer
Copy link
Copy Markdown
Contributor Author

Hi again,

I did some tests building a small size docker image. Take a look :
prometheus_small_size_docker_image

FROM alpine:edge
MAINTAINER The Prometheus Authors <[email protected]>

ENV GOPATH /go
COPY . /go/src/github.com/prometheus/prometheus

RUN apk add --update -t build-deps go git mercurial vim \
    && apk add -u musl && rm -rf /var/cache/apk/* \
    && go get github.com/tools/godep \
    && cd /go/src/github.com/prometheus/prometheus \
    && $GOPATH/bin/godep restore && go get -d \
    && ./utility/embed-static.sh web/static web/templates | gofmt > web/blob/files.go \
    && go build -ldflags " \
            -X main.buildVersion  $(cat VERSION) \
            -X main.buildRevision $(git rev-parse --short HEAD) \
            -X main.buildBranch   $(git rev-parse --abbrev-ref HEAD) \
            -X main.buildUser     root \
            -X main.buildDate     $(date +%Y%m%d-%H:%M:%S) \
            -X main.goVersion     $(go version | awk '{print substr($3,3)}') \
        " -o /bin/prometheus \
    && cd tools/rule_checker && go build && cd ../.. \
    && mkdir -p /etc/prometheus \
    && mv ./documentation/examples/prometheus.conf /etc/prometheus/prometheus.conf \
    && mv ./console_libraries/ ./consoles/ /etc/prometheus/ \
    && rm -rf /go \
    && apk del --purge build-deps

EXPOSE     9090
VOLUME     [ "/prometheus", "/etc/prometheus" ]
WORKDIR    /prometheus
ENTRYPOINT [ "/bin/prometheus" ]
CMD        [ "-logtostderr", "-config.file=/etc/prometheus/prometheus.conf", \
             "-storage.local.path=/prometheus", \
             "-web.console.libraries=/etc/prometheus/console_libraries", \
             "-web.console.templates=/etc/prometheus/consoles" ]

@discordianfish
Copy link
Copy Markdown
Member

@sdurrheimer Love it! Can you submit a PR? This might breaks people who assumes that this image is ubuntu and try to install ubuntu base but I still think it's worth it.

@sdurrheimer
Copy link
Copy Markdown
Contributor Author

There are definitly breaking changes.

It will affect people :

  • who extended the prom/prometheus image, thinking it's a debian base image.
  • the /go/src/github.com/prometheus/prometheus/console_libraries, /go/src/github.com/prometheus/prometheus/consoles folders moved to /etc/prometheus
  • /prometheus.conf file moved to /etc/prometheus too.

Some precisions :

  • I used the edge tag of alpine base image because of golang version. In alpine:3.1, golang version is 1.3.3. In alpine:edge, it's 1.4.2. Later on, we will be able to change to alpine:3.2 when it released.

@discordianfish
Copy link
Copy Markdown
Member

Well I would be okay breaking people with that change. The thing is, it's a inherit design issue with Docker, there is just no way to provide a stable interface to people who build upon a image. Nothing we can do about that.

codesome pushed a commit to codesome/prometheus that referenced this pull request Jul 29, 2019
fileutil.Replace - remove destination only when a directory.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants