Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pre-Deploy Script on ElasticBeanstalk

I'm deploying a rails application to AWS. One of the gem's had a dependency and needs certain files installed on the server before bundle install is run during deployment. In my .ebextensions file I have the following

01-oracle_sdk:
    sources:
      /usr/lib: https://s3-us-west-2.amazonaws.com/xyz/instantclient-sdk-linux.x64-12.2.0.1.0.zip
  02-oracle-basic:
    sources:
      /usr/lib: https://s3-us-west-2.amazonaws.com/xyz/instantclient-basic-linux.x64-12.2.0.1.0.zip
  03-oracle_sql_plus:
    sources:
      /usr/lib: https://s3-us-west-2.amazonaws.com/xyz/instantclient-sqlplus-linux.x64-12.2.0.1.0.zip
  04-container_commands:
    00_oracle_dir:
      command: "export LD_LIBRARY_PATH=/usr/lib/instantclient_12_1"

From what I can tell, none of this is getting run pre-deploy. It fails when it tries to install the gem because that directory is not there. When I SSH into the instance, LD_LIBRARY_PATH is not set and none of the zipfiles were downloaded and unzipped by the source command.

1) Is my syntax in correct 2) How do I get these commands to execute PRE deploy/bundle install?

like image 405
theartofbeing Avatar asked May 05 '26 09:05

theartofbeing


2 Answers

EB has a specific folder where you can execute scripts to run pre-deploy. I created a .config file in my .ebextensions with bash commands I wanted executed pre deploy. It creates a file in "/opt/elasticbeanstalk/hooks/appdeploy/pre/ that gets run

001_script.config

files:
  "/opt/elasticbeanstalk/hooks/appdeploy/pre/001_oracle.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/usr/bin/env bash
      bash commands you want executed here
      ...
      ...
like image 83
theartofbeing Avatar answered May 07 '26 23:05

theartofbeing


First off, .ebextensions is a directory, not a file. Within that directory, you need to create a file with a .config extension.

Also, YAML is very whitespace sensitive, so you need to be consistent with your spacing.

Try this instead (I'm not 100% sure that sources can take multiple files, however - you might need to make three separate .config files...)

.ebextensions/01-oracle.config

sources:
  /usr/lib: https://s3-us-west-2.amazonaws.com/xyz/instantclient-sdk-linux.x64-12.2.0.1.0.zip
  /usr/lib: https://s3-us-west-2.amazonaws.com/xyz/instantclient-basic-linux.x64-12.2.0.1.0.zip
  /usr/lib: https://s3-us-west-2.amazonaws.com/xyz/instantclient-sqlplus-linux.x64-12.2.0.1.0.zip

Finally, setting the LD_LIBRARY_PATH variable in this way won't work; it'll be set for the duration of the deployment, but will not persist. You can set environment variables from the command line using eb setenv, or from the Configuration tab on the ElasticBeanstalk console.

More information can be found in the documentation.

like image 28
Brian Avatar answered May 08 '26 00:05

Brian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!