Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to deploy a subdirectory of git repo to elastic beanstalk

I'm fairly new to elastic beanstalk. It was not obvious to me that committing to git was required for deploying, but now I've found in the docs that it uses git archive behind the scenes to make a zip that gets deployed.

How can I deploy a subdirectory of a large project only; without uploading the entire contents of the repo?

Say I have a structure like:

git-repo/
    mobile/
        ios/...
        android/...
    assets/...
    django-app/
        .ebextensions
        manage.py
        site/...
        ...

I want to deploy just django-app and below.

Ideally I'd avoid using subtrees, and avoid other scripts (but scripts would be okay if eb deploy has a way to automate them).

like image 451
owenfi Avatar asked Jul 18 '16 07:07

owenfi


People also ask

How do you deploy codes in Elastic Beanstalk?

Open the Elastic Beanstalk console , and in the Regions list, select your AWS Region. In the navigation pane, choose Environments, and then choose the name of your environment from the list. If you have many environments, use the search bar to filter the environment list. Choose Upload and deploy.

How do you deploy a new application version in Elastic Beanstalk?

On the environment overview page, choose Upload and deploy. Choose Choose file, and then upload the sample application source bundle that you downloaded. The console automatically fills in the Version label with a new unique label. If you type in your own version label, ensure that it's unique.


1 Answers

Assuming you have installed and set up the EB CLI you can create a script to zip your django-app/ folder and then deploy the resulting artefact:

  1. Create a folder in your project root called .ebextensions and inside this folder create a file called config.yml with the following basic contents:

    deploy: artifact: "deploy.zip"

(note the spacing is very important in a yml file, "deploy" should be in the first column, "artifact" in a secod (tab spaced) column)

  1. Create a deploy.sh script in your project root with the following:

    git archive --format=zip HEAD:django-app/ > deploy.zip; eb deploy;

Note: this works very well on Mac and Linux, I've had issues in the past with Windows because of spaces in the user folder structure on Windows.

like image 117
contool Avatar answered Oct 11 '22 01:10

contool