AWS CodeBuild buildspec.yml递归获取所有文件和子文件夹

问题描述 投票:3回答:1

我正在尝试使用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存储桶的根目录中。

到目前为止,我已经尝试过跟随文档hereherehere。我尝试过使用:

  • **/*在文件夹public中递归获取所有内容,但S3存储桶将具有该文件夹的路径,因此index.html不在根目录中。
  • discard-paths: yes删除public文件夹的路径,但在S3存储桶内,所有文件都在根目录中,不保留子文件夹结构。
  • base-directory:如here所述。
  • artifacts: secondary-artifacts: artifact1: files: - directory/file artifact2: files: - directory/file2保持文件夹结构,但我的构建失败。
  • 上面所有语法的不同组合,但我的构建失败了。
amazon-web-services amazon-s3 aws-codebuild
1个回答
5
投票

我找到了解决它的方法。我不认为这是最好的方式,但它的工作原理。我希望你能找到这个解决方案有用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
  • 删除从我的GitHub的repo中提取的文件,这些文件不需要在S3 bucket中托管静态网站
  • 然后我得到我想要的结果:public根目录中的S3 bucket所有文件和正确的文件夹树。

更新:

  • 您也可以使用我的buildspec.yml示例文件here。由于该示例超出了此问题的范围,因此我不会在此处粘贴代码。
  • 我详细解释了here

0
投票

我遇到了类似的问题,经过下面的许多排列后,语法对我起作用。

artifacts:
  files:
    - './**/*'
  base-directory: public
  name: websitename
© www.soinside.com 2019 - 2024. All rights reserved.