Can't remove file based variables

885 views Asked by At

It looks like this error output from gitlab runner isn't well documented on the Internet so far so I'm starting a topic. Error output:

Step 11/13 : RUN chown -R node /usr/src/app/node_modules
 ---> Running in d9cb1a93d908
WARNING: Error while executing file based variables removal script  error=context canceled job=1 project=0
ERROR: Failed to cleanup volumes
ERROR: Job failed: execution took longer than 30m0s seconds

FATAL: execution took longer than 30m0s seconds

this is coming from gitlab runner installed locally on Ubuntu machine. Any suggestions as to how to troubleshoot this error ?

Dockerfile:

FROM node:16-alpine

WORKDIR /usr/src/app

ENV PATH /usr/src/app/node_modules/.bin:$PATH

COPY package.json /usr/src/app/package.json
COPY package-lock.json /usr/src/app/package-lock.json
RUN mkdir /usr/src/app/node_modules
RUN mkdir /usr/src/app/node_modules/.cache
RUN npm config set unsafe-perm true  # to avoid permission problems when accessing .cache dir later on
RUN npm ci --loglevel=error
RUN npm i -g --silent --loglevel=error
RUN chown -R node /usr/src/app/node_modules
USER node

CMD ["npm", "start"]
1

There are 1 answers

2
Aristu On

I don't think this is related to gitlab, you are overwriting the owner of every dependency in your project, with nodejs those tend to grow exponentially.

node modules

You didn't post your Dockerfile, but this would be a matter of just rewriting in the following way:

FROM node:16-alpine

ENV PATH /home/node/app/node_modules/.bin:$PATH

# Create a directory for the project, change the owner and group
# to it, but do this before installing anything in the node_modules
# directory, to avoid timeouts.
RUN mkdir -p /home/node/app/node_modules \
    && mkdir -p /home/node/app/node_modules/.cache \
    && chown -R node:node /home/node/app

# Change to a workdir that can be owned by the 'node' user
WORKDIR /home/node/app

# Copying the lockfiles to make them cached by Docker, 
# also sets the right permissions at the same time
COPY --chown=node:node package*.json ./

# to avoid permission problems when accessing .cache dir later on
RUN npm config set unsafe-perm true
RUN npm ci --loglevel=error \
    && npm i -g --silent --loglevel=error

# Now, change to the node user and install your deps
USER node

# Copy the remaining files and make sure to set the user/group
# right, to avoid permission issues
COPY --chown=node:node . .

RUN npm install

CMD ["npm", "start"]