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;“]
# 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”
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"
Thanks @r.abbasi it works
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@r.abbasi hi. Do you have warnings in your local build? This was pointed here: https://stackoverflow.com/a/58701621
Regards, Igor.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
ok, Thanks @Igor Stoyanov . I am trying the first comment, as the second one isn't valid in my case.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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”
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@ 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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.