A few weeks ago AWS CodeCommit became a deprecated service on AWS. This means, customers cannot create new repositories anymore – refer to this announcement for all details: Blog for CodeCommit
There are obviously a lot of alternatives to CodeCommit (Github, Gitlab, …) but if you need a “self-hosted” Git repository in your own AWS account this can become a little bit harder to provision.
If you’re looking for a “self-hosted” Git server, a bunch of tools come up:
As I wanted to be able to deploy something that works “out of the box” I looked at how to provision one of these alternatives on my own AWS account.
Gitness
Gitness is an open source development platform packed with the power of code hosting and automated DevOps pipelines. It’s biggest mantainer is Harness. It includes “way more” than just Git – eg Gitspaces, Pipelines, etc.
Deployment of Gitness
If you want to deploy Gitness, the docs point you at running it locally using Docker, or by deploying it on EC2 or k8s.
My aim was to “only” make the “Git” component available and because of that I’ve chosen Amazon ECS with EFS as storage to provision Gitness.
Open Source Code for the deployment of Gitness
I’ve set up a project on Github where all of the code examples are available for you to look at:
https://github.com/Lock128/setup-gitness
In the rest of the article, I’ll try to walk you through the most important parts of the project.
Please note that this code is not production-ready, it is more a PoC to showcase the direction that you could take.
Source Overview
We’re using AWS CDK and Typescript for Infrastructure As Code (IaC).
We have a “bin” directory where the main application is and a “lib” directory where the “Cloudformation Stack” is.
The “real code” is in setup-gitness-stack.ts where we create:
- an Amazon EFS – a shared filesystem
- an Amazon ECS Service running on Fargate
Required modifications?
You only need to set up “Secrets” in your repository with the names AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY.
After the initial deployment, you will need to modify the GITNESS_URL_BASE in https://github.com/Lock128/setup-gitness/blob/main/lib/setup-gitness-stack.ts#L104 to point it at the Load Balancer URL that has been set up for you.
Deployment
If you “fork” this repository and then push something to the “main” branch, a Github Action workflow will deploy this to your AWS account.
The deployed CloudFormation stack will contain everythign that you need:
The expected costs for this is roughly 50 USD / month.
Next steps from here
As mentioned above the code presented here is not production ready and it does not allow to use all of the functionalities of Gitness.
Things that you will need to consider / think of when using this code as a starting point:
- What’s the backup schedule for the data on EFS?
- What’s the required scaling policies?
- Do you need a custom domain name?
- Do we need to do security hardening – on the image, on the infrastructure, etc.?
- Do we need to have multiple environments (development / production) for Gitness?
- How to connect to this Git server from your VPC?
- How to automate user creation or tie it to an existing AWS Identity Center?
As you can see, this is just a starting point of your journey to host your own Git Server on AWS 🙂
Please let me know if you have better ideas, suggestions or alternatives!
Views: 299