Skip to content
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

cypress/factory with docker 4.36.0 error #1263

Closed
johnhok opened this issue Dec 5, 2024 · 12 comments
Closed

cypress/factory with docker 4.36.0 error #1263

johnhok opened this issue Dec 5, 2024 · 12 comments
Assignees
Labels

Comments

@johnhok
Copy link

johnhok commented Dec 5, 2024

I recently upgraded my docker desktop from 4.35.0 -> 4.36.0 and a build that was previously working using cypress/factory seems to be producing an error now.

#24 [codegen  1/21] ONBUILD RUN bash /opt/installScripts/node/install-node-version.sh 20.18.1
#24 0.114 bash: /opt/installScripts/node/install-node-version.sh: No such file or directory
#24 ERROR: process "/bin/sh -c bash /opt/installScripts/node/install-node-version.sh ${APPLIED_FACTORY_DEFAULT_NODE_VERSION}" did not complete successfully: exit code: 127

This seems to happen in multi staged builds.

An abridged version of the dockerfile where it fails on the codgen stage:

# syntax = docker/dockerfile:1

ARG CHROME_VERSION='131.0.6778.69-1'
ARG YARN_VERSION='1.22.19'
ARG NODE_VERSION='20.18.1'
ARG CYPRESS_VERSION='13.15.2'

# install
# --------------------------
FROM cypress/factory:5.1.1 AS install

WORKDIR /usr/src/app

COPY package.json yarn.lock ./

RUN yarn install --frozen-lockfile --ignore-optional

ENTRYPOINT [ "yarn" ]

# codegen
# --------------------------
FROM install AS codegen

RUN ./codegen.sh
@MikeMcC399
Copy link
Collaborator

@johnhok

The file which your error log shows is missing:

/opt/installScripts/node/install-node-version.sh

is included in cypress/factory Cypress Docker images and it runs with an ONBUILD command.
The final ONBUILD in the factory.Dockerfile then deletes the directory /opt/installScripts.

