How do I utilize private composer repositories when deploying with Amazon AWS Elastic Beanstalk in a PHP environment? Specifically using GitHub (Q & A style, answer foll
TLDR: Use ~/.composer/auth.json, github-oauth on composer.json, or create a custom script like the one below:
This is my 02-github-deploy-keys.config file. It's working right now. The only workaround was to disable StrictHostKeyChecking. But you can turn StrictHostKeyChecking on after this script runs, if you like.
I added /vendor (without any file) to Git to stop AWS from auto-running Composer before the keys were OK. To do so i created a .gitignore file inside /vendor, with this:
*
!.gitignore
I'm storing the keys (id_rsa) on a S3 bucket, where i allowed "Authorized" people to read the file, but you can put the file on your github repository. These keys were generated on a machine user (https://developer.github.com/guides/managing-deploy-keys/#machine-users).
files:
"/home/ec2-user/sshgit/composer.sh":
mode: "00755"
owner: ec2-user
group: ec2-user
encoding: plain
content: |
if [ ! -f /home/ec2-user/id_rsa ] ; then
aws s3 cp s3://eb-files/id_rsa /home/ec2-user/id_rsa
chmod 0400 /home/ec2-user/id_rsa
fi
eval `ssh-agent -s`
ssh-add /home/ec2-user/id_rsa
echo 'StrictHostKeyChecking no' >> /etc/ssh/ssh_config
export COMPOSER_HOME=/root
COMPOSER_HOME=/root
/opt/elasticbeanstalk/support/composer.phar install --no-interaction
container_commands:
01-run-composer:
command: "/home/ec2-user/sshgit/composer.sh"
Just wanted to point out that there's an easier (maybe riskier) way to do this by adding this to composer.json:
"config": {
"github-oauth": {
"github.com": "YOUR-OAUTH-KEY"
}
}
And there's a 3rd way which i did't test, but you can create a ~/.composer/auth.json, and composer will probably understand your tokens there.