-
Notifications
You must be signed in to change notification settings - Fork 389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add slim build support #276
Conversation
3741196
to
859851a
Compare
I am not sure the image size has much to do with CI system UNLESS CI system does not cache images. For example GitHub Actions https://github.com/bahmutov/cypress-gh-action-included/runs/498639926?check_suite_focus=true just spends 1 minute to get the image GitLab CI takes 1 min and 22 seconds to pull So I don't think the size of the Docker image matters that much - it depends on the CI caching a lot more. |
@bahmutov I'm on CircleCI and I agree, the image is often cached and pulling the image is usually fast. That is one more point for having Cypress binaries embedded in the image. Downloading them in a separate step takes much longer than downloading a heavier image. By doing this, it got 50% faster on my builds. |
@bahmutov Yeah. Although now is very obvious, I didn't realize The Slim option could still be a valid idea, but... I'm very curious how your images can achieve 830mb with so many added layers, browsers, and when you start from 300 mb+. This one starting from 45mb, no browsers, and a single layer added is going to 850mb. |
I have managed to achieve a whopping 3x smaller cypress base image. This is significant enough to validate for an additional officially supported image. I have only made a few changes to the current base image. The base image is Image size is often very important. Gitlab CI using shared runners doesn't quite cache effectively the image, especially if you are using your own built images (based on cypress base image you add additional libraries), also using DIND runners (docker in docker) which is quite popular, you don't get any caching of the images. I think a lot of bandwidth is wasted with docker images in these times. FROM node:12.18.3-slim
RUN apt-get update && \
apt-get install --no-install-recommends -y \
libgtk2.0-0 \
libgtk-3-0 \
libnotify-dev \
libgconf-2-4 \
libgbm-dev \
libnss3 \
libxss1 \
libasound2 \
libxtst6 \
xauth \
xvfb \
# clean up
&& rm -rf /var/lib/apt/lists/*
RUN npm install -g npm@latest && rm ./opt/yarn-v1.22.4/ -rf && rm /usr/local/bin/yarn
RUN npm --version
# a few environment variables to make NPM installs easier
# good colors for most applications
ENV TERM xterm
# avoid million NPM install messages
ENV npm_config_loglevel warn
# allow installing when the main user is root
ENV npm_config_unsafe_perm true
# Node libraries
RUN node -p process.versions I have change the base image to the slim node one. I have also removed the Chinese fonts. I strongly believe this should be an optimized image with the most basic things, so chinese fonts shouldn't be included here, especially since they were bloating the image size with Since this is such an easy change I think it could be easily added to the official ones. I have only marginally tested this image though. @bahmutov What do you say? Should I create a separate issue? |
With this simple change managed to reduce my cypress-dind image from 2.1gb to 1.3gb. |
This is a no brainer. What is the status of this PR? |
I still need to build one of these slim images and try to run the full set of tests using it |
@archfz You actually can go even further xauth is actually not needed as you can disable all Xvfb authentication. As our CI tests will run in k8s cluster I'm going even further I'm splitting Xvfb into dedicated image based on alpine with size 26.8MB |
Closing this as |
Motivation
I was trying to use Alpine (node:10-alpine ~25mb), but after spending some time fighting with Glibc I saw that you are already aware that it does not seem to be possible. This was discussed here on #110 and #206.
The second-best option for me is slim images. While node:10 (the base image for cypress/base) is based on the full Debian (~330mb), there are node images available that come from Debian slim (45mb).
Additional info
I am also including the Cypress binaries. Although it makes the image much heavier, the binary will have to be downloaded anyway.
In my opinion, this is essential for proper CI. Downloading cypress after the application code is transferred to the container (with npm/yarn) adds time to the build that is not needed. Even if the image gets much heavier with Cypress already in it, it saves time in the end.
When using CIs that are based on docker, it is essential to build a docker image also for cypress. By using this image with slim and cypress already installed, I was able to reduce my build times by 50% (from 10 minutes to 5)
Proposed image naming
cypress/slim:10-4.0.2
Sizing
Remaining work