gpt4 book ai didi

Angular Build EPERM : operation not permitted, 复制文件

转载 作者:行者123 更新时间:2023-12-05 05:59:31 27 4
gpt4 key购买 nike

我在 Docker 容器中的 Jenkins 中运行 Angular 12 构建,在尝试将 Assets 文件复制到 dist 文件夹时看到此错误:

✖ Copying of assets failed.
Unable to copy assets: EPERM: operation not permitted, copyfile '/var/jenkins_home/workspace/MY-Web-App/src/assets/building.svg' -> '/var/jenkins_home/workspace/MY-Web-App/dist/my-web-app/assets/building.svg'

问题是在我们于 2021 年 6 月 15 日更新 Ubuntu docker 主机上的所有操作系统包后开始的。

首先想到的是 seccomp 是错误的,但我在 docker-compose 中有这个:

  jenkins:
build: ./jenkins
image: my-ci-jenkins
hostname: ....
user: root
volumes:
- /data/ci/jenkins/jenkins_home:/var/jenkins_home
- artifactsvolume:/var/jenkins_home/workspace/artifacts/dist/my-web-app
ports:
- '8080:8080'
- '50000:50000'
security_opt:
- seccomp:./jenkins/seccomp.json
depends_on:
- mariadb
- gitea
environment:
- TZ=America/Los_Angeles
- JENKINS_HOME=/var/jenkins_home
restart: always
networks:
my-ci-net:
ipv4_address: ....

除此之外,在 seccomp.json 中:

{
"defaultAction": "SCMP_ACT_ERRNO",
"syscalls": [
...
{
"name": "copyfile",
"action": "SCMP_ACT_ALLOW",
"args": null
}, ...
]
}

然后,也许是权限,NodeJS,npm?不,我目前以 root 身份运行该进程,清理了 node_modules,在 Jenkinsfile 中输入大量日志以查看发生了什么。我正在使用 Jenkins 管道运行构建——这些是结帐、日志记录和构建步骤:

checkout scm
sh 'rm -rf ./node_modules'
sh 'npm install'
sh 'mkdir -p ./dist/my-web-app/assets'
sh 'chmod 766 ./dist/my-web-app/assets'
sh 'ls -al ./dist/my-web-app'
sh 'whoami'
sh 'pwd'
sh 'ls -al'
sh 'node --version'
sh 'npm --version'
sh 'ls -al /var/jenkins_home/workspace/My-Web-App/src/assets'
sh 'ng build --configuration=staging'

产生以下日志:

Building...
[Pipeline] sh
+ mkdir -p ./dist/my-web-app/assets
[Pipeline] sh
+ chmod 766 ./dist/my-web-app/assets
[Pipeline] sh
+ ls -al ./dist/my-web-app
total 5848
.....
drwxrw-rw- 2 root root 4096 Jun 23 17:44 assets
.....
[Pipeline] sh
+ whoami
root
[Pipeline] sh
+ pwd
/var/jenkins_home/workspace/My-Web-App
[Pipeline] sh
+ ls -al
total 720
.....
drwxr-xr-x 3 root root 4096 Jun 23 17:43 dist
-rw-r--r-- 1 root root 95 Feb 28 2020 docker-compose.yml
-rw-r--r-- 1 root root 3522 Jun 23 16:48 Jenkinsfile
.....
[Pipeline] sh
+ node --version
v14.17.1
[Pipeline] sh
+ npm --version
6.14.13
[Pipeline] sh
+ ls -al /var/jenkins_home/workspace/My-Web-App/src/assets
total 2080
drwxr-xr-x 2 root root 4096 Jun 23 18:39 .
drwxr-xr-x 6 root root 4096 Jun 23 18:39 ..
-rw-r--r-- 1 root root 3737 Feb 28 2020 building.svg
.....
[Pipeline] sh
+ ng build --configuration=staging
- Generating browser application bundles (phase: setup)...
Compiling @angular/core : es2015 as esm2015
.....
✔ Browser application bundle generation complete.
- Generating ES5 bundles for differential loading...
✔ Browser application bundle generation complete.
✔ ES5 bundle generation complete.
- Copying assets...
✖ Copying of assets failed.
Unable to copy assets: EPERM: operation not permitted,
copyfile '/var/jenkins_home/workspace/My-Web-App/src/assets/building.svg'
-> '/var/jenkins_home/workspace/My-Web-App/dist/my-web-app/assets/building.svg'

构建成功地在 dist 文件夹中创建了 main-...js 文件等,但只是没有复制 Assets 。我可以成功创建一个文件,然后将其复制到 Jenkinsfile sh 中,但在 Angular 构建期间不能:

[Pipeline] sh
+ touch ./dist/my-web-app/assets/me.txt
[Pipeline] sh
+ cp ./dist/my-web-app/assets/me.txt ./dist/my-web-app/assets/me-copy.txt
[Pipeline] sh
+ ls -al ./dist/my-web-app/assets
total 8
drwxrw-rw- 2 root root 4096 Jun 24 10:40 .
drwxr-xr-x 3 root root 4096 Jun 23 18:43 ..
-rw-r--r-- 1 root root 0 Jun 24 10:40 me-copy.txt
-rw-r--r-- 1 root root 0 Jun 24 10:40 me.txt

也许是 Angular 版本?我在 Angular 9、10、11 和 12 上尝试过同样的事情,结果相同,所以看起来问题不是 Angular 造成的。 Angular 人员建议这不是 Angular 问题:https://github.com/angular/angular-cli/issues/21198

angular.config(配置)

"configurations": {


"staging": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.staging.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"namedChunks": false,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"budgets": [
{
"type": "initial",
"maximumWarning": "2.7mb",
"maximumError": "15mb"
},
{
"type": "anyComponentStyle",
"maximumWarning": "8kb",
"maximumError": "10kb"
}
]
},
...

节点,NPM?我尝试过使用 Node 12 和 14。我尝试过 npm cache clean --forcenpm cache verify 并且如上所示,还删除了整个 node_modules 文件夹。

docker ?我使用 jenkins/jenkins:latest 作为基础多次重建了 docker 镜像和容器

我已经阅读并尝试了很多 StackOverflow、Github 等来自有类似问题的人的评论,建议重新启动、重建、检查权限、升级等,但没有运气,同样的问题。

不确定问题出在哪里:Angular、Docker、Jenkins、config、perms、colour-of-socks-im-wearing...非常感谢接受任何建议。

最佳答案

每当我尝试运行构建时,我也会遇到同样的错误,(windows os) 然后我只是在 Angular 项目文件夹的配置中取消选中“只读”属性然后构建成功, enter image description here

所以只需尝试为项目文件夹提供读、写权限

关于Angular Build EPERM : operation not permitted, 复制文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68120537/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com