DeployBot Configuration with Git LFS
I recently started using Git LFS for image and video files in an existing repository. Migrating the repository to Git LFS would be another Odyssean story.
However, since I’m using DeployBot to deploy the repository to a web server, I also had to make sure it would handle the files properly, i.e. the actual image files, not the text pointers would be transferred to the host.
An answer to DeployBot’s “common questions about build tools” says:
Unfortunately, we do not yet support LFS by default. But it is possible to use Git LFS right now by using build tools. Inside the container, you are free to install the LFS plugin and set things up yourself. You could also use a command to install the LFS distribution.
It took me a while to figure out how to do it but I think it now works for my scenario. It’s probably not ideal; I will try to update this post, if I change my configuration. Let me go through what I’ve tried:
First Attempt
I started configuring my own container based on the existing Ubuntu 18.04 one with the
Build commands
apt install git-lfs
git lfs install --system
to install Git LFS and set its Git hooks up.
That alone was not sufficient. Git LFS was set up — so I kept the setting — but text pointers were being deployed.
Second Attempt
In the deployment server settings, by adding the following commands to the Build Tools section
Compile, compress, or minimize your code
cd /source/
git lfs pull
I tried to make Git LFS replace the text pointers with the media files. Yet, text pointers were still being deployed.
Third Attempt
Realizing that the files weren’t being pulled from my original (Github) repository, I modified
Compile, compress, or minimize your code
cd /source/
git remote set-url origin %REPO_URL%
git lfs pull
so that the ”origin” remote was set to my repository, not to some intermediate one by DeployBot.
While this worked, DeployBot viewed all LFS files as different and always deployed all of them again.
Fourth Attempt
Once again, I modified
Compile, compress, or minimize your code
cd /source/
git checkout -b deploy %PREVIOUS_COMMIT%
git remote set-url origin %REPO_URL%
git pull origin %BRANCH%
to only pull the files from my repository that were modified since the last deployed commit.
This worked until I had to roll back for the first time since making these configuration modifications.
Fifth Attempt
So I first made sure that a rollback was not happening by using a conditional statement in
Compile, compress, or minimize your code
cd /source/
if [ %ROLLBACK?% != 1 ]; then
git checkout -b deploy %PREVIOUS_COMMIT%
git remote set-url origin %REPO_URL%
git pull origin %BRANCH%
fi
Sixth Attempt (November 2021 Update)
After some renamed/moved LFS files had — once again — not been properly pulled and deployed, I realized that the “deploy” branch could not be created on DeployBot instances where it already existed (from a recent deployment) resulting in a failed checkout.
By making the option uppercase I think I finally managed to configure DeployBot with Git LFS to my satisfaction. For completeness sake, I’m including all parts of my current configuration, again:
Build commands
apt install git-lfs
git lfs install --system
Compile, compress, or minimize your code
cd /source/
if [ %ROLLBACK?% != 1 ]; then
git checkout -B deploy %PREVIOUS_COMMIT%
git remote set-url origin %REPO_URL%
git pull origin %BRANCH%
fi