Ale*_*lls 6 node.js npm docker circleci circleci-2.0
我有一个运行良好的 Dockerfile:
FROM node:10
RUN npm set unsafe-perm true
RUN npm install -g '@oresoftware/r2g@0.0.132'
Run Code Online (Sandbox Code Playgroud)
但是与上述 Dockerfile 相同的 CircleCI config.yml 文件不起作用:
{
"version": 2,
"jobs": {
"build": {
"docker": [
{
"image": "circleci/node:10"
}
],
"steps": [
{
"run": "npm set unsafe-perm true"
},
{
"run": "npm install -g --loglevel=warn '@oresoftware/r2g@0.0.132'"
}
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
我使用上面的 config.yml 文件在 CircleCI 上收到以下错误:
#!/bin/bash -eo pipefail
npm install -g --loglevel=warn @oresoftware/r2g
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! path /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR! { [Error: EACCES: permission denied, access '/usr/local/lib/node_modules']
npm ERR! stack:
npm ERR! 'Error: EACCES: permission denied, access \'/usr/local/lib/node_modules\'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/local/lib/node_modules' }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).
npm ERR! A complete log of this run can be found in:
npm ERR! /home/circleci/.npm/_logs/2018-06-18T18_26_53_651Z-debug.log
Exited with code 243
Run Code Online (Sandbox Code Playgroud)
CircleCI 2.0 应该使用 Docker,所以我不确定为什么会发生这个权限错误。
npm install --prefix=$HOME/.local --global serverless
Run Code Online (Sandbox Code Playgroud)
serverless
为您自己的全局包要求。CircleCI 的当前circleci/node:lts-buster
图像在路径上有以下内容:
/home/circleci/.local/bin:/home/circleci/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
/home/circleci/bin
由于写入权限被阻止,我无法写入。
/home/circleci/.local/bin
--prefix=$HOME/.local
选项添加到npm install
命令意味着然后将全局包安装到/home/circleci/.local/bin
serverless
是可执行的。如上所述,顶部的 Dockerfile 与 CircleCI-config 中的不完全相同。在 Dockerfile 中,基础镜像node
默认在root
用户下运行。
circleci/node
另一方面,图像下降到非特权circleci
用户。因此,基于node
图像的 100% 相同的 Dockerfile将如下所示:
FROM node:10
RUN useradd -m circleci
USER circleci
RUN npm set unsafe-perm true
RUN npm install -g '@oresoftware/r2g@0.0.132'
Run Code Online (Sandbox Code Playgroud)
使用此 Dockerfile 会出现与 CircleCI 中相同的错误。
一种解决方案是使用sudo
,问题在于您必须在使用sudo
您安装的节点包的每个命令上使用(因为使用 sudo 它实际上会安装在用户/root
无法访问的目录中circleci
) .
我认为更好的选择是将软件包安装在circleci
主目录中。
{
"version": 2,
"jobs": {
"build": {
"docker": [
{
"image": "circleci/node:10"
}
],
"steps": [
{
"run": "npm set prefix=/home/circleci/npm && echo 'export PATH=$HOME/circleci/npm/bin:$PATH' >> /home/circleci/.bashrc"
},
{
"run": "npm install -g --loglevel=warn '@oresoftware/r2g@0.0.132'"
}
]
}
}
}
Run Code Online (Sandbox Code Playgroud)
这样您就不必sudo
每次要使用该软件包时都这样做。
归档时间: |
|
查看次数: |
2689 次 |
最近记录: |