18

I have some directories that I would like to be in my local git repository, but NOT in the remote repository when I deploy to my beanstalk environment.

I have googled a bit, and found a few years old posts like this:

http://blog.beanstalkapp.com/post/38164899272/patterns-for-excluded-deployment-paths

that explain that there is this option somewhere, but I have looked everywhere and cannot find it. I think it must still be there and possibly it's been moved around?

If that helps (though it probably doesn't make any difference), I've got an environment based on the sample node.js application. Where is this option?

Is it possible to do it in a config file in the .ebextensions folder instead?

Gio
  • 841
  • 1
  • 5
  • 11

2 Answers2

59

With the current eb cli v3.x elastic beanstalk supports the .ebignore file. It follows the same format as a .gitignore file and it replaces it on deploy.

If you want to use .ebignore then you need to copy your .gitignore into the file and then add the extra exclusions to the file. If you edit your .gitignore file in the future you will need to replicate any changes into you .ebignore file.

See elastic beanstalk docs for more details

nmott
  • 9,454
  • 3
  • 45
  • 34
  • 3
    This should now be the selected answer. (From the guy who has the currently selected answer) – Nick Humrich May 21 '15 at 22:27
  • Yes, I've selected it now, even though I haven't had a chance to test it as I've been using a (very hacky) workaround. I should probably switch to this solution now – Gio May 22 '15 at 09:28
  • 3
    It's worth noting you need a trailing `/` behind the folder to exclude all of its content. E.g. `node_modules/`. Without it, it will archive and upload the entire folder. – Mirage Jul 15 '16 at 10:28
  • It may not be necessary to synchronize `.gitignore` and `.ebignore` if using the EB CLI's `deploy` command: ["If git is installed, EB CLI uses the git archive command to create a .zip file from the contents of the most recent git commit command."](http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb3-deploy.html) The `git archive` command should respect the contents of `.gitignore`. In this scenario, maybe `.ebignore` further filters what is deployed from the [staging directory](http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#linux-container-commands)? – Carl G Nov 11 '17 at 15:13
  • Indeed, .ebignore does seem to further filter what's not already in .gitignore – Oded Aug 06 '20 at 17:51
  • The being said, it seems you need to copy in the entirety of .gitignore into .ebignore for initial creation. .gitignore doesn't seem to be considered during creation, only during subsequent deploys (probably a bug). I'm basing this on the fact that my archive was >512 MB, until I added the contents of .gitignore to .ebignore, including my local media files. – Oded Aug 06 '20 at 17:59
15

Unfortunately, this is not currently possible. The best workaround right now is to create your own zip and tell the CLI to use it instead. You can do this by adding the following lines to .elasticbeanstalk/config.yml

deploy:
  artifact: /path/to/file.zip

If you can script your zip, you could add an alias like

alias ebdeploy="zip {your zip stuff here}; eb deploy"
Nick Humrich
  • 14,905
  • 8
  • 62
  • 85
  • 1
    Even though this isn't the latest and greatest way to do it; this still works and shows an interesting option. Upvoted. – George Stocker Jun 01 '15 at 14:11
  • @GeorgeStocker any idea how to accomplish this now? The artifact trick definitely doesn't work here. – Emil Ahlbäck Aug 21 '15 at 12:44
  • @EmilAhlbäck I used this trick on the Jewelbots WWW site: https://github.com/Jewelbots/www/commit/790c46681352e74cff4a545e26625cfd9ba6d920 and it worked; if you have an .ebignore file and are using the latest version of the EB CLI, you can just use the .ebignore and deploy normally. – George Stocker Aug 21 '15 at 13:56
  • The artifact trick tended to work randomly for me. Seemed to be an issue with the CLI client. I resorted to addinge verything but my Dockerrun.aws.json file to .ebignore... heh! Thanks for the help & follow up @GeorgeStocker – Emil Ahlbäck Aug 24 '15 at 08:16
  • 1
    @emil even when using artifact deploys, the CLI still respects your commits. So it will only deploy a new version on a new commit unless you use the `--staged` flag. Would that explain the "randomness" you are seeing? – Nick Humrich Aug 24 '15 at 12:51
  • @NickHumrich possibly! Interesting. Thanks for that, I will look into it. – Emil Ahlbäck Aug 25 '15 at 08:20