DEV Community

Cover image for How to deploy git submodules to CapRover
Alejandro Akbal
Alejandro Akbal

Posted on • Originally published at blog.akbal.dev

3 2

How to deploy git submodules to CapRover

Introduction

In this tutorial I will explain how to get git submodules to deploy correctly to CapRover using the CapRover CLI.


Before we start

Preface

Having some knowledge about CapRover, Docker and Git will help you understand how this solution works.


The problem

When you use caprover deploy, what happens underneath is that the CLI uses git archive to make a compressed tar of your repository. It then sends and deploys that file to your CapRover server.

But there are some problems with git archive:
It does NOT include the .git directory in the tar.

So what you end up deploying is not really a git repository...

And if you were using git submodules in your repository, they are not downloaded, since the .git directory is missing.

To solve that issue, I have found a solution that is separated into three steps.


First step: Create a Dockerfile

The first step to use git submodules in CapRover is to create a Dockerfile and download the git submodules as a build step.

You will need to create a captain-definition file and point it to a Dockerfile.

For example:

{
  "schemaVersion": 2,
  "dockerfilePath": "./Dockerfile"
}
Enter fullscreen mode Exit fullscreen mode

Then, you will need to create a Dockerfile that contains the following build step.

RUN git submodule update --init --recursive
Enter fullscreen mode Exit fullscreen mode

For example:

FROM node:15-alpine

COPY . .

RUN apk --no-cache add git

# IMPORTANT: Download git submodules
RUN git submodule update --init --recursive

# ...

RUN npm ci

CMD ["node", "src/main"]
Enter fullscreen mode Exit fullscreen mode

Second step: Include .git directory in the tar

The second step is to improve what caprover deploy does.
Create a tar file of your repository, while adding the .git directory.

For that, you can use the following commands:

# Archive git repository
git archive HEAD > deploy.tar

# Add `.git` directory to `tar`
tar -rf deploy.tar .git
Enter fullscreen mode Exit fullscreen mode

Third step: Deploy the tar

Now that you have both the tar with the .git directory, and a Dockerfile that downloads the git submodules, you are ready to deploy.

# Deploy the `tar` to your CapRover server
npx caprover deploy -t ./deploy.tar

# Remove the tar
rm ./deploy.tar
Enter fullscreen mode Exit fullscreen mode

End

That was it, I hope you had luck and your deployment was successful!

Feel free to use the following script to perform all of these steps automatically.

#!/bin/bash

# Archive git repository
git archive HEAD > deploy.tar

# Add `.git` directory to `tar`
tar -rf deploy.tar .git

# Deploy the `tar` to your CapRover server
npx caprover deploy -t ./deploy.tar

# Remove the tar
rm ./deploy.tar

Enter fullscreen mode Exit fullscreen mode

Self-promotion

If you have found this useful, then you should follow me, I will be posting more interesting content! 🥰

Or support me financially. 💸

Conclusion

Congratulations, today you have learned how to deploy git submodules to your CapRover server.

Let me know if the tutorial was useful to you in the comments!

Image of AssemblyAI tool

Transforming Interviews into Publishable Stories with AssemblyAI

Insightview is a modern web application that streamlines the interview workflow for journalists. By leveraging AssemblyAI's LeMUR and Universal-2 technology, it transforms raw interview recordings into structured, actionable content, dramatically reducing the time from recording to publication.

Key Features:
🎥 Audio/video file upload with real-time preview
🗣️ Advanced transcription with speaker identification
⭐ Automatic highlight extraction of key moments
✍️ AI-powered article draft generation
📤 Export interview's subtitles in VTT format

Read full post

Top comments (0)

Billboard image

Deploy and scale your apps on AWS and GCP with a world class developer experience

Coherence makes it easy to set up and maintain cloud infrastructure. Harness the extensibility, compliance and cost efficiency of the cloud.

Learn more

👋 Kindness is contagious

Explore a sea of insights with this enlightening post, highly esteemed within the nurturing DEV Community. Coders of all stripes are invited to participate and contribute to our shared knowledge.

Expressing gratitude with a simple "thank you" can make a big impact. Leave your thanks in the comments!

On DEV, exchanging ideas smooths our way and strengthens our community bonds. Found this useful? A quick note of thanks to the author can mean a lot.

Okay