(c) 2025 Mark Himsley
This repository contains a Docker build file to create an Open Container Initiative (OCI) image containing Gitolite and an OpenSSH server.
This repository also contains example Kubernetes kubectl kustomize manifest fragments to create a Gitolite instance accessed by public-key auth SSH, running as a StatefulSet in a Kubernetes cluster. The example Kubernetes manifest fragments assume that some highly available NFS storage is available for storing persistent data.
Please make sure you are familiar with Gitolite, OpenSSH server, building and publishing OCI images with Docker and Kubernetes.
The OCI image will be useful for self-hosting your private git repositories. It should be more secure than running a bare metal server or virtual machine running Gitolite.
The image could be run as a stand-alone Docker container, but I'm not interested in that.
An image has been published to GitHub's Container registry ghcr.io/himslm01/gitolite:v3.6.13.
The Dockerfile and entry point shell script entrypoint.sh are located in the src folder.
I assume you'll be pushing the built OCI image to a local repository, so these are the commands you'll need to run from a shell at the root of this repository.
docker build -t <your-repository>/gitolite:v3.6.13 src/
docker push <your-repository>/gitolite:v3.6.13
This assumes that you have persistent storage available that you can make a PersistentVolume point to, via NFS or something similar.
- Make a new kubectl kustomize override directory by copying the directory
override/exampleand its contents to a new directory within theoverridedirectory.pushd src/override cp -va example foo popd - Create or copy your ssh host keys into the
sshfolder within your newly created override folder. See below for creating ssh host keys. - If you have built your own OCI image and pushed it to your repository, edit the file
kustomization.yamlto replace the current values forimages/newNameandimages/newTagwith your repository, image name, and tag. - Edit the file
env.propertiesto set the four environment variables for:GIT_UIDthe user ID that thegituser will run as in your containerGIT_GIDthe group ID that thegituser will run as in your containerGITOLITE_ADMIN_PUBKEYonly used when creating a new set of git repositories managed by Gitolite, this is the first public key which will have access to administer the Gitolite instance. See the-pkoptionGITOLITE_ADMIN_USERNAMEonly used when creating a new set of git repositories managed by Gitolite, this is the name of the first public key. Seeyournamein the-pkoption
- Edit the file
service-patch.yamlto set theloadBalancerIPaddress for thesshdservice. - Edit the file
persistentVolume.yamlto point to your storage.
These kubectl kustomize manifest fragments assume that you will deploy the Gitolite system into a new namespace called gitolite. If that is not the case then edit the files kustomization.yaml and namespace.yaml to set the namespace you will use.
Now you should be ready to deploy Gitolite into your Kubernetes cluster. Check that the kustomized yaml manifests are correct by running kubectl kustomize against your override folder.
kubectl kustomize src/override/foo
When you believe the output is correct, apply that to your kubernetes cluster.
kubectl kustomize src/override/foo | kubectl apply -f - --context <cluster-name>
The OCI image runs an SSH server. The SSH config file and host keys must be provided to the container at run time. They are stored within a secret in Kubernetes and mounted as a volume onto the container.
The example kubernetes kustomize manifest fragments expect four key-pairs to be stored in the folder ssh in the override folder you create for your deployment.
If you need to create those keys you can do so using these commands.
pushd src/override/foo/ssh
ssh-keygen -q -t dsa -N '' -f ssh_host_dsa_key
ssh-keygen -q -t ecdsa -b 521 -N '' -f ssh_host_ecdsa_key
ssh-keygen -q -t ed25519 -N '' -f ssh_host_ed25519_key
ssh-keygen -q -t rsa -b 4096 -N '' -f ssh_host_rsa_key
popd
This repository was created to migrate an unmaintained VM running Gitolite into a Kubernetes cluster.
This assumes that:
- the user which Gitolite is running as on the bare metal or virtual machine is
git - the home directory of the
gituser is~git - the repositories directory is at
~git/repositorieson the original server - you have some persistent storage that can hold all of the repositories data and the other data held in the
~gitfolder
In my instance I had, for many years, run Gitolite in a small VM with the repositories stored on a NAS mounted with NFS.
As described in the odds and ends page in the Gitolite documentation, it's okay to move the repositories folder to wherever you want and replace it with a symlink pointing to the new location. This is what I had done, with repositories being stored on a NAS, mounted onto a directory with autofs, and a symbolic link at ~git/repositories pointing to that mount point.
When the Gitolite VM was quiescent (I stopped the sshd service) I copied the following files and directories onto the NFS NAS server:
~git/.gitolitedirectory~git/.gitolite.rcfile~git/projects.listfile~git/.sshdirectory
cd ~git
cp -var .gitolite .gitolite.rc projects.list .ssh /<NAS mount point>/
On the NAS server I ended up with /export/git/home_git and /export/git/repositories. This allowed me to have one Kubernetes PV mounting the /export/git directory, one Kubernetes PVC exposing that to the Gitolite pod, and use the subPath: home_git and subPath: repositories to mount those as volumes into the Gitolite container.
If the gitolite-shell on the source machine was not located at /opt/gitolite/src/gitolite-shell, as it is in this image, then you will need to edit .ssh/authorized_keys to replace the old location with /opt/gitolite/src/gitolite-shell.
My previous VM was based on Ubuntu and had the Gitolite deb package installed. Gitolite was installed in /usr/shared/gitolite3/. I had to edit .ssh/authorized_keys. Since I have quite a lot of keys I used vim's global edit function to replace all instances of /usr/shared/gitolite3/gitolite-shell with /opt/gitolite/src/gitolite-shell. The magic vim incantation was:
:%s!/usr/shared/gitolite3/gitolite-shell!/opt/gitolite/src/gitolite-shell!g
I am not interested in running the image on plain-old-Docker. But if you wanted to, you could run the OCI image as a local Docker container to host your Gitolite managed repositories in local Docker volumes.
docker run \
--rm \
--name gitolite \
--env GIT_UID=1001 \
--env GIT_GID=1001 \
--env "GITOLITE_ADMIN_PUBKEY=ssh-rsa AAAAB3NzaC1yc2...7HSYSw0r+ANk=" \
--env GITOLITE_ADMIN_USERNAME=admin \
--mount type=bind,src=$PWD/sshd,dst=/sshd,ro \
--mount type=volume,src=gitolite-home,dst=/home/git \
--mount type=volume,src=gitolite-repositories,dst=/repositories \
--publish 2222:2222 \
<your-repository>/gitolite:v3.6.13
Or you could run the OCI image as a local Docker container to host your Gitolite managed repositories in remote NFS accessible volumes.
docker run \
--rm \
--name gitolite \
--env GIT_UID=1001 \
--env GIT_GID=1001 \
--env "GITOLITE_ADMIN_PUBKEY=ssh-rsa AAAAB3NzaC1yc2...7HSYSw0r+ANk=" \
--env GITOLITE_ADMIN_USERNAME=admin \
--mount type=bind,src=$PWD/sshd,dst=/sshd,ro \
--mount "type=volume,dst=/repositories,volume-driver=local,volume-opt=type=nfs,volume-opt=device=:/export/git/repositories,\"volume-opt=o=addr=nas.lan,rw,nosuid,noatime\"" \
--mount "type=volume,dst=/home/git,volume-driver=local,volume-opt=type=nfs,volume-opt=device=:/export/git/home_git,\"volume-opt=o=addr=nas.lan,rw,nosuid,noatime,\"" \
--publish 2222:2222 \
<your-repository>/gitolite:v3.6.13
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
