Reputation: 510
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.
Upvotes: 23
Views: 21333
Reputation: 1
faced the same issue and here is what worked for me:
CodeBuild Artifacts Config
name: just a "/" no quotes.
path: "./" again no quotes.
nameSpace: None
All my files are now in root of s3 with no parent folders.
Upvotes: 0
Reputation: 71
Adhering to the paradigma of CodePipeline, I'd suggest you produce an artifact containing only the folder using code build, and then deploy that artifact to whereever, e.g. to S3 using AWS Code Deploy.
But if if you really want to use Code Build then the following is a solution:
In the Codebuild template
use:
artifacts:
files:
- "dist/**/*"
Then in the AWS Console edit the "Artifacts" section of your codebuild project, use the following inputs:
Other Examples taken from aws documentation:
If path is set to MyArtifacts, namespaceType is set to BUILD_ID, and name is set to MyArtifact.zip, then the output artifact is stored in MyArtifacts//MyArtifact.zip.
If path is empty, namespaceType is set to NONE, and name is set to "/", the output artifact is stored in the root of the output bucket.
If path is set to MyArtifacts, namespaceType is set to BUILD_ID, and name is set to "/", the output artifact is stored in MyArtifacts/.
Upvotes: 4
Reputation: 877
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.
Upvotes: 42
Reputation: 126
I only recently figured this out myself, so experts please forgive me if I am incorrect, but:
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.
Again, this part I'm not sure about, but it seemed to me that you can't tell CodeBuild not to apply server side encryption to your artifacts, meaning if its a website you intend to allow people to browse to, that's not going to work, at least out of the box. What I ended up doing was instead of using the artifact section of codebuild at all, I added the following post_build command:
commands:
- aws s3 sync my/artifact/path/ s3://my-bucket-name/
edit: I am building using a docker image I created and added to Amazon's ECR, I had to install the AWS CLI in my image to be able to run that command.
Upvotes: 11