slimtoolkit / slim

Slim(toolkit): Don't change anything in your container image and minify it by up to 30x (and for compiled languages even more) making it secure too! (free and open source)
Apache License 2.0
18.96k stars 706 forks source link

Xvfb issues after slim build #134

Open ChaikaBogdan opened 4 years ago

ChaikaBogdan commented 4 years ago

Greetings, i am trying to slim https://github.com/cypress-io/cypress-docker-images/tree/master/included/4.0.2 Using command (MAC): ./docker-slim build cypress/included:4.0.2 --http-probe=false
(I am also tried to use --from-dockerfile solution) But i am getting this error on container run:

Xvfb exited with a non zero exit code.
There was a problem spawning Xvfb.
This is likely a problem with your system, permissions, or installation of Xvfb.
Error: (EE) 
Fatal server error:
(EE) Could not create lock file in /tmp/.tX99-lock
Platform: linux (4.19.76-linuxkit)
Cypress Version: 4.0.2

Can you suggest how it can be fixed or debugged? 2.9GB->733mb is an impressive result, i am really interested in finding workaround here. The fat image and original image are 100% working.

kcq commented 4 years ago

@ChaikaBogdan thanks for sharing your docker-slim command and the image info! It'll help with the repro!

This specific failure appears to come from the xvfb package ( https://github.com/cypress-io/xvfb ). It's possible that the minified images includes /tmp/.tX99-lock already and it's causing this failure. Let me try to repro it to see if it's the case. There might be other problems too. This appears to be an advanced multi-process/app setup and it definitely needs a review.

Do you know much about the tool design and its internals? Curious about the main components and how they are supposed to interact...

ChaikaBogdan commented 4 years ago

@kcq Thanks for quick response! I not sure about internal work of Cypress...its almost 3gb of all-in test framework. I know it's coming with a lot of bundled stuff - test runners, reporters, browsers, which probably require some real frame buffer even for headless run. Also it bundled with Node12+ (but you can force use system one)

The fastest way to test image is:

mkdir dummy
cd dummy
npm init -y
npm install cypress --save-dev
npx cypress open //to generate dummy tests
docker run -it -v $PWD:/e2e -w /e2e cypress/included:4.0.2 --browser chrome

Container itself doesn't have any http access, you can run tests just from their repo or even copy them inside container:

FROM cypress/included:4.0.2
COPY cypress /e2e/cypress
COPY cypress.json /e2e
COPY package.json /e2e
WORKDIR /e2e

It's very handy in CI/CD, because you can just grab junit xml reports after run and pass them to Jenkins for example.

kcq commented 4 years ago

@ChaikaBogdan Thanks for the extra info! This is super helpful! I'll try to repo and share my findings soon.

One thing to note is that you should probably pass the same extra parameters you have in your docker run command when you run docker-slim: ./docker-slim build --http-probe=false --mount $(pwd):/e2e --workdir /e2e --cmd '--browser chrome' cypress/included:4.0.2

ChaikaBogdan commented 4 years ago

@kcq Thanks, error still same, but your arguments make more sense

kusumkappdirect commented 3 years ago

any update here? i am also gettting same issue.

ChaikaBogdan commented 3 years ago

So, I made a little spike about possible slimming of cypress/included

Its looks like, what docker-slim is too aggressively removing everything related to Node and Cypres from the target image. I was able to get to some "almost working" state with:

./docker-slim build --http-probe=false --include-shell --include-path /usr/bin --include-path /usr/local --include-path /root/.cache/Cypress --include-path /usr/lib --target cypress/included:6.6.0

But cypress verify still results in an error...

A similar issue was solved by https://github.com/iperdomo/cypress-docker-test#fixing-the-errors, but in my case I just getting different error

Anyway, right now image weighs 1.62 GB unpacked...which is already more than just take node:buster-slim and install Cypress on top with Chrome. https://github.com/ChaikaBogdan/cypress_slim

Screenshot 2021-03-07 at 02 06 55

I wonder if it is related to the global install of Cypress in the original image...but no idea for now how to solve the socket issue

chenzx commented 2 years ago

I'm using docker-slim to build an original docker image which uses nodejs & xvfb-run, it also reports:

...
cmd=build info=continue.after mode='timeout&exec' message='provide the expected input to allow the container inspector to continue its execution' 
cmd=build prompt='waiting for the target container (30 seconds)'
cmd=build info=event message='done waiting for the target container' 
cmd=build info=continue.after mode='exec' shell='cd /renderserver && xvfb-run node index.js' 
docker-slim[build][exec]: output: xvfb-run: error: Xvfb failed to start
cmd=build info=continue.after mode='exec' exitcode='1'
...

The problem is: why can't i see the log output? In interactive mode there is.