Search code examples
dockergitlabgitlab-cicreate-react-appgitlab-ci-runner

Why is Create React App build failing in Gitlab CI Runner?


The contents of my Dockerfile:

FROM node:alpine as builder

WORKDIR /usr/src/app

COPY package.json . 

RUN npm install

COPY . .

RUN npm run build  || cat /root/.npm/_logs/*.log

FROM nginx 

COPY --from=builder /usr/src/app/build /usr/share/nginx/html

I've configured this to run with my own gitlab runner. This was working fine until the last time I attempted a build. On my own machine it builds without issue. Only when the gitlab runner attempts to build it does it fail. Only changes I made were to install some extra libraries inside my web app. Here is the output of the gitlab runner:

Running with gitlab-runner 12.0.0 (6946bae7)
  on chargo-runner r1N7i14n
Using Docker executor with image docker:stable ...
Starting service docker:dind ...
Pulling docker image docker:dind ...
Using docker image sha256:fd0c64832f7e46b63a180e6000dbba7ad7a63542c5764841cba73429ba74a39e for docker:dind ...
Waiting for services to be up and running...

*** WARNING: Service runner-r1N7i14n-project-10187987-concurrent-0-docker-0 probably didn't start properly.

Health check error:
service "runner-r1N7i14n-project-10187987-concurrent-0-docker-0-wait-for-service" timeout

Health check container logs:

...

2019-07-27T09:17:36.285748935Z time="2019-07-27T09:17:36.285428543Z" level=warning msg="Running modprobe bridge br_netfilter failed with message: ip: can't find device 'bridge'\nbridge                151552  1 br_netfilter\nstp                    16384  1 bridge\nllc                    16384  2 bridge,stp\nip: can't find device 'br_netfilter'\nbr_netfilter           24576  0 \nbridge                151552  1 br_netfilter\nmodprobe: can't change directory to '/lib/modules': No such file or directory\n, error: exit status 1"

...

Pulling docker image docker:stable ...
Using docker image sha256:c4154a2b47a18fe9437956ab981bd5924b19e7ae3eb3ed60c42cf8dfa394d550 for docker:stable ...
Running on runner-r1N7i14n-project-10187987-concurrent-0 via ubuntu-s-1vcpu-1gb-lon1-01...
Fetching changes...
Reinitialized existing Git repository in /builds/chargo/chargoworkspace/.git/
Checking out 7ec3cfc1 as master...
Removing adminapp/coverage/
Removing adminapp/node_modules/

Skipping Git submodules setup
Checking cache for master...
No URL provided, cache will not be downloaded from shared cache server. Instead a local version of cache will be extracted. 
Successfully extracted cache
$ docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
WARNING! Using --password via the CLI is insecure. Use --password-stdin.
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store

Login Succeeded
$ docker build -t $DOCKER_ADMAPP_IMAGE_TAG -f adminapp/Dockerfile ./adminapp
Sending build context to Docker daemon  201.4MB

Step 1/8 : FROM node:alpine as builder
alpine: Pulling from library/node
e7c96db7181b: Pulling fs layer
72484f09da35: Pulling fs layer
86bee4bed5f2: Pulling fs layer
f9e983f0fe2c: Pulling fs layer
f9e983f0fe2c: Waiting
e7c96db7181b: Verifying Checksum
e7c96db7181b: Download complete
86bee4bed5f2: Verifying Checksum
86bee4bed5f2: Download complete
72484f09da35: Verifying Checksum
72484f09da35: Download complete
e7c96db7181b: Pull complete
f9e983f0fe2c: Verifying Checksum
f9e983f0fe2c: Download complete
72484f09da35: Pull complete
86bee4bed5f2: Pull complete
f9e983f0fe2c: Pull complete
Digest: sha256:300e3d2c19067c1aec9d9b2bd3acbd43d53797a5836d70a23e437a5634bcd33a
Status: Downloaded newer image for node:alpine
 ---> d97a436daee9
Step 2/8 : WORKDIR /usr/src/app
 ---> Running in 7c3a1727f367
Removing intermediate container 7c3a1727f367
 ---> dfe2f6cb09f7
Step 3/8 : COPY package.json .
 ---> f22d985084b4
Step 4/8 : RUN npm install
 ---> Running in 2505724f412d
npm WARN deprecated [email protected]: Please update: there are crash fixes
npm WARN deprecated [email protected]: core-js@<2.6.8 is no longer maintained. Please, upgrade to core-js@3 or at least to actual version of core-js@2.
npm WARN deprecated [email protected]: I wrote this module a very long time ago; you should use something else.
npm WARN deprecated [email protected]: use String.prototype.padStart()

> [email protected] postinstall /usr/src/app/node_modules/core-js
> node scripts/postinstall || echo "ignore"


The command '/bin/sh -c npm install' returned a non-zero code: 1
ERROR: Job failed: exit code 1

The build task in my .gitlab-ci.yml file is when the failure occurs:

variables:
    DOCKER_ADMAPP_IMAGE_TAG: ${CI_REGISTRY_IMAGE}/adminapp:${CI_COMMIT_SHORT_SHA}
build:
    tags: [docker]
    stage: build
    image: docker:stable
    services:
        - docker:dind
    before_script:
        - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
    script:
        - docker build -t $DOCKER_ADMAPP_IMAGE_TAG -f adminapp/Dockerfile ./adminapp
        - docker push $DOCKER_ADMAPP_IMAGE_TAG 

Can anyone suggest a solution or explain what is causing the build to fail?


Solution

  • This seems to be an issue to do with a recent change in Docker which is conflicting with gitlab see here:

    https://gitlab.com/gitlab-org/gitlab-runner/issues/4501

    I tried the solutions posted there but could only get my runner working again by resorting to using the gitlab shared runners instead of my own.