Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Codebuild puting all artifacts in root of S3 bucket

I'm building a project that puts all of it's files in a 'dist' folder, and running it through CodeBuild. I'm trying to get it to put all of the files and folders in 'dist' into the root of the s3 bucket, but I'm having trouble figuring out how to make that work.

My 'dist' folder looks something like this:

- index.html - somecssfiles.css - fonts/ - - some fonts or w/e - js/ - - some javascript files

I've tried a lot of different stuff, but can't seem to get it to just drop 'dist/*' into the root of the s3 bucket. Here's the current iteration of my artifacts property in the buildspec.yml file:

artifacts: files: - '*' discard-paths: yes base-directory: 'dist'

I thought that would probably work, but it ignores the folders. Any help is appreciated, thanks for reading.

like image 262
Xylude Xaalud Avatar asked Mar 29 '18 16:03

Xylude Xaalud


People also ask

What is discard path?

The "discard-paths: yes" is what throws away your directory structure. It essentially flattens your artifact set. If (like me) you only want to throw away paths up to your artifact folder, put that full path in the "base-directory" field.

Where do the build artifacts are stored after AWS CodeBuild service completes code build?

If the build details page is not displayed, in the navigation bar, choose Build history, and then choose the Build run link. The link to the Amazon S3 folder is under the Artifacts upload location. This link opens the folder in Amazon S3 where you find the messageUtil-1.0. jar build output artifact file.

How do you encrypt the build artifacts that are stored by CodeBuild?

Q: Can I encrypt the build artifacts stored by CodeBuild? Yes. You can specify a key stored in the AWS Key Management Service (AWS KMS) to encrypt your artifacts.

What are artifacts in CodeBuild?

Artifacts is a property of the AWS::CodeBuild::Project resource that specifies output settings for artifacts generated by an AWS CodeBuild build.


1 Answers

I think you're missing a piece - it's not clear but you need to specify the path in your Codebuild template with the following artifacts:

artifacts:
  files:
    - '**/*'
  base-directory: 'dist'

And then ensure that in the "Artifacts" section of your codebuild project, you specify the S3 bucket normally, but add the "optional" name parameter to be /

This sets the output to the root of the S3 directory - see https://docs.aws.amazon.com/codebuild/latest/APIReference/API_ProjectArtifacts.html#CodeBuild-Type-ProjectArtifacts-name

If type is set to S3, this is the name of the output artifact object. If you set the name to be a forward slash ("/"), the artifact is stored in the root of the output bucket.

like image 186
abbottdev Avatar answered Sep 17 '22 13:09

abbottdev