aws / elastic-beanstalk-roadmap

AWS Elastic Beanstalk roadmap
https://aws.amazon.com/elasticbeanstalk/
Creative Commons Attribution Share Alike 4.0 International
283 stars 11 forks source link

Environment Dependant Hooks #71

Open dragoonis opened 4 years ago

dragoonis commented 4 years ago

I have hooks in .platform/hooks/postdeploy/xxxx.sh This application is being deployed on staging and production.

I was some hooks to deploy on prod, and others to deploy on staging.

How can I have sets of hooks run, based on the environment name?

dragoonis commented 4 years ago

/cc @Sekhar-Kutikuppala

dragoonis commented 4 years ago

/cc @chadhayton

dragoonis commented 4 years ago

/cc @jsheld

dragoonis commented 4 years ago

I'm sorry for the spam guys. I have a deadline due tomorrow, and this is blocking me.

dragoonis commented 4 years ago

@chadhayton @jsheld @Sekhar-Kutikuppala

What I'm saying is, is this already a feature of EB AL2? Having hooks run on specific environments? (prod only), or not.

If it is a feature can you just link me to your docs.

If it's not, what are your opinions on adding it?

remarkusable commented 4 years ago

@dragoonis you can use the environment variables for this, see https://aws.amazon.com/premiumsupport/knowledge-center/elastic-beanstalk-pass-variables/

for example set APP_ENV=production on EB of production server and APP_ENV=staging for staging server. then your bash script can use it to determine the deployment tasks

remarkusable commented 4 years ago

i see you are using EB Amazon Linux 2, not sure which platform you're using but in the case of PHP 7.4, my suggestion above won't work straight forward as the ENV variables are not set in the shell and only set in PHP-FPM, see: https://github.com/aws/elastic-beanstalk-roadmap/issues/72

dsentker commented 4 years ago

Same here! I want to run different shell scripts, depending on the environment is currently performing the deploy. I have a workaround that uses get-config:

#!/bin/bash
EB_ENV=$(/opt/elasticbeanstalk/bin/get-config environment -k APP_ENV)
case "$EB_ENV" in
  app-pp)          SYMFONY_ENV=preproduction ;;
  app-production)  SYMFONY_ENV=prod ;;
  *)                    SYMFONY_ENV=dev ;;
esac

But that just doesn't feel right.