# Global Cleanup
ONBUILD RUN apt-get purge -y --auto-remove \
curl \
bzip2 \
gnupg \
dirmngr\
&& rm -rf /usr/share/doc \
&& rm -rf /var/lib/apt/lists/* \
# Remove cypress install scripts
&& rm -rf /opt/installScripts

The build log only shows the error, not the rest of the steps, so it's difficult to understand the cause, however it looks like the ONBUILD might be getting called more than once in your build workflow.

Which operating system are you running Docker Desktop 4.36.0 under?

Did you try re-installing your previous version 4.35.0 (or 4.35.1)? See https://docs.docker.com/desktop/release-notes/ for downloads.

I don't see anything in the release notes that I would expect to cause your issue due to upgrading.

@crlsgms
Copy link

crlsgms commented Dec 6, 2024

I'm having the same issue, running a build with factory:4.2.2, if I build the first image FROM cypres/factory AS whatever it runs to the end, but if I use whatever new image FROM whatever AS new_image, it will break as the script is not there anymore.

I'v tried to copy it elsewhere and copy it back on the first stages but I don't know how to have it there before the image starts, as the first step is to call the install script.

some references:

  • first stage
[+] Building 0.7s (16/16) FINISHED
 => [internal] load .dockerignore                                                                                                                                                        0.0s
 => => transferring context: 2B                                                                                                                                                          0.0s
 => [internal] load build definition from Dockerfile                                                                                                                                     0.0s
 => => transferring dockerfile: 4.99kB                                                                                                                                                   0.0s
 => resolve image config for harbor.local:30003/bmw-proxy/docker/dockerfile:latest                                                                                                       0.0s
 => CACHED docker-image://harbor.local:30003/bmw-proxy/docker/dockerfile:latest                                                                                                          0.0s
 => [internal] load build definition from Dockerfile                                                                                                                                     0.0s
 => [internal] load metadata for harbor.local:30003/bmw-proxy/cypress/factory:4.2.2                                                                                                      0.0s
 => [internal] load .dockerignore                                                                                                                                                        0.0s
 => [node_upstream_test 1/1] FROM harbor.local:30003/bmw-proxy/cypress/factory:4.2.2                                                                                                     0.0s
 => CACHED [node_upstream_test  2/16] ONBUILD RUN bash /opt/installScripts/node/install-node-version.sh 20.17.0                                                                          0.0s
 => CACHED [node_upstream_test  3/16] ONBUILD RUN node /opt/installScripts/yarn/install-yarn-version.js ${YARN_VERSION}                                                                  0.0s
 => CACHED [node_upstream_test  4/16] ONBUILD RUN node /opt/installScripts/chrome/install-chrome-version.js ${CHROME_VERSION}                                                            0.0s
 => CACHED [node_upstream_test  5/16] ONBUILD RUN node /opt/installScripts/edge/install-edge-version.js ${EDGE_VERSION}                                                                  0.0s
 => CACHED [node_upstream_test  6/16] ONBUILD RUN node /opt/installScripts/firefox/install-firefox-version.js ${FIREFOX_VERSION}                                                         0.0s
 => CACHED [node_upstream_test  7/16] ONBUILD RUN node /opt/installScripts/cypress/install-cypress-version.js ${CYPRESS_VERSION}                                                         0.0s
 => CACHED [node_upstream_test  8/16] ONBUILD RUN apt-get purge -y --auto-remove     curl     bzip2     gnupg     dirmngr  && rm -rf /usr/share/doc   && rm -rf /var/lib/apt/lists/*     0.0s
 => exporting to image                                                                                                                                                                   0.0s
 => => exporting layers                                                                                                                                                                  0.0s
 => => writing image sha256:afb7054db17897aaf080d984fcafce32211ce6795eac96e4c31b36de41c31a8f                                                                                             0.0s
 => => naming to docker.io/library/node-cypress-dev'

next stage image:

 => [internal] load build definition from Dockerfile                                                                                                                                     0.0s
 => => transferring dockerfile: 4.99kB                                                                                                                                                   0.0s
 => [internal] load .dockerignore                                                                                                                                                        0.0s
 => => transferring context: 2B                                                                                                                                                          0.0s
 => resolve image config for harbor.local:30003/bmw-proxy/docker/dockerfile:latest                                                                                                       0.0s
 => CACHED docker-image://harbor.local:30003/bmw-proxy/docker/dockerfile:latest                                                                                                          0.0s
 => [internal] load build definition from Dockerfile                                                                                                                                     0.0s
 => [internal] load metadata for harbor.local:30003/bmw-proxy/cypress/factory:4.2.2                                                                                                      0.0s
 => [internal] load .dockerignore                                                                                                                                                        0.0s
 => [internal] load build context                                                                                                                                                        0.1s
 => => transferring context: 40.99kB                                                                                                                                                     0.0s
 => CACHED [node_upstream_test 1/1] FROM harbor.local:30003/bmw-proxy/cypress/factory:4.2.2                                                                                              0.0s
 => [node_upstream_test  2/16] ONBUILD RUN bash /opt/installScripts/node/install-node-version.sh 20.17.0                                                                                26.3s
 => [node_upstream_test  3/16] ONBUILD RUN node /opt/installScripts/yarn/install-yarn-version.js ${YARN_VERSION}                                                                         0.9s
 => [node_upstream_test  4/16] ONBUILD RUN node /opt/installScripts/chrome/install-chrome-version.js ${CHROME_VERSION}                                                                   0.9s
 => [node_upstream_test  5/16] ONBUILD RUN node /opt/installScripts/edge/install-edge-version.js ${EDGE_VERSION}                                                                         1.0s
 => [node_upstream_test  6/16] ONBUILD RUN node /opt/installScripts/firefox/install-firefox-version.js ${FIREFOX_VERSION}                                                                0.8s
 => [node_upstream_test  7/16] ONBUILD RUN node /opt/installScripts/cypress/install-cypress-version.js ${CYPRESS_VERSION}                                                                0.8s
 => [node_upstream_test  8/16] ONBUILD RUN apt-get purge -y --auto-remove     curl     bzip2     gnupg     dirmngr  && rm -rf /usr/share/doc   && rm -rf /var/lib/apt/lists/*   && rm -  3.6s
 => ERROR [base_node_app_test  1/19] ONBUILD RUN bash /opt/installScripts/node/install-node-version.sh 20.17.0                                                                           0.8s
------
 > [base_node_app_test  1/19] ONBUILD RUN bash /opt/installScripts/node/install-node-version.sh 20.17.0:
#0 0.641 bash: /opt/installScripts/node/install-node-version.sh: No such file or directory
------
Dockerfile:51
--------------------
  49 |
  50 |     # Test environment derived from Cypress
  51 | >>> FROM node_upstream_test AS base_node_app_test
  52 |     # ARG RELATIVE_PATH_TO_BASE_IMAGE_DIRECTORY=./docker/base-bmw-angular-application/
  53 |
--------------------
ERROR: failed to solve: process "/bin/sh -c bash /opt/installScripts/node/install-node-version.sh ${APPLIED_FACTORY_DEFAULT_NODE_VERSION}" did not complete successfully: exit code: 127`

and the steps I can fetch from the cypress image:

docker inspect harbor.local:30003/bmw-proxy/cypress/factory:4.2.2 | jq '.[0].Config.OnBuild'
[
  "ARG NODE_VERSION",
  "ENV APPLIED_FACTORY_DEFAULT_NODE_VERSION=${NODE_VERSION:-${CYPRESS_FACTORY_DEFAULT_NODE_VERSION}}",
  "RUN bash /opt/installScripts/node/install-node-version.sh ${APPLIED_FACTORY_DEFAULT_NODE_VERSION}",
  "ARG YARN_VERSION",
  "RUN node /opt/installScripts/yarn/install-yarn-version.js ${YARN_VERSION}",
  "ARG CHROME_VERSION",
  "RUN node /opt/installScripts/chrome/install-chrome-version.js ${CHROME_VERSION}",
  "ARG EDGE_VERSION",
  "RUN node /opt/installScripts/edge/install-edge-version.js ${EDGE_VERSION}",
  "ARG FIREFOX_VERSION",
  "RUN node /opt/installScripts/firefox/install-firefox-version.js ${FIREFOX_VERSION}",
  "ARG CYPRESS_VERSION",
  "ENV NODE_PATH=${CYPRESS_VERSION:+/usr/local/lib/node_modules}",
  "RUN node /opt/installScripts/cypress/install-cypress-version.js ${CYPRESS_VERSION}",
  "RUN apt-get purge -y --auto-remove     curl     bzip2     gnupg     dirmngr  && rm -rf /usr/share/doc   && rm -rf /var/lib/apt/lists/*   && rm -rf /opt/installScripts"
]

so the question is, is it possible to use cypress in multistage builds? I have tried many workarounds copying the file away, copying it back to the new image... but no success

@MikeMcC399
Copy link
Collaborator

@crlsgms

Thank you for adding your experience with cypress/factory and Docker multi-stage builds to this issue! This needs some further investigation.

@MikeMcC399
Copy link
Collaborator

@johnhok

I can reproduce the issue in a multi-stage build when the Dockerfile includes the following, as recommended on Custom Dockerfile syntax

# syntax = docker/dockerfile:1

Using Docker Desktop 4.36.0 on Ubuntu, if I omit the above line, or pin it to the earlier version 1.10.0, then the problem does not occur:

# syntax = docker/dockerfile:1.10.0

You may like to see if this could be a temporary workaround.

@crlsgms
I'm not sure if this fits your situation as I couldn't see if you were using this directive or what environment you are working in (versions, operating system, architecture, etc.).

@crlsgms
Copy link

crlsgms commented Dec 6, 2024

well, for now I have tested 1.11, 1.4 , latest and this untagged one but may be some delay from harbor

image

one thing I'm trying here is to copy the script before the ONBUILD chain finishes, and get it from a stage instead of dumping, copying and etc.. but until now now working, still need to test

also the node-alpine versions do not come with bash, as this script do not work properly with only sh I had to add an apk add bash

@MikeMcC399
Copy link
Collaborator

@crlsgms

I'm not quite sure, but I think you were saying that the workaround of pinning to an earlier version is working for you.

also the node-alpine versions do not come with bash, as this script do not work properly with only sh I had to add an apk add bash

Cypress isn't involved with node:alpine. (See #110) due to incompatibility.

@johnhok
Copy link
Author

johnhok commented Dec 6, 2024

@johnhok

The file which your error log shows is missing:

/opt/installScripts/node/install-node-version.sh

is included in cypress/factory Cypress Docker images and it runs with an ONBUILD command. The final ONBUILD in the factory.Dockerfile then deletes the directory /opt/installScripts.

# Global Cleanup
ONBUILD RUN apt-get purge -y --auto-remove \
curl \
bzip2 \
gnupg \
dirmngr\
&& rm -rf /usr/share/doc \
&& rm -rf /var/lib/apt/lists/* \
# Remove cypress install scripts
&& rm -rf /opt/installScripts

The build log only shows the error, not the rest of the steps, so it's difficult to understand the cause, however it looks like the ONBUILD might be getting called more than once in your build workflow.

Which operating system are you running Docker Desktop 4.36.0 under?

Did you try re-installing your previous version 4.35.0 (or 4.35.1)? See https://docs.docker.com/desktop/release-notes/ for downloads.

I don't see anything in the release notes that I would expect to cause your issue due to upgrading.

The full log:

❯ docker build --target="update-cache2" . > log2.txt
[+] Building 1.0s (18/25)                                                                                                                                                                                                                 docker:desktop-linux
 => [internal] load build definition from Dockerfile                                                                                                                                                                                                      0.0s
 => => transferring dockerfile: 631B                                                                                                                                                                                                                      0.0s
 => resolve image config for docker-image://docker.io/docker/dockerfile:1                                                                                                                                                                                 0.4s
 => CACHED docker-image://docker.io/docker/dockerfile:1@sha256:db1ff77fb637a5955317c7a3a62540196396d565f3dd5742e76dddbb6d75c4c5                                                                                                                           0.0s
 => [internal] load build definition from Dockerfile                                                                                                                                                                                                      0.0s
 => [internal] load metadata for docker.io/cypress/factory:5.1.1                                                                                                                                                                                          0.3s
 => [internal] load .dockerignore                                                                                                                                                                                                                         0.0s
 => => transferring context: 66B                                                                                                                                                                                                                          0.0s
 => [install 1/3] FROM docker.io/cypress/factory:5.1.1@sha256:ece75e68a6ef4b92c296b1bee68c4c7fcec7e30a2b0aff1394c7b6092aabd450                                                                                                                            0.0s
 => [internal] load build context                                                                                                                                                                                                                         0.0s
 => => transferring context: 207B                                                                                                                                                                                                                         0.0s
 => CACHED [install  2/18] ONBUILD RUN bash /opt/installScripts/node/install-node-version.sh 20.18.1                                                                                                                                                      0.0s
 => CACHED [install  3/18] ONBUILD RUN node /opt/installScripts/yarn/install-yarn-version.js 1.22.19                                                                                                                                                      0.0s
 => CACHED [install  4/18] ONBUILD RUN node /opt/installScripts/chrome/install-chrome-version.js 131.0.6778.69-1                                                                                                                                          0.0s
 => CACHED [install  5/18] ONBUILD RUN node /opt/installScripts/edge/install-edge-version.js ${EDGE_VERSION}                                                                                                                                              0.0s
 => CACHED [install  6/18] ONBUILD RUN node /opt/installScripts/firefox/install-firefox-version.js ${FIREFOX_VERSION}                                                                                                                                     0.0s
 => CACHED [install  7/18] ONBUILD RUN node /opt/installScripts/cypress/install-cypress-version.js 13.15.2                                                                                                                                                0.0s
 => CACHED [install  8/18] ONBUILD RUN apt-get purge -y --auto-remove     curl     bzip2     gnupg     dirmngr  && rm -rf /usr/share/doc   && rm -rf /var/lib/apt/lists/*   && rm -rf /opt/installScripts                                                 0.0s
 => CACHED [install  9/18] WORKDIR /usr/src/app                                                                                                                                                                                                           0.0s
 => CACHED [install 10/18] COPY reg-suit ./reg-suit                                                                                                                                                                                                       0.0s
 => ERROR [update-cache2  1/16] ONBUILD RUN bash /opt/installScripts/node/install-node-version.sh 20.18.1                                                                                                                                                 0.1s
------
 > [update-cache2  1/16] ONBUILD RUN bash /opt/installScripts/node/install-node-version.sh 20.18.1:
0.096 bash: /opt/installScripts/node/install-node-version.sh: No such file or directory
------
Dockerfile:21
--------------------
  19 |     # cache node modules if not already
  20 |     # --------------------------
  21 | >>> FROM install AS update-cache2
  22 |
  23 |     COPY package.json yarn.lock regconfig.json restore-cache.sh ./
--------------------
ERROR: failed to solve: process "/bin/sh -c bash /opt/installScripts/node/install-node-version.sh ${APPLIED_FACTORY_DEFAULT_NODE_VERSION}" did not complete successfully: exit code: 127

I've encountered the issue in both OSX and with Ubuntu in CI.

I tried your suggestion of pinning the dockerfile syntax and this seems to have worked.

# syntax = docker/dockerfile:1.10.0

@MikeMcC399
Copy link
Collaborator

@johnhok

I tried your suggestion of pinning the dockerfile syntax and this seems to have worked.

That's great! Thanks for confirming.

I did some more research and found that there have been several changes in this area lately on the Docker side.

dockerfile/1.11.0

dockerfile/1.11.1

It looks to me like these changes could have introduced a bug in how ONBUILD is handled for multi-stage builds using cypress/factory. My understanding is the ONBUILD should be used in children, but not grandchildren. This may need an issue opening in the https://github.com/moby/buildkit repo to clarify, or get a fix produced.

@MikeMcC399
Copy link
Collaborator

This issue is reproduced and described in

https://github.com/MikeMcC399/cy-docker-multistage

I plan to report this as a Docker regression.

@crlsgms
Copy link

crlsgms commented Dec 6, 2024

# syntax = docker/dockerfile:1.10.0

I confirm that setting the #syntax fixed to :1.10.0 on Dockerfiles fixed the issue and I can again build child images, thanks @johnhok

@MikeMcC399
Copy link
Collaborator

@MikeMcC399
Copy link
Collaborator

This issue is reproducible in multi-stage Docker builds in a parent-child-grandchild sequence without using a cypress/factory Docker image, so the inference is that this is not a Cypress Docker image bug and can't be fixed in this repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants