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.
Deploying the Git submodule project
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.
First clone the project
git clone --recursive https://github.com/repot.git
The recursive flag will be sure to grab all of the code attached to the submodules
Start the Elastic Beanstalk app
Configure the .elasticbeanstalk/config.yml to deploy an artifact instead of Git.
Add this to yml file
Also change sc: git
This is what my config.yml looked like
default_platform: PHP 7.0
Create Zip File Artifact
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*
Create the Eb environment
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.
Managing the Git submodule 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 into your main project forlder
cd /path to project
update the repos
git submodule update --recursive --remote
This will go through the submodules and update them all with the most recent code in their master branches
Create the new Zip file artifact
zip -FSr BA-Multi.zip . -x *.git*
Deploy new artifact
Push updates to the running app using eb deploy