eclipse-archived / codewind

The official repository of the Eclipse Codewind project
https://codewind.dev
Eclipse Public License 2.0
114 stars 45 forks source link

Reduce image size of project templates, and optimize their dockerfiles #187

Closed johnmcollier closed 4 years ago

johnmcollier commented 5 years ago

The overall size of the docker images we use in our templates (both as the base-layer and the resultant, built image) is getting to be too large. This leads to a small number of images taking up a lot of space on the user's machine, and on their docker registry. It also leads to overall longer build times, as more time needs to be spent pulling the base image, and pushing the built image up to a Docker registry.

Furthermore, Kube needs to pull the docker image before the application is deployed, so the larger the project's docker image, the longer it will take to start the application.

Our templates have the following sizes, when pushed to Dockerhub (which compresses the layers a fair bit, so overall size will be larger on the user's machine or cluster):

If we make use of smaller overall base images and multi stage builds, we can reduce the overall footprint a fair bit. For example, if we change the Go template's dockerfile to use alpine and a build-stage:

FROM golang:latest as builder
RUN mkdir /app
ADD . /app/
WORKDIR /app
RUN CGO_ENABLED=0 GOOS=linux go build -o main .

FROM alpine:latest
COPY --from=builder /app/main /app/main
CMD ["/app/main"]
EXPOSE 8000

The resultant image is only 7MB on Dockerhub, which is much more reasonable for a hello world app.

We should look at what improvements and optimizations we can make to our project templates to improve and optimize the resultant size of their docker images, and to reduce overall build time.

I recommend also looking at https://blog.docker.com/2019/07/intro-guide-to-dockerfile-best-practices/

johnmcollier commented 5 years ago

Some areas to look at:

deboer-tim commented 5 years ago

Many of these templates are still coming from microclimate-dev2ops, and also include out of date readme/splash screens and Jenkinsfiles. FYI, I've talked to a couple people (but primarily Toby) about copying these to another org and then doing some general cleanup, I don't know if we have an issue open for that.

johnmcollier commented 5 years ago

@deboer-tim I've actually been meaning to follow up about creating a codewind-templates org on Github. I don't see an issue Github for that currently, but I'll go open one.

tobespc commented 4 years ago

issue https://github.com/eclipse/codewind/issues/1788 is investigating using UBI that could well help in this area

tobespc commented 4 years ago

closing as moved to centos everywhere