Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS CodeBuild artifact handling

So I have a react with SSR project that I am trying to create a CI/CD pipeline. My project needs to deploy the following artifacts:

  • dist folder created by Webpack
  • appspec.yml file needed by Code Deploy
  • script folder for scripts that are references in appspec.yml

When I tried to get the files one by one using this buildspec.yml:

version: 0.2

phases:
 install:
   runtime-versions:
     nodejs: 10
   commands:
     - npm install
 build:
   commands:
     - npm run build
artifacts:
  files:
    - 'dist/*'
    - 'appspec.yml'
    - 'deploy-scripts'

I got dist with only part of it's content and the appspec.yml and the deploy scripts folder.

Then I tried a different approach:

version: 0.2

phases:
  install:
    runtime-versions:
      nodejs: 10
    commands:
      - npm install
  build:
    commands:
      - npm run build
artifacts:
  files:
    - '**/*'
  base-directory: "dist"
  discard-paths: yes

The dist folder has the scripts and the appspec file inside it. Now it does deploy, but I lose the folder structure of dist which is necessary for my deploy scripts.

I need to get all the contents of dist in their folder structure. As well as the scripts and the appspec.yml file. The scripts and the appspec.yml can't be inside dist, but dist needs to have all of it's content.

Can anyone help with this?

like image 648
Carlos Jimenez Bermudez Avatar asked Oct 21 '25 06:10

Carlos Jimenez Bermudez


1 Answers

The solution was to use the first buildspec file and adding "**/*" to the dist directory.

So in the dist line it ends up being this: "dist/**/*".

So if we apply this to the general context, anytime you want to get a directory to be sent along with single files in the build phase, you can add it like this:

"[directory_name]/**/*"

And that will get you both the directory and everything inside it in a recursive way.

like image 102
Carlos Jimenez Bermudez Avatar answered Oct 25 '25 11:10

Carlos Jimenez Bermudez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!