简体   繁体   中英

Yarn error while deploying application on the Google cloud

I have been trying to deploy this application( https://github.com/DivanteLtd/open-loyalty/ ) on Google cloud using Kubernetes. The instance used to deploy this application contains Debian v4.9 as its OS. And we installed Docker, GCloud, Kubernetes, and Kompose as the tools for deployment. I built two docker images for the frontend and backend and linked them to the docker-compose file. Now in front-end model, we used (node:5) image from docker hub in Dockerfile of the frontend. Given below is the docker file of frontend container.

FROM node:5

RUN apt-get update \
    && apt-get install -y ruby-full rubygems \
    && gem instal sass
RUN npm install -g gulp node-sass yarn
COPY . /var/www
WORKDIR /var/www
EXPOSE 3000

CMD npm rebuild node-sass && yarn install && gulp config --prod && gulp compile && gulp prod

I also tried using (node:6) and (node:7) as images but in error the node version remains v5.12.0 and npm version to be v3.8.6. I also tried node-yarn( https://hub.docker.com/r/yarnpkg/node-yarn/ ) package specifically made for this issue.

npm info it worked if it ends with ok
npm info using npm@3.8.6
npm info using node@v5.12.0
npm info readInstalled object
npm info ok
/bin/sh: 1: yarn: not found

A possible solution may be to change the image version of node in Dockerfile, but it remains same in error every time. But when I execute the same process on a local machine with (node:5), it works as expected.

Now for to run containers i am using "kompose up" which runs the docker-compose.yml file and deploys pods automatically. docker-compose.yml file is shown below.

backend:
  container_name: open-loyalty-backend
  image: gcr.io/open-loyalty/openloyalty_backend
  links:
    - elk
    - db
    - mail
  ports:
    - "8181:80"
  extra_hosts:
    - "web:127.0.0.1"
frontend:
  container_name: open-loyalty-frontend
  image: gcr.io/open-loyalty/openloyalty_frontend
  ports:
    - "8182:3000"
    - "8183:3001"
    - "8184:3002"
elk:
  container_name: open-loyalty-elk
  image: elasticsearch:2.2
db:
  container_name: open-loyalty-postgresql
  image: postgres
  environment:
    - POSTGRES_DB=openloyalty
    - POSTGRES_USER=openloyalty
    - POSTGRES_PASSWORD=openloyalty
mail:
  container_name: open-loyalty-mail
  image: mailhog/mailhog
  ports:
    - "8186:8025"

So, is there any possible solution with this error?

It's odd that it's not working, but the yarn install docs specifically say you shouldn't install via npm.

Note: Installation of Yarn via npm is generally not recommended. When installing Yarn with Node-based package managers, the package is not signed, and the only integrity check performed is a basic SHA1 hash, which is a security risk when installing system-wide apps.

For these reasons, it is highly recommended that you install Yarn through the installation method best suited to your operating system.

On Debian, the installation would go like this:

RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
RUN apt-get update && apt-get install yarn

If you are willing to run node:8.4 , I can attest this method works on that image.

Also, confirm that the global node modules directory is in your PATH. Otherwise it won't be accessible on the command line. npm root will tell you where this is.

One thing that might help is to use an ENTRYPOINT script that will install yarn at runtime, immediately before you need to use it.

ENTRYPOINT ["./entry.sh"]

If you don't care about using yarn, and you just want the project to work, then simply use npm instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM