Skip to content

Commit 16d07ac

Browse files
authored
Update README.md
1 parent b938910 commit 16d07ac

1 file changed

Lines changed: 45 additions & 1 deletion

File tree

README.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,46 @@
11
# gitops-deploy
2-
(Work In Progress) A simple Docker image to use in your CI pipeline and help you commit the right line in your repo containing your Kubernetes .yaml manifests (which will make your GitOps tool trigger the actual deployment)
2+
3+
## Why ?
4+
During my learning of GitOps philosophy, I found out that many of existing tools and articles do assume that you are already taking care of the last step in your CI pipeline to commit / push the right modification in the right file of the Git repo that describes your Kubernetes cluster for example.
5+
And this push will trigger the actual deployment.
6+
7+
It took me some time to achieve this and I was thinking : it's probably sure that some people will face this exact situation in the future during their researches. So I am sharing this simple script here if that can help you to gain some time with that!
8+
9+
It's really possible (I hope not ^^) that I "reinventend the wheel" here so if you know an existing similar repo or way to achieve the exact same purpose, please let me know. I precise that the goal is to avoid the using of an external CLI (like Flux one for example), only git command line, to follow the GitOps philosophy and have a CI pipeline completely independent of the GitOps agent pulling the changes.
10+
11+
## Assumptions of the current script
12+
- the .yaml file you want to modify does only describe 1 Deployment having 1 container
13+
- Deployment name is the same as the Docker image name (like this : repo/**deployment-name**:tag)
14+
15+
## How to build your first gitops-deploy image ?
16+
- simply git clone this repo, if you host it somewhere : make sure this Git repo will be PRIVATE (regarding the SSH key)
17+
- handle the TODO in [Dockerfile](Dockerfile)
18+
- generate a new SSH key and follow the TODO in [id_rsa](id_rsa) and [id_rsa.pub](id_rsa.pub)
19+
- add this SSH key to the Git user you put in [Dockerfile](Dockerfile)
20+
- read [main.sh](main.sh) and adapt it according your needs (do not hesitate to ask questions here!)
21+
22+
- use the [Dockerfile](Dockerfile) to build and push your gitops-deploy image (you can use the [.gitlab-ci.yml](.gitlab-ci.yml) template if host your repo in Gitlab) : make sure your image access will be PRIVATE (regarding the SSH key)
23+
24+
## How to use it ?
25+
- at the end of your CI pipeline, you can use docker CLI directly (if your job has access to it of course) like this :
26+
```
27+
docker run -e CLUSTER_GIT_CLONE_URL=your-url -e YAML_FILE_PATH=your-path ... THE_DOCKER_IMAGE_YOU_BUILT_ABOVE "./main.sh"
28+
```
29+
- if your project is hosted in Gitlab, you can use the equivalent snippet
30+
```
31+
deploy:
32+
stage: deploy
33+
image: THE_DOCKER_IMAGE_YOU_BUILT_ABOVE
34+
dependencies: []
35+
when: manual
36+
variables:
37+
CLUSTER_GIT_CLONE_URL: 'your-url'
38+
YAML_FILE_PATH: 'your-path'
39+
...
40+
script:
41+
- /main.sh
42+
```
43+
44+
## Improvement ideas
45+
- Think about the best way to use a SSH key through a Dockerfile
46+
- Add snippets and templates for other tools

0 commit comments

Comments
 (0)