我想通过aws代码构建过程为我的nodejs lambda创建一个zip工件-这样,lambda函数就可以将此zip文件用作S3中的源,并且我们在代码构建中具有使用git commit id进行管理的部署“证明”
我在github-repo中的文件结构是
folder1
- myfile.js
- otherfile.js
folder2
- otherfiles.js
package.json
现在,对于nodejs lambda项目,我想要没有zip文件夹的zip文件(对于lambda中的nodejs项目,我们需要该文件),因此zip应该直接包含以下文件
- myfile.js
- node_module ==> folder from codebuild via npm install command
问题:
1)S3中的输出zip包含在文件夹中,即.zip-> rootfolder-> myfile.js,而不是我们要求的.zip-> myfiles.js,对于lambda而言,这是不可用的,因为nodejs应该在root zip中而不是在内部他们(文件夹内没有相对路径)
2)路径-如您所见myfile.js位于文件夹中,我想省略相对路径-我尝试放弃路径,但是问题是所有的node_module文件也都在文件夹中,而不是在文件夹中,因为丢弃路径适用于两者-我可以仅为myfile.js设置丢弃路径,而不能为node_module文件夹设置丢弃路径吗?我当前的Yaml文件:
artifacts:
files:
- folder/myfile.js
- node_modules/**/*
discard-paths: yes
如果有人可以提供解决方案,那将是很好吗?
如果解决方案不包含更改github-repo文件夹结构,那太好了,我也想在该仓库中为其他文件重复此操作,以创建其他lambda函数。
编辑:
我在yaml文件下面使用过,@ awsnitin回答后一切都正常
version: 0.2
phases:
build:
commands:
- echo Build started on `date`
- npm install
post_build:
commands:
- echo Running post_build commands
- mkdir build-output
- cp -R folder1/myfile.js build-output
- mkdir -p build-output/node_modules
- cp -R node_modules/* build-output/node_modules
- cd build-output/
- zip -qr build-output.zip ./*
- mv build-output.zip ../
- echo Build completed on `date`
artifacts:
files:
- build-output.zip
不幸的是,丢弃路径在这种情况下不起作用。最好的选择是将必要的文件复制到新文件夹中,作为构建逻辑的一部分(buildspec.yml),然后在构件部分中指定该文件夹。这是一个示例buildspec文件
post_build:
commands:
- mkdir build-output
- cp -R folder/myfile.js node_modules/ build-output
artifacts:
files:
- build-output/**/*
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句