Docker Build Failing on Travis --> can't find app/build - docker

I am trying to push my images from Travis CI to docker hub.
Here is my Dockerfile
FROM node:alpine as builder
WORKDIR /app
COPY ./package.json ./
RUN npm install
COPY . .
CMD npm run build
FROM nginx
EXPOSE 3000
COPY ./nginx/default.conf /etc/nginx/conf.d/default.conf
COPY --from=builder /app/build /usr/share/nginx/html
My .travis.yml
sudo: required
services:
- docker
before_install:
- docker build -t aseel/react-test -f ./client/Dockerfile.dev ./client
script:
- docker run -e CI=true aseel/react-test npm run test
after_success:
- docker build -t aseel/multi-client ./client
- docker build -t aseel/multi-nginx ./nginx
- docker build -t aseel/multi-server ./server
- docker build -t aseel/multi-worker ./worker
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_ID" --password-stdin
- docker push aseel/multi-server
- docker push aseel/multi-nginx
- docker push aseel/multi-worker
- docker push aseel/multi-client
The reason the push is failing is because this command
docker build -t aseel/multi-client ./client
is failing on travis (but not locally).
More specifically, I'm getting this error on travis
COPY failed: stat
/var/lib/docker/overlay2/135282513e177be132b6978986f878ba61f3b89914b6b2f7030cbafa0d33f629/merged/app/build:
no such file or directory
Any idea why this is happening?

I needed to switch CMD to RUN -- It was a pretty silly mistake

Related

docker : No subsytem for mount

I'm running a CI pipeline in gitlab-runner which is running on a linux machine.
In the pipeline I'm trying to build an image.
The Error I'm getting is,
ci runtime error: rootfs_linux.go:53: mounting "/sys/fs/cgroup" to rootfs "/var/lib/docker/overlay/d6b9ba61e6eed4bcd9c23722ad6f6a9fb05b6c536dbab31f47b835c25c0a343b/merged" caused "no subsystem for mount"
The Dockerfile contains :
# Set the base image to node:12-alpine
FROM node:16.7.0-buster
# Specify where our app will live in the container
WORKDIR /app
# Copy the React App to the container
COPY . /app/
# Prepare the container for building React
RUN npm install
RUN npm install react-scripts#4.0.3 -g
# We want the production version
RUN npm run build
# Prepare nginx
FROM nginx:stable
COPY --from=0 /app/build /usr/share/nginx/html
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx/nginx.conf /etc/nginx/conf.d
# Fire up nginx
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
The gitlab-ci.yml contains :
image: gitlab/dind
services:
- docker:dind
variables:
DOCKER_DRIVER: overlay
stages:
- build
- docker-build
cache:
paths:
- node_modules
yarn-build:
stage: build
image: node:latest
script:
- unset CI
- yarn install
- yarn build
artifacts:
expire_in: 1 hour # the artifacts expire from the artifacts folder after 1 hour
paths:
- build
docker-build:
stage: docker-build
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD
- docker build -t $CI_REGISTRY_USER/$app_name .
- docker push $CI_REGISTRY_USER/$app_name
I'm not getting how to resolve this, I tried upgrading docker in my linux machine.

Gitlab CI hangs on npm run build (webpack production command)

GitLab Pipeline Output
GitLab CI/CD YML file
image: docker:latest
services:
- docker:dind
stages:
- test
test_stage:
stage: test
tags:
- def
before_script:
- apk version
- apk add --no-cache docker-compose
- docker info
- docker-compose --version
script:
- echo "Building and testing"
- docker-compose up --abort-on-container-exit
Dockerfile
FROM node:10.15.3 as source
COPY package.json ./
COPY package-lock.json ./
RUN node -v
RUN npm -v
RUN npm install
COPY . ./
RUN npm run build
FROM nginx:1.15.9
COPY default.template /etc/nginx/conf.d/default.conf
CMD ["nginx", "-g", "daemon off;"]
'npm run build' from the Dockerfile runs 'webpack --mode production' which attempts to start my app on localhost within Docker. Instead, GitLab is getting stuck in 'npm run build'.
This works locally with Docker but not on the GitLab CI/CD runner, it seems to be hanging there and potentially having an out of memory error, which I received earlier when it was hanging even longer.
Why is the GitLab runner getting stuck on 'webpack --mode production' (my npm run build command)? Should I only be using 'webpack -p"?

Gitlab job failed when I try to build Docker image

There is the following Dockerfile:
FROM node:12.22-alpine3.12 as builder
RUN mkdir /app
COPY . /app
WORKDIR /app
RUN npm i && npm build
FROM nginx:alpine
WORKDIR /usr/share/nginx/html
RUN rm -rf ./*
EXPOSE 80
COPY --from=builder /app/build ./
ENTRYPOINT ["nginx", "-g", "daemon off;"]
There is nothing smart - just build static JS app and put it to nginx directory. It works locally excellent. But it failed on Gitlab with the following error:
Step 8/11 : RUN rm -rf ./*
---> Running in a9cf55a3da31
Removing intermediate container a9cf55a3da31
---> 50c9a02d542d
Step 9/11 : EXPOSE 80
---> Running in edda7f7bf296
Removing intermediate container edda7f7bf296
---> be2caf89404f
Step 10/11 : COPY --from=builder /app/build ./
COPY failed: stat /var/lib/docker/overlay2/6a441679247bd4e1a321f7c6e15d4fe8dd59c5013d4e0058b7f3c9f395c20f98/merged/app/build: no such file or directory
Cleaning up file based variables
00:02
ERROR: Job failed: command terminated with exit code 1
And I don't understand what does it mean, because locally it works without any troubles at all.
UPD: my .gitlab-ci.yml:
stages:
- test
- build
test:
stage: test
image: node:12.22-alpine3.12
script:
- echo 'Test Success'
build:
image: docker:19.03.12
stage: build
services:
- docker:19.03.12-dind
variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_TLS_CERTDIR: ""
before_script:
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
script:
- docker build -t "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG.$CI_PIPELINE_ID" .
- docker push "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG.$CI_PIPELINE_ID"

How to solve build timeout when using travis

I'm setting up travis to push images to docker hub after running a test script
sudo: required
services:
- docker
before_install:
- docker build -t oskygh/react-test -f ./client/Dockerfile.dev ./client
script:
- docker run oskygh/react-test npm test -- --coverage
after_success:
- docker build -t osbee/client ./client
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_ID" --password-stdin
- docker push osbee/client
dockerfile.dev
FROM node:alpine
WORKDIR '/app'
COPY ./package.json ./
RUN npm install
COPY . .
CMD ["npm","run","start"]
As explained here you could use the travis_wait function. Adding it before the command, which failed. You could also read this stackoverflow, which added it in another way.

Docker images using circleci

I am working on integrating CI/CD pipeline using Docker. How can i use dockercompose file to build and create container?
I have tried it in putting Dockerfile, and docker-compose.yml, but none of them works.
Below is docker-compose file :
FROM ruby:2.2
EXPOSE 8000
RUN mkdir -p /usr/src/app
COPY . /usr/src/app
WORKDIR /usr/src/app
RUN bundle install
CMD ["ruby","app.rb"]
RUN docker build -t itsruby:itsruby .
RUN docker run -d itsruby:itsruby
Below is docker-compose.yml
version: 2
jobs:
build:
docker:
- image: circleci/ruby:2.2
steps:
- checkout
- run: CMD ["ruby","app.rb"]
- run: |
docker build -t itsruby:itsruby .
docker run -d itsruby:itsruby
test:
docker:
- image: circleci/ruby:2.2
steps:
- checkout
- run: CMD ["ruby","app.rb"]
The build is getting failed in circle/ci.

Resources