Reputation: 41470
How to generate ".env" when Deploying with Bitbucket AWS CodeDeploy add-on?
I see bitbucket-pipelines.yml
can generate .env from bitbucket environment variables, but, how tie it up with Bitbucket AWS CodeDeploy add-on?
appspec.yml
- can trigger script on deployment but how can I make it get .env from bitbucket environment variables?
Upvotes: 0
Views: 973
Reputation: 41470
BitBucket
should not create .env
, this service should know nothing about production .env
. Instead the production .env
should sit on secure AWS S3 bucket
where only AWS CodeDeploy
scripts can take it and put on the instance.
it would be copied like this
sudo aws --region us-east-2 s3 cp "s3://${S3_NAME}/prod.env" "${EC2_DIRECTORY}/.env"
Upvotes: 1
Reputation: 7464
Looking at the documentation, BitBucket should make the environments available in the build environment, and you should be able to access them directly in your scripts run by your appspec.yml
just like you would access any other environment variables.
For example, if we had an appspec like this:
hooks:
AfterInstall:
- location: scripts/runTests.sh
timeout: 180
You could access the environment variables in scripts/runTests.sh
like this:
# scripts/runTests.sh
echo "$BITBUCKET_BUILD_NUMBER"
# Or, use in some other valid way in your script
Upvotes: 0