Git submodules are a handy way of segmenting modules and plugins in your code into separate Git repositories. This way you can manage each of those projects individually, each with their own git version histories and issue tracking. This keeps all of your differing parts of the projects separate and clean. The issue is how do you deploy the main project with all of its submodules? This tutorial will cover how I deployed a project containing Git submodules.
The first thing to know about deploying git submodules in a project is it doesn't work. According to Aws elastic beanstalk documentation you can initialize git submodules in the config.yml file. Unfortunately I've never been able to deploy that code correctly; the submodule directories are always empty. This is also an issue when cloning a repo that contains submodules; they are always empty. When you clone a project containing submodules you will use a --recursive flag which will pull all of the code. That is fine for locally - however Elastic Beanstalk uses git to wrap and deploy your project. Somehow the submodules are always left out since there is no way for the project to initialize its' submodules. The only way I've gotten eb to deploy submodules is by using a zipped artifact files and only using the submodules for local file management. Artifacts work perfectly fine. The only real issue you might run into with them is if your artifact file is larger than 512 Mb. Artifacts are limited to that size.
git clone --recursive https://github.com/repot.git
The recursive flag will be sure to grab all of the code attached to the submodules
eb init
Configure the .elasticbeanstalk/config.yml to deploy an artifact instead of Git. Add this to yml file
deploy: artifact: BA-Multi.zip
Also change sc: git
sc: null
This is what my config.yml looked like
branch-defaults: default: environment: null deploy: artifact: Repo.zip global: application_name: BA-Multi default_ec2_keyname: YourAwsEc2SecurityPemFile.pem default_platform: PHP 7.0 default_region: us-east-1 profile: eb-cli sc: null
cd into the main project folder and create your zip file artifact that will be used for deployment
cd /path to project
Create the Zip file artifact. The .git will remove all of the git files from the zip file.
zip -FSr Repo.zip . -x *.git*
eb create
At this point your repo should get deployed to an elastic beanstalk instance. You can ssh into your ec2 unit to make sure that all of the files are correct and everything was deployed correctly. If there were any issues you can fix them with the information about managing the git submodule project. You don't have to create the project again unless you terminate the eb project.
After the app is created and running management requires a different set of commands. The first consideration is grabbing the newest code available.
cd /path to project
git submodule update --recursive --remote
This will go through the submodules and update them all with the most recent code in their master branches
zip -FSr BA-Multi.zip . -x *.git*
Push updates to the running app using eb deploy
eb deploy