Bitbucket Pipeline npm install fails with "npm ERR! fatal: unable to access" - node.js

I'm trying to run test cases in my node app using Bitbucket pipeline as follows.
image: channagayan/node_test:latest
pipelines:
default:
- step:
caches:
- node
script: # Modify the commands below to build your repository.
- cd NodeApi && pwd && npm install
- npm test
But it fails giving following error
+ cd NodeApi && pwd && npm install
/opt/atlassian/pipelines/agent/build/NodeApi
npm ERR! Error while executing:
npm ERR! /usr/bin/git ls-remote -h -t https://git#github.com/peterbraden/node-opencv.git
npm ERR!
npm ERR! fatal: unable to access 'https://git#github.com/peterbraden/node-opencv.git/': Problem with the SSL CA cert (path? access rights?)
npm ERR!
npm ERR! exited with error code: 128
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2018-05-01T09_15_55_789Z-debug.log
My Dockerfile is as follows,
FROM ubuntu:16.04
RUN apt-get update
RUN apt-get install -y --no-install-recommends \
build-essential \
cmake \
python-software-properties \
pkg-config \
wget \
&& rm -rf /var/lib/apt/lists/*
#node installation goes here....
RUN apt-get update && apt-get install -y git
#opencv installation goes here....
ENV LD_LIBRARY_PATH /usr/local/lib
WORKDIR /usr/src/app
EXPOSE 3001
It seems like Bitbucket is not accessing the internet from the docker container. Appreciate any help to resolve this.

Related

Node.js service Timeout issues

The Node.js API service hosted on AWS times out at intervals and crashes the server. When I checked Cloudwatch logs, I saw this error come up often.
npm ERR! path /app
npm ERR! command failed
npm ERR! signal SIGTERM
npm ERR! command sh -c -- npm run build && node dist/server.js
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2022-11-11T11_54_06_397Z-debug-0.log
Here's my docker file
#!/bin/sh
FROM node:16-bullseye-slim
RUN apt-get update; \
apt-get install -y python3; \
apt-get install -y python2 make; \
apt-get install -y g++; \
ln -s /usr/bin/python2.7 /usr/bin/python;
ARG app_env
ARG DOPPLER_TOKEN
ARG DOPPLER_PROJECT
ARG DOPPLER_CONFIG
ENV NODE_ENV=${app_env}
ENV DOPPLER_TOKEN=${DOPPLER_TOKEN}
ENV DOPPLER_PROJECT=${DOPPLER_PROJECT}
ENV DOPPLER_CONFIG=${DOPPLER_CONFIG}
WORKDIR /app
COPY package*.json ./
RUN npm install
RUN npm ci --only=production
COPY . .
CMD ["npm", "run", "start:server"]
EXPOSE 3000
My package.json file start script
"start:server": "npm run build && node dist/server.js"
I'm using Node version: v16.13.2
Npm version: 8.19.0
Not sure the cause of this issue.

npm install global in Dockerfile

Trying to install resume-cli through docker but getting some permission errors on installing resume-cli.
Dockerfile:
FROM python:3.7-slim-buster
RUN apt-get update
RUN apt-get install -y curl
SHELL ["/bin/bash", "--login", "-c"]
RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
RUN nvm install 15.13.0
RUN npm install -g resume-cli --unsafe-perm=true --allow-root
RUN npm install -g jsonresume-theme-paper
and i run: docker build -t containernpm .
where I get Error on RUN npm install -g resume-cli --unsafe-perm=true --allow-root:
npm ERR! code 127
npm ERR! path /root/.nvm/versions/node/v15.13.0/lib/node_modules/resume-cli/node_modules/puppeteer
npm ERR! command failed
npm ERR! command sh -c node install.js
npm ERR! sh: 1: node: Permission denied
btw next line RUN npm install -g jsonresume-theme-paper (with -g) runs normally without permission error.
Any idea how to overpass that without removing -g on RUN npm install -g resume-cli --unsafe-perm=true --allow-root
? (by removing -g runs without error)
I can't say I know why the permissions errors are happening, but here is a Dockerfile that works.
FROM node:15.13.0-buster-slim
RUN npm install -g resume-cli
ENTRYPOINT ["resume"]
There is a related question (sh: 1: node: Permission denied) but the top-voted answer there does not work for me.

NodeJS installing on Docker

I am trying to run my app on the Docker. One of the library I am using is https://www.npmjs.com/package/odbc.
In order to install that lib I need to meet the requirements described in the odbc readme:
unixODBC binaries and development libraries for module compilation
on Ubuntu/Debian sudo apt-get install unixodbc unixodbc-dev
on RedHat/CentOS sudo yum install unixODBC unixODBC-devel
odbc drivers for target database
properly configured odbc.ini and odbcinst.ini.
As per Microsoft doc in order to install ODBC Driver 13 for SQL Server https://learn.microsoft.com/en-us/sql/connect/odbc/linux-mac/installing-the-microsoft-odbc-driver-for-sql-server?view=sql-server-2017#ubuntu-1604-1
I manage to install all the stuff locally on my Mac and successfully connect with the SQL Server on Azure but still have some issues with installing them on the Docker and then run on VSTS.
My Dockerfile:
FROM ubuntu:16.04
USER root
RUN apt-get update
RUN apt-get install --yes curl
RUN curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
RUN apt-get install --yes nodejs
RUN apt-get install --yes build-essential
RUN apt-get install -y npm
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN apt-get install -y build-essential
RUN apt-get install -y make
RUN apt-get install apt-transport-https
RUN apt-get update && ACCEPT_EULA=Y apt-get install -y msodbcsql unixodbc-dev
ADD . /var/www/app
WORKDIR /var/www/app
RUN npm install && \
npm cache clean --force
RUN npm run build
EXPOSE 3000:80
CMD ["npm", "start"]
But so far have an issue with installing NodeJS in line with
RUN curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
error: /bin/sh: 1: sudo: not found
I was trying to install only the driver and for installing NodeJs just use some existing Docker images:
FROM ubuntu:16.04
USER root
RUN apt-get update
RUN apt-get install --yes curl
RUN curl https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
RUN curl https://packages.microsoft.com/config/ubuntu/16.04/prod.list > /etc/apt/sources.list.d/mssql-release.list
RUN apt-get install -y build-essential
RUN apt-get install -y make
RUN apt-get install apt-transport-https
RUN apt-get update && ACCEPT_EULA=Y apt-get install -y msodbcsql unixodbc-dev
FROM node:9-alpine
ADD . /var/www/app
WORKDIR /var/www/app
RUN npm install && \
npm cache clean --force
RUN npm run build
EXPOSE 3000:80
But that approach throws an error:
gyp ERR! configure error
gyp ERR! stack Error: Can't find Python executable "python", you can set the PYTHON env variable.
gyp ERR! stack at PythonFinder.failNoPython (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:483:19)
gyp ERR! stack at PythonFinder.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:397:16)
gyp ERR! stack at F (/usr/local/lib/node_modules/npm/node_modules/which/which.js:68:16)
gyp ERR! stack at E (/usr/local/lib/node_modules/npm/node_modules/which/which.js:80:29)
gyp ERR! stack at /usr/local/lib/node_modules/npm/node_modules/which/which.js:89:16
gyp ERR! stack at /usr/local/lib/node_modules/npm/node_modules/which/node_modules/isexe/index.js:42:5
gyp ERR! stack at /usr/local/lib/node_modules/npm/node_modules/which/node_modules/isexe/mode.js:8:5
gyp ERR! stack at FSReqWrap.oncomplete (fs.js:170:21)
gyp ERR! System Linux 4.9.125-linuxkit
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "build"
gyp ERR! cwd /var/www/app/node_modules/odbc
gyp ERR! node -v v9.11.2
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents#1.2.7 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents#1.2.7: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! odbc#1.4.5 install: `node-gyp configure build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the odbc#1.4.5 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2019-03-08T20_51_17_496Z-debug.log
You are working off the ubuntu:16.04 image, and essentially doing a lot of footwork that the NodeJS guys have already done.
I would go for the image node:10-stretch-slim if I was you. And then install the drivers that you need with apt-get (if available, otherwise script the download and install in your Dockerfile).
The sudo command is not typically installed on docker images, because the user is root by default in the container sessions. If you see any errors concerning sudo, you can generally just remove sudo from the command line that is causing the issue.
Possible solution
Updating my answer here, with a possible solution for you.
This solution will put your application in a node 10 image, based on debian stretch 9. It will get the database drivers for you, from the debian 9 microsoft repository, and install all the packages that I see you are requiring from your question.
I have also added an ENTRYPOINT and CMD in the bottom of the script. But those lines are guesswork, since your question states nothing about how you actually start your application. (If you add that, then I will update my answer).
Note. Notice that I am passing --host 0.0.0.0 to the npm run start command. This is to avoid binding the live server to localhost, which will make in inaccessible from outside the container. Unless you start the container with --network="host".
You may have another means of starting your application that is more "production grade" than the live development server. If so, just replace the lines in the bottom of the Dockerfile, or ask me on this answer.
Dockerfile
# from debian stretch 9.8, node 10
FROM node:10-stretch-slim
# get apt-transport-https, etc., so that we can install by https protocol
RUN apt-get update \
&& apt-get install -y \
apt-transport-https \
build-essential \
make
# add and accept the microsoft signature
RUN curl -q https://packages.microsoft.com/keys/microsoft.asc | apt-key add -
# retrieve the microsoft packagelist for debian 9
RUN curl -q https://packages.microsoft.com/config/debian/9/prod.list > /etc/apt/sources.list.d/mssql-release.list
# install the ms odbc sql driver and unixodbc header stuff
RUN apt-get update \
&& ACCEPT_EULA=Y apt-get install -y \
msodbcsql17 \
unixodbc-dev \
&& rm -rf /var/lib/apt/lists
# expose port 80 in containers of this image
EXPOSE 80
# copy working directory into the image and set as pwd
ADD . /var/www/app
WORKDIR /var/www/app
# install dependencies for the application
RUN npm install \
&& npm cache clean --force
# build the application
RUN npm run build
# i am just guessing how you want your app started here, npm?
ENTRYPOINT ["npm"]
# and then this, which makes "npm run start --host 0.0.0.0"
CMD ["run", "start", "--host", "0.0.0.0"]
Build the image with:
docker build -t mynodeapp:0.1 .
Run the application image with:
docker run -p 3000:80 --name mynodeapp mynodeapp:01
Finally visit: http://localhost:3000 to see it working.

Strange Git Error on Docker NPM Install

I had a working Dockerfile until literally a day ago when it just seemed to break. I didn't make any changes to my dependencies - but I am getting the following error:
[91mnpm ERR! code ENOGIT
[0m
[91mnpm ERR! No git binary found in $PATH
npm ERR!
npm[0m
[91m ERR! Failed using git.
npm ERR! Please check if you have git installed and in your PATH.
[0m
[91m
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2017-09-28T21_12_50_050Z-debug.log
[0m
Removing intermediate container be9d5bfe5521
The command '/bin/sh -c npm install' returned a non-zero code: 1
This is super strange because this wasn't happening before. I'm also attaching my Dockerfile. The things I've tried so far are adding git (third line), and also trying to export the path. Nothing seems to be working.
FROM ubuntu:latest
RUN apt-get update
RUN apt-get install -y git
FROM node:alpine
RUN npm install sails -g
#RUN npm install git -g
#RUN export PATH="$HOME/usr/bin/git:$PATH"
RUN mkdir -p /service/app
WORKDIR /service/app
COPY package.json /service/app
RUN npm install
COPY . /service/app
EXPOSE 80
CMD NODE_ENV=production sails lift
One reason for this could be that you are using the slim version of node in your Dockerfile:
FROM node:8-slim
I presume this does not include git, because when I changed to the full version the error went away:
FROM node:8.11.2
Try the following:
RUN apk update && \
apk add --update git && \
apk add --update openssh
The git binary within the docker container becomes available at /usr/bin/git
I had the same issue. It was due to lack of git. Below is how it worked
FROM node:alpine
RUN apk add git
RUN npm install ...

Dockerhub automated build failing due to npm install bcrypt issue

I've got a Dockerfile that looks like so:
FROM ubuntu:14.04
MAINTAINER Firstname Lastname <email#myapp.com>
ENV NODE_ENV production
ENV PORT 3333
RUN apt-get update && apt-get install -y git nodejs npm htop
RUN mkdir /root/.ssh/ && \
touch /root/.ssh/known_hosts && \
ssh-keyscan github.com >> /root/.ssh/known_hosts
ADD .ssh/my-github-deploy-key /root/.ssh/my-github-deploy-key
ADD .ssh/config /root/.ssh/config
RUN chmod 600 /root/.ssh/my-github-deploy-key && \
chmod 600 /root/.ssh/config && \
chown -R root:root /root/.ssh
RUN mkdir /srv/MyAppName && \
cd /srv && \
git clone git#github.com:MyAccountName/MyAppName.git MyAppName && \
cd MyAppName && \
npm install
EXPOSE 3333
CMD ["nodejs","/srv/MyAppName/index.js"]
And I've got my Dockerhub repo wired up to my Github repo so that an Automated Build is triggered each time I push to my master branch.
But the build is failing, and it's likely due to the npm install bcrypt command. I get the following error in the build log:
gyp: Call to 'node -e "require('nan')"' returned exit status 127. while trying to load binding.gyp
Error: `gyp` failed with exit code: 1 at ChildProcess.onCpExit (/usr/share/node-gyp/lib/configure.js:431:16)
ERR! at ChildProcess.EventEmitter.emit (events.js:98:17)
ERR! stack at Process.ChildProcess._handle.onexit (child_process.js:797:12)
ERR! System Linux 3.14.27
ERR!command "nodejs" "/usr/bin/node-gyp" "rebuild"
ERR! cwd /srv/MyApp/node_modules/bcrypt
ERR! node -v v0.10.25
ERR! node-gyp -v v0.10.10
ERR! not ok
npm WARN This failure might be due to the use of legacy binary "node"
I'm not sure why this would be a legacy binary node issue since I'm installing the latest version.
How do I work around this?
Figured this out. It was a nodejs legacy issue. Needed to add the Debian nodejs-legacy symlink package like so:
RUN apt-get update && apt-get install -y git nodejs npm htop nodejs-legacy
And then the build ran without issue.

Resources