我正在尝试使用AWS CodeBuild来获取嵌套的public
文件夹中的所有文件和子文件夹,并使用CodePipeline部署到S3存储桶。我能够将它们连接在一起,但努力配置buildspec.yml
文件以获得我想要的输出。
我的文件夹结构:
<path>/public/
├── 404.html
├── css
│ ├── ...
├── fonts
│ ├── bootstrap
│ │ ├── ...
│ ├── icomoon
│ │ ├── icomoon
│ │ │ ├── ...
│ └── simple-line-icons
│ ├── ...
├── images
│ ├── ...
├── index.html
├── index.xml
├── js
│ ├── ...
└── tags
└── index.xml
我需要将public
文件夹中的所有内容(包括子文件夹)放入S3存储桶的根目录中。
到目前为止,我已经尝试过跟随文档here,here和here。我尝试过使用:
**/*
在文件夹public
中递归获取所有内容,但S3存储桶将具有该文件夹的路径,因此index.html
不在根目录中。discard-paths: yes
删除public
文件夹的路径,但在S3存储桶内,所有文件都在根目录中,不保留子文件夹结构。base-directory
:如here所述。artifacts:
secondary-artifacts:
artifact1:
files:
- directory/file
artifact2:
files:
- directory/file2
保持文件夹结构,但我的构建失败。我找到了解决它的方法。我不认为这是最好的方式,但它的工作原理。我希望你能找到这个解决方案有用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:
- '**/*'
用语言:
<path>/public
文件夹中的所有内容复制到名为./build-output
的文件夹中。post_build
我移动文件夹build-output
。S3 bucket
中托管静态网站public
根目录中的S3 bucket
所有文件和正确的文件夹树。更新:
我遇到了类似的问题,经过下面的许多排列后,语法对我起作用。
artifacts:
files:
- './**/*'
base-directory: public
name: websitename