【问题标题】:Can't remove file based variables无法删除基于文件的变量
【发布时间】:2022-01-02 21:40:54
【问题描述】:

到目前为止,似乎 gitlab runner 的这个错误输出在互联网上没有很好的记录,所以我开始一个话题。错误输出:

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

这是来自 Ubuntu 机器上本地安装的 gitlab runner。 有关如何解决此错误的任何建议?

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"]

【问题讨论】:

    标签: gitlab-ci gitlab-ci-runner


    【解决方案1】:

    我认为这与 gitlab 无关,您正在覆盖项目中每个依赖项的所有者,而 nodejs 往往会呈指数增长。

    你没有发布你的Dockerfile,但这只是用以下方式重写的问题:

    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"]
    

    【讨论】:

    • 我已将我正在使用的 Dockerfile 添加到问题中。你能复习一下吗?我不认为那里有什么大问题,但我以前错了。
    • @Mark Nice,我已经更新了我的答案以匹配提供的 Dockerfile。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-19
    • 1970-01-01
    • 1970-01-01
    • 2021-03-07
    • 2020-01-14
    • 2022-01-16
    • 2020-02-11
    相关资源
    最近更新 更多