Search code examples
amazon-web-servicescomposer-phpaws-codepipelineebextensions

.ebextensions - How to add auth credentials to the composer config?


In my Application I have a composer package which requires authorization credentials. It's possible to add the credentials in the composer config via the command: composer.phar config http-basic.##PACKAGE## username password

For deployment, I use AWS CodePipeline. Since I added the package which requires credentials, the deployment process fails on the composer install part.

I added a composer.config inside the .ebextensions folder. Inside the file I execute the command:

container_commands:
  01-app-deploy:
    command: /bin/sh -c composer.phar config http-basic.##PACKAGE## ${USERNAME} ${PASSWORD}

In my understanding the command will run before the composer install happens and it should run the composer install with the correct config. The credentials are loaded from the env variables in my beanstalk configuration.

But somehow the config is (i guess) not configured / the command not executed.

How to add auth credentials to the composer config?


Solution

  • I solved it with using a .platform prebuild hook.

    Created a file: .platform/hooks/prebuild/composer-config-auth.sh

    #!/usr/bin/env bash
    composer.phar config http-basic.##PACKAGE_NAME## ${ENV_USERNAME} ${ENV_TOKEN}