`yarn` not found in `node:alpine`
I'm using the node:alpine image in a gitlab-ci build.
Since a few minutes ago I get the following error in gitlab-ci:
$ yarn config set cache-folder .yarn
/bin/sh: eval: line 50: yarn: not found
ERROR: Job failed: exit code 127
My .gitlab-ci.yaml:
build:
image: node:alpine
stage: build
script:
- yarn config set cache-folder .yarn
- yarn
- yarn build
I'm happy we were not the only one experiencing this issue 😅 , reverting to a earlier tag was our solution but kudos to the community on this form for providing suggestions.
I'm happy we were not the only one experiencing this issue 😅 , reverting to a earlier tag was our solution but kudos to the community on this form for providing suggestions.
I think the whole world ended up here when they realized their builds were not passing lol!
The fix seems to have made its way through the system. I've just had a GitLab CI build pass using the node:alpine image.
@SimenB @LaurentGoderre - PR with changes to prevent this sort of thing happening again - https://github.com/nodejs/docker-node/pull/658
I wrote up a blog post to explain how/why this happened, why it's not completely unexpected and can happen again, and what you can do to protect against it in future: https://renovateapp.com/blog/docker-mutable-tags
In summary:
- Docker tags can change at any time. They are mutable and that is by design, not fault
- Even a Docker tag that looks like semver (e.g.
node:8.10.0) still has the properties of a tag and can be changed/updated at any time, like happened here - There are valid reasons for the image a tag points to to be changed (such as refactoring the Dockerfile or a security patch to the base), so it's not a good idea to insist that a tag that looks like a semver should never be changed
- The only way to ensure your build is reproducible/consistent is to use Docker digests as the identifier instead of the tag
- You can conveniently still include a Docker tag in the digest for human readability, e.g.
node:8.10.0-alpine@sha256:a55d3e87802b2a8464b3bfc1f8c3c409f89e9b70a31f1dccce70bd146501f1a0 - If you were using digests for your
nodebase images instead of tags, you not only wouldn't have "accidentally" upgraded to the new broken image in the first place, and even if you had updated on purpose then you could have immediately rolled back the digest in your Dockerfile once you discovered the break, instead of waiting hours - Beyond that, these digests are a little "developer-unfriendly" to update by hand, but open source tools to automate it exist
I believe there is a much simpler solution: if you use Docker for your work, host your own registry and update the images when you need to.
@cecton no build time Internet is good for private projects, but not open source development. Also, it does not solve the problems with not having a repeatable build when debugging.
That should read: “no build time Internet dependencies”
Yes actually, you made a good point... I was more thinking about professional projects.
Fixed by adding
RUN apk add --no-cache --virtual .build-deps \
ca-certificates \
wget \
tar && \
cd /usr/local/bin && \
wget https://yarnpkg.com/latest.tar.gz && \
tar zvxf latest.tar.gz && \
ln -s /usr/local/bin/dist/bin/yarn.js /usr/local/bin/yarn.js && \
apk del .build-deps
from https://hub.docker.com/r/jfyne/node-alpine-yarn/dockerfile to my Dockerfile.
For me the issue was in using singlequotes in Dockerfile CMD command
CMD ['yarn', 'start'] // Wrong
CMD ["yarn", "start"] // Correct