[英]AWS CodeBuild buildspec.yml get all files and subfolders recursively
I'm trying to use AWS CodeBuild to get all files and subfolders inside a nested public<\/code> folder and deploy to an S3 bucket using CodePipeline.
我正在尝试使用 AWS CodeBuild 获取嵌套
public<\/code>中的所有文件和子文件夹,并使用 CodePipeline 部署到 S3 存储桶。
I was able to hook them all together but struggling to configure the
buildspec.yml<\/code> file to get the output I want.
我能够将它们全部连接在一起,但努力配置
buildspec.yml<\/code>文件以获得我想要的输出。
My folder structure:我的文件夹结构:
<path>/public/
├── 404.html
├── css
│ ├── ...
├── fonts
│ ├── bootstrap
│ │ ├── ...
│ ├── icomoon
│ │ ├── icomoon
│ │ │ ├── ...
│ └── simple-line-icons
│ ├── ...
├── images
│ ├── ...
├── index.html
├── index.xml
├── js
│ ├── ...
└── tags
└── index.xml
TL;DR You probably don't need to use " discard-paths: yes ". TL; DR你可能并不需要使用“丢弃路径:是的”。 So, drop " discard-paths: yes " and instead use " base-directory " with " **/* " for glob pattern.所以,去掉“ discard-paths: yes ”,而是使用“ base-directory ”和“ **/* ”作为glob模式。 Read on for more reasoning why.继续阅读以了解更多原因。
So yeah, as it usually happens, the culprit was pretty trivial.所以是的,正如通常发生的那样,罪魁祸首非常微不足道。 In my case the directory structure looked like this:就我而言,目录结构如下所示:
dist/
|-- favicon.ico
|-- index.html
|-- js
| `-- app.js
`-- revision.txt
So in order for the artifact to contain everything from the " dist " directory whilst preserving the nested directories structure, the buildspec had to look like this:因此,为了让工件包含“ dist ”目录中的所有内容,同时保留嵌套目录结构,构建规范必须如下所示:
artifacts:
files:
- '**/*'
base-directory: 'dist'
Essentially " base-directory " parameter behaves as unix's "cd" command, so at first CodeBuild jumps to that directory and only after that resolves the glob pattern, in this case - **/* .本质上,“ base-directory ”参数的行为类似于unix的“ cd”命令,因此首先CodeBuild跳转到该目录,然后才解析glob模式,在本例中为 - **/* 。 If you also happen to use " discard-paths " then what happens is that, presumably, CodeBuild will change current directory to " dist ", resolve the files structure correctly but then remove all path prefixes from the resolved paths, thus the result will be a plain directory structure with no nesting.如果你也碰巧使用“丢弃路径”然后发生的事情是,据推测,CodeBuild将当前目录切换到“DIST”,正确地解析文件结构,但随后从解决路径删除所有路径前缀,这样的结果将是没有嵌套的普通目录结构。
Hope that helps!希望有帮助!
I've figured out a way to work around it.我想出了一个办法来解决它。 I don't think it's the best way but it works.我不认为这是最好的方法,但它有效。 I hope you can find this solution useful buildspec.yml
:我希望你能找到这个解决方案有用的buildspec.yml
:
version: 0.2
phases:
build:
commands:
- mkdir build-output
- cp -R <path>/public/ build-output
post_build:
commands:
- mv build-output/**/* ./
- mv build-output/* ./
- rm -R build-output *.yml LICENSE README* .git*
artifacts:
files:
- '**/*'
In words:用一句话来说:
I copy everything inside the nested <path>/public
folder out to a folder called ./build-output
.我将嵌套的<path>/public
文件夹中的所有内容复制到名为./build-output
的文件夹中。
Then in post_build
I move everything out of folder build-output
.然后在post_build
我将所有内容移出文件夹build-output
。
Delete files pulled from my GitHub's repo which aren't needed to host the static website in the S3 bucket
删除从我的 GitHub 存储库中提取的文件,这些文件不需要在S3 bucket
托管静态网站
Then I get the result I want: all files inside public
in the root of the S3 bucket
with the right folder tree.然后我得到了我想要的结果: S3 bucket
根目录中public
中的所有文件以及正确的文件夹树。
Update:更新:
I was running into a similar issue and after many permutations below syntax worked for me.我遇到了类似的问题,经过以下语法的许多排列对我有用。
artifacts:
files:
- './**/*'
base-directory: public
name: websitename
对于那些在 CodePipline 中使用 CodeBuid 并尝试正确配置 buildspec.yml 文件的人来说,罪魁祸首是在部署阶段,我将源工件而不是构建工件设置为输入工件。
This worked for me.这对我有用。
/
buildspec.yml
/public
index.html
/js
/img
appspec.yml
/src
in buildspec.yml在 buildspec.yml 中
artifacts:
files:
- 'public/*'
discard-paths: yes
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.