Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Docker build fails in the pipeline with npm error while builds local builds successfully

r_abbasi December 2, 2021

My docker file which is building successfully local, is as following 

FROM node:14.1-alpine AS builder

COPY . /opt/web

WORKDIR /opt/web

RUN npm install

RUN npx browserslist@latest --update-db

ENV PATH=“/opt/web/node_modules/.bin:$PATH

RUN npm run build

FROM nginx:1.17-alpine

RUN apk --no-cache add curl

COPY --from=builder /opt/web/build /usr/share/nginx/html

RUN chgrp -R 0 /var/* && chmod -R g=u /var/*

CMD [“nginx”, “-g”, “daemon off;“]
When I run the same docker file for the build throught he pipeline, I am getting following error. 
error.png
My bitbucket pipeline yml file is as following, I did try both atlassian/default-image:3 and node image, however getting same error. 

# Template docker-push

# This template allows you to build and push your docker image to a Docker Hub account.

# The workflow allows running tests, code linting and security scans on feature branches (as well as master).

# The docker image will be validated and pushed to the docker registry after the code is merged to master.

# Prerequisites: $DOCKERHUB_USERNAME, $DOCKERHUB_PASSWORD setup as deployment variables

# image: atlassian/default-image:3

image: node:14.1-alpine

pipelines:

branches:

feature/devops:

- step:

name: Build and Test

script:

- IMAGE_NAME=$BITBUCKET_REPO_SLUG

- docker build . --file Dockerfile --tag ${IMAGE_NAME}

- docker save ${IMAGE_NAME} --output “${IMAGE_NAME}.tar”

services:

- docker

caches:

- docker

artifacts:

- “*.tar”

2 answers

1 accepted

1 vote
Answer accepted
r_abbasi December 7, 2021

The final solution, which worked for me was to unset the CI before running the npm run build, along with using the npm in the bitbucket pipeline, instead of the docker file. 

Here I am pasting my updated pipeline, for the successfull build 

 

image: atlassian/default-image:3

pipelines:

branches:

feature/devops:

- step:

name: Build and Test

script:

- npm cache clean --force

- rm -rf node_modules

- npm install

- unset CI

- npm run build

- IMAGE_NAME=${BITBUCKET_REPO_SLUG}

- docker build . --file Dockerfile --tag ${IMAGE_NAME}

- docker save ${IMAGE_NAME} --output "${IMAGE_NAME}.tar"

services:

- docker

caches:

- docker

artifacts:

- "*.tar"
Ahmad Shah December 7, 2021

Thanks @r_abbasi  it works

Igor Stoyanov
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 8, 2021

@r_abbasi hi. Do you have warnings in your local build?  This was pointed here: https://stackoverflow.com/a/58701621

Regards, Igor.

Like r_abbasi likes this
r_abbasi December 8, 2021

@Igor Stoyanov  Yeh, I had warnings in the build.  Thanks for the support. 

0 votes
Igor Stoyanov
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 3, 2021

@r_abbasi hi. Thanks for your question. Try to follow Build and push a Docker image guide.

Also the suggestion is not to use node:14.1-alpine, because alpine is minimalistic, instead use the image node:14.1

Regards, Igor

r_abbasi December 7, 2021

I am getting the same error for the following very simple pipeline

 

image: node:14.17.6

pipelines:

branches:

feature/devops:

- step:

name: Build and Test

script:

- npm install

- npm run build
Igor Stoyanov
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 7, 2021
Igor Stoyanov
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 7, 2021
r_abbasi December 7, 2021

ok, Thanks @Igor Stoyanov . I am trying the first comment, as the second one isn't valid in my case. 

r_abbasi December 7, 2021

I am still getting the same error, while the build is successfull locally. Looks like something wrong with the bitbucket pipeline for node containerized app. look at the updated pipeline file. 

 

image: node:16.13.1

pipelines:

branches:

feature/devops:

- step:

name: Build and Test

script:

- IMAGE_NAME=$BITBUCKET_REPO_SLUG

- docker build . --file Dockerfile --tag ${IMAGE_NAME}

- docker save ${IMAGE_NAME} --output “${IMAGE_NAME}.tar”

services:

- docker

caches:

- docker

artifacts:

- “*.tar”
Igor Stoyanov
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 7, 2021

@ hi. Since you do not use npm in bitbucket-pipeline.yml use 

image: atlassian/default-image:3

also check and update commands inside your Dockerfile according to https://stackoverflow.com/questions/42308879/how-to-solve-npm-error-npm-err-code-elifecycle

r_abbasi December 7, 2021

I did follow that as well, but didn't work. Looks like some conflict between node and bitbucket pipelines. 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events