A mock Git server that creates ephemeral Git repos for testing.
Every request from an unknown user is against a fresh copy of a Git repo, so no changes are preserved.
The service accepts any username and password.
The repo copies are created when they are first accessed, so the workflow is:
- Clone a repo (e.g.
git clone http://localhost:8080/repo/platformhubrepo) - The server creates a temporary copy of the git repo for that request.
- The client can interact with the repo as normal (e.g.
git add,git commit,git push), and the temporary directory will be modified. - The temporary directory is immediately deleted after the request is complete.
The git repo for known users will persit for a short amount of time providing an ephemeral repo. The repos are either explicitly cleaned up, or are deleted as the hosting environment scales to 0, so the lifetime of the ephemeral repos is not guaranteed.
The sample repos exist in repotemplate.tar.bz2. This is to prevent Git from complaining about nested Git repositories in the project.
The unpacktemplate.sh and packtemplate.sh scripts are used to unpack and pack the template repository.
Octopus has a restriction that means a git repo can only be used by one project in any space.
This can be worked around by pointing the project to the repo https://mockgit.octopusdemos.com/uniquerepo/id/projectrepo, where <id> is a unique identifier (e.g. a number). This way, each project can have its own copy of the repo, and they won't conflict with each other.
platformhubrepo: A sample Octopus Platform Hub repoprojectrepo: A sample Octopus CaC project configured to use the process template inplatformhubrepoargocd: A sample Argo CD project repo.blank#: Blank repos. Replace#with a number between 1 and 10.
Repos are cloned with the command:
git clone https://<unique user name>@mockgit.octopusdemos.com/repo/<repo name>For example:
git clone https://whatever@mockgit.octopusdemos.com/repo/platformhubrepoStart the server using the pre-built image from GitHub Container Registry:
docker run -d --name mockgitserver -p 8080:8080 ghcr.io/OctopusSolutionsEngineering/mockgitrepo:latestOr with Podman:
podman run -d --name mockgitserver -p 8080:8080 ghcr.io/OctopusSolutionsEngineering/mockgitrepo:latestConfiguration environment variables:
GIT_PROJECT_ROOT: Base path containing source repositories (default:/data/repos).GIT_TEMP_ROOT: Base path for temporary repository copies created per request (default: system temp directory).
GIT_TEMP_ROOT usually points at a mounted network file share, where the first copy of
a repository for a user is slow enough to time out the request that triggers it. Clones
and fetches do not write to the repository, so when the copy on the share is missing
they are served from a second copy under /tmp while the share is populated in the
background. Pushes always use the copy on the share, and once that copy exists every
request uses it.
Anonymous users are only ever served from /tmp, because their copy is deleted as soon
as the request that created it finishes and so never needs to reach the share.
Clone the repository (you must provide a username in the URL):
cd /tmp
git clone http://myusername@localhost:8080/repo/platformhubrepoBuild the Docker image:
docker build -t mockgitserver .Run the locally built image:
docker run -d --name mockgitserver -p 8080:8080 mockgitserverThis application is hosted on Azure. The follow commands demonstrate how you can clone and then interact with the repo.
git clone https://blahblah@mockgit.octopusdemos.com/repo/platformhubrepo
cd platformhubrepo
touch newfile.txt
git add newfile.txt
git commit -m "Add new file to test commit"
git push origin main
git pull
# Git will report a "forced update" with the changes reverted- Run
unpacktemplate.shto unpack the template repo intorepotemplate - Add a directory in
repotemplate - Run
git initin the new directory - Run
git config http.receivepack truein the new directory - Add template files
- Run
git add .andgit commit -m "Add new sample repo" - Run
git checkout -b mainto create the main branch - Run
git config --bool core.bare true - Run
git config receive.denyNonFastForwards falseto allow non-fast-forward pushes (e.g. force pushes) - Enter the root of the template repo e.g.
cd ../.. - Run
packtemplate.shto pack the template repo intorepotemplate.tar.bz2
- Run
unpacktemplate.shto unpack the template repo intorepotemplate - Enter the directory of the repo you want to update e.g.
cd repotemplate/argocd - Run
git config --bool core.bare false - Make changes to the repo
- Run
git add .andgit commit -m "Update sample repo" - Run
git config --bool core.bare true - Enter the root of the template repo e.g.
cd ../.. - Run
packtemplate.shto pack the template repo intorepotemplate.tar.bz2
These are the commands chained up:
git config --bool core.bare false; git add .; git commit -m "Update sample repo"; git config --bool core.bare true; cd ../..curl -X PUT -H "X_MOCKGIT_SERVICE_API_KEY: tokengoeshere" -d '{"data":{"type": "credentials", "id": "user1", "attributes": {"password": "blah"}}}' http://localhost:8080/api/credentials You must enable session affinity (sticky sessions) on the Azure App Service to ensure that all requests from a client go to the same instance of the application. This is necessary because the application creates and maintains a temporary copy of the Git repo for each user, and switching between instances means you persist changes to one instance and then read the repo from another instance where the changes don't exist.