Skip to main content

How to Create a Pipeline for Git Submodule Repo

Deploying code from a repository that includes Git submodules can be a bit more complex than a standard repository. This article will guide you through the process of deploying a submodule Git repository on Elestio CI/CD, using a pipeline. We’llCheck useout our example repository to see how the exampleprocess repository [elestio-examples/git-submodule](https://github.com/elestio-examples/git-submodule) to demonstrate the steps.works.

The overall deployment process is similar to deploying a standard repository, as detailed in the [Elestio documentation](https://docs.elest.io/books/cicd-pipelines/page/how-to-deploy-react-app-on-elestio).documentation. However, there are a few additional considerations when deploying a submodule repository with Elestio.
Configuring .gitmodules
For a repository to handle submodules correctly, it must include a .gitmodules file. This file contains the configuration for each submodule, specifying its path, URL, and optionally the branch to be used.

If you want to deploy a submodule Git repository on a particular branch, you need to specify the branch in the .gitmodules file. Here’s an example configuration:

```ini
[submodule "reactjs"]
      path = reactjs
      url = https://github.com/elestio-examples/reactjs.git
      branch = master
```

This configuration tells Git to check out the `master` branch of the `reactjs`reactjs repository.

## Steps to Deploy on Elestio CI/CD

### 1. Clone the Main Repository

First, clone your main repository, which includes the submodule configurations:

```sh
git clone https://github.com/elestio-examples/git-submodule.git
cd git-submodule
```

### 2. Initialize and Update Submodules

After cloning the main repository, initialize and update the submodules:

```sh
git submodule init
git submodule update --remote
```

### 3. Set Up Elestio CI/CD Pipeline

Elestio provides an easy way to set up CI/CD pipelines for your repositories. Here’s how you can configure it for your submodule repository:

1. **Login to Elestio**: Navigate to your Elestio dashboard and log in.
2. **Create a New Project**: Click on "Create New Project" and select "Git Repository".
3. **Configure Repository URL**: Enter the URL of your main repository (e.g., `https://github.com/elestio-examples/git-submodule.git`).
4. **Set Up Pipeline**: Configure your pipeline settings. Make sure to include steps to initialize and update submodules:

    ```yaml
    steps:
      - name: Clone repository
        run: |
          git clone https://github.com/elestio-examples/git-submodule.git
          cd git-submodule
          git submodule init
          git submodule update --remote
      - name: Build and Deploy
        run: |
          # Add your build and deployment commands here
    ```

### 4. Trigger a Deployment

Once your pipeline is configured, trigger a deployment. Elestio will clone your repository, initialize and update the submodules, and then proceed with the build and deployment steps defined in your pipeline configuration.

### 5. Monitor and Verify

Monitor the deployment process through the Elestio dashboard. Ensure that the submodules are correctly initialized and updated. Verify that the deployment has been successful by checking the deployed application or service.

##
 Webhook Considerations

When working with submodules, it's important to note that Git only sends webhooks for changes in the main repository, not for changes only in the submodules. EnsureTherefore, yourif CI/CDyou pipelinemake isany setchanges upin the submodule repository, you need to handlesync thisand appropriately.
commit

those
##changes Conclusion
in

the
Deploying a Gitmain repository withto submodulestrigger onthe webhook. Alternatively, if you commit any changes in the main repository as well, the Elestio CI/CDautomation iswill straightforwardautomatically once you understandfetch the process.latest Bychanges configuring your `.gitmodules` file and setting up your pipeline correctly, you can manage and deploy complex projects with multiple dependencies efficiently.

For more detailed information, refer tofrom the [Elestiosubmodule documentation](https://docs.elest.io/books/cicd-pipelines/page/how-to-deploy-react-app-on-elestio) and the example repository [elestio-examples/git-submodule](https://github.com/elestio-examples/git-submodule).repository.