how to run gulp task from dockerfile - docker

I am trying to run gulp task from my Dockerfile. Here is my Dockerfile
#
# Node.js w/ Bower & Grunt Dockerfile
#
# https://github.com/digitallyseamless/docker-nodejs-bower-grunt
#
# Pull base image.
FROM library/node:4
MAINTAINER Digitally Seamless <docker#digitallyseamless.com>
# Install Bower & Grunt
RUN npm install -g bower grunt-cli && \
echo '{ "allow_root": true }' > /root/.bowerrc
RUN npm install gulp -y
RUN gulp ng-config --env development
# Define working directory.
WORKDIR /data
COPY . /data
# Define default command.
EXPOSE 7000
CMD ["bash"]
Please note in above Dockerfile I am trying to install gulp and run gulp task as follows:
RUN npm install gulp -y
RUN gulp ng-config --env development
where ng-config is my gulp task defined in gulpfile.js file.
when I try to build image with above mentioned Dockerfile content I get error like gulp: not found
I am not sure if gulp is not getting installed properly or why it is not recognizing the gulp command.
Can you guys please help?
EDIT:
If I try to install gulp globally, my build fails with following output.
Sending build context to Docker daemon 7.893MB
Step 1/9 : FROM library/node:4
---> 3fb5ca8fcd8e
Step 2/9 : MAINTAINER Digitally Seamless <docker#digitallyseamless.com>
---> Using cache
---> 242154cec3ce
Step 3/9 : RUN npm install -g bower grunt-cli && echo '{ "allow_root": true }' > /root/.bowerrc
---> Using cache
---> b73fc7831a4a
Step 4/9 : RUN npm install -g gulp -y
---> Using cache
---> b498e61bfb8e
Step 5/9 : RUN gulp ng-config --env development
---> Running in 38d2e7f208cc
[08:21:29] Local gulp not found in /
[08:21:29] Try running: npm install gulp
The command '/bin/sh -c gulp ng-config --env development' returned a non-zero code: 1

You have to install gulp globally AND locally:
RUN npm install -g gulp
RUN npm install gulp
See this post for a discussion about the reason.

Related

Install GitHub dependency using PNPM in Dockerfile

I'm using pnpm in Dockerfile I have one dependency which is installed from GitHub.
PNPM by default use yarn to install dependency from Git.
Problem with PNPM is it is not able to access the yarn, I think some kind of permission problem.
ERROR:
ERR_PNPM_PREPARE_PKG_FAILURE  Command failed with exit code 1: /usr/local/bin/yarn install
The command '/bin/sh -c pnpm install' returned a non-zero code: 1
Here is my Dockerfile
FROM node:alpine
RUN npm install -g pnpm
WORKDIR /app
COPY ["package.json", "pnpm-lock.yaml", "./"]
RUN pnpm install
COPY . .
RUN pnpm build
ENV PORT=8080
EXPOSE 80
CMD [ "node", "./build/index.js" ]
Update
This is repo that is used from GitHub. Baileys
Everything works perfect when I try to install packages without Dockerfile If I run pnpm install everything just works. But When I run the build command for Dockerfile it will create problem.
docker build -t name .
As you stated, pnpm uses yarn to install dependencies from Git. From your output, you can see that yarn failed. If you run inside Docker container yarn add https://github.com/adiwajshing/Baileys.git, it would output:
info No lockfile found.
[1/4] Resolving packages...
error Couldn't find the binary git
node:alpine image is missing git.
To resolve your problem, simply install git before pnpm install in Dockerfile:
FROM node:alpine
RUN apk add --no-cache git
RUN npm install -g pnpm
...

My destenation folder is empty when running yarn build:css inside docker image

Here is my Dockerfile
# syntax=docker/dockerfile:1
FROM ruby:3.0.3
RUN apt-get update -qq && apt-get install -y nodejs npm yarn postgresql-client
RUN curl --compressed -o- -L https://yarnpkg.com/install.sh | bash
RUN mkdir /myapp
WORKDIR /myapp
COPY Gemfile /myapp/Gemfile
COPY Gemfile.lock /myapp/Gemfile.lock
RUN bundle install
RUN rails assets:precompile
COPY . /myapp
RUN npm install -g yarn -y
RUN yarn install
RUN yarn build:css
RUN rails webpacker:install
RUN rails webpacker:clobber
RUN rails webpacker:compile
# Add a script to be executed every time the container starts.
COPY entrypoint.sh /usr/bin/
RUN chmod +x /usr/bin/entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
EXPOSE 3000
# Start the main process.
CMD ["rails", "server", "-b", "0.0.0.0"]
And on my package.json I have the following
"scripts": {
"build:css": "sass ./app/assets/stylesheets/application.bootstrap.scss ./app/assets/builds/application.css --no-source-map --load-path=node_modules"
}
When I run docker-compose build works fine but the command RUN yarn build:css has no efect, the builds folder is empty.
I recently ran into an issue similar to this and the source of the problem was in fact npm and yarn.
I was able to get my application up and running in a docker container.
A properly configured application using cssbundling-rails should not need to run the command
"scripts": { "build:css": "sass ./app/assets/stylesheets/application.bootstrap.scss ./app/assets/builds/application.css --no-source-map --load-path=node_modules" },
to get the application to generate the build/application.css
npm known issue
Check your npm version, there is an issue if you are not using npm 7.1+ that basically prevents yarn from setting things up correctly.
Run npm -v and if necessary, upgrade npm with npm install -g npm#latest
If you had to upgrade npm, you will then need to close out your terminal and launch a new one, verify that the npm version is greater than 7.1.
After upgrading, re run rails css:install:bootstrap
And everything should be configured correctly.
Bundle Watcher
From the documentation for cssbundling-rails
"You develop using this approach by running the bundler in watch mode in a terminal with yarn build:css --watch (and your Rails server in another, if you're not using something like puma-dev). You can also use ./bin/dev, which will start both the Rails server and the CSS build watcher (along with a JS build watcher, if you're also using jsbundling-rails)."
So, you can either run yarn build:css --watch from a separate terminal in your rails application or just use the ./bin/dev but either way should resolve the issue you are experience.

Docker build fails with "The command '/bin/sh -c yarn install' returned a non-zero code: 1"

I have a react project which is built inside docker with the next config:
FROM alpine:3.14 as build
RUN apk add --update nodejs npm
RUN npm install -g yarn
RUN yarn set version berry
RUN yarn set version latest
RUN npm config set unsafe-perm true
RUN apk add --no-cache autoconf automake g++ git libtool libpng-dev make nasm python3 py3-pip
ARG NODE_ENV
ARG APP_URL
ARG ENV_TYPE
ENV HOME=/home/app
ENV NODE_ENV=${NODE_ENV}
ENV ENV_TYPE=${ENV_TYPE}
ENV APP_URL=${APP_URL}
ENV API_URL=${APP_URL}
ENV CHAT_URL=${APP_URL}
COPY . $HOME
WORKDIR $HOME
RUN yarn cache clean
RUN yarn install
RUN yarn run build-stage-env-prod
FROM nginx:1.15.3-alpine as final
COPY --from=build /home/app/build /usr/share/nginx/html
COPY --from=build /home/app/lighthouse.html /usr/share/nginx/html/lighthouse.html
COPY --from=build /home/app/default.conf /etc/nginx/conf.d/default.conf
COPY --from=build /home/app/nginx.conf /etc/nginx/nginx.conf
When I run this on a local machine, everything looks fine, but when it's run by Jenkins it fails with the next error:
(the end of log)
➤ YN0000: Failed with errors in 20s 322ms
The command '/bin/sh -c yarn install' returned a non-zero code: 1
Build step 'Execute shell' marked build as failure
Finished: FAILURE
So, the error happens on the yarn install. How to debug it?
May the "The remote archive doesn't match the expected checksum" in on package be the source of the build fail?

Npm install specific version does not work in Dockerfile

I'm trying to install a specific version of npm package within the node:alpine image (latest tag), so this is what I specified in my Dockerfile:
Edit (this is the full Dockerfile):
FROM node:alpine as build-stage
ARG SONAR_VERSION=4.6.0.2311
RUN apk add --no-cache zip unzip
RUN wget -c https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-$SONAR_VERSION-linux.zip
RUN unzip -q sonar-scanner-cli-$SONAR_VERSION-linux.zip
RUN rm sonar-scanner-cli-$SONAR_VERSION-linux.zip
# Adding the $install_directory/bin directory to path
RUN cd sonar-scanner-$SONAR_VERSION-linux
RUN echo $PWD
RUN export PATH="$PATH:/$PWD/bin"
RUN npm i -g eslint#6.7.2
RUN npm i -g eslint-plugin-vue --save-dev
However when I run & execute the built image, the installed version of eslint is the latest instead of what I'd specified in the Dockerfile.
Result from npm list -g:
/ # npm list -g
/usr/local/lib
+-- eslint-plugin-vue#7.9.0
+-- eslint#7.25.0
`-- npm#7.11.2
If I run npm i -g eslint#6.7.2 within the container itself, the version from npm list -g will be exactly the one I specified.
What is the reason of this scenario?

gulp not running in Dockerfile: Local gulp not found in /

This is my Dockerfile:
RUN mkdir /mcvitty
COPY . /mcvitty
RUN cd /mcvitty &&\
npm install -g gulp#3.9.1 &&\
npm link gulp --force &&\
npm install jshint#2.9.5 &&\
npm install gulp-jshint#2.0.4 &&\
npm install gulp-sass#3.1.0 &&\
npm install gulp-concat#2.6.1 &&\
npm install gulp-uglify#3.0.0 &&\
npm install gulp-rename#1.2.2 &&\
npm install gulp-minify-css#1.2.4 &&\
npm install gulp-image-resize#0.13.0
RUN gulp
RUN gulp resize-images
Whenever I run my container I get the following error:
[08:35:34] Local gulp not found in /
[08:35:34] Try running: npm install gulp
The command '/bin/sh -c gulp' returned a non-zero code: 1
Adding
npm install gulp#3.9.1
to have a local gulp, as suggested by someone does not work either.
Any suggestion?
I have Gulp running in a container. The main differences are that I set a working directory:
RUN mkdir /mcvitty
WORKDIR /mcvitty
COPY . /mcvitty
I don't run npm link gulp, either.
If that doesn't work, remove the RUN gulp commands and add them to your docker run command, e.g.
docker run -it --rm --entrypoint '/bin/sh' myimage -c 'gulp && gulp images'
I fixed the problem by CD back into my dir before running gulp:
RUN cd /mcvitty && gulp

Resources