Skip to content

Commit 7740ec7

Browse files
committed
feat: Add complete DevOps infrastructure with ArgoCD GitOps
- Add ArgoCD Helm deployment via Terraform (argocd.tf) - Update Terraform providers to use kubectl config authentication - Enhance main.tf with improved cluster and resource management - Add ArgoCD application manifest for GitOps deployment - Update CI/CD pipeline with Docker Hub integration - Improve .gitignore to exclude ArgoCD CLI binaries while preserving configs This commit establishes a complete DevOps infrastructure with: - Minikube cluster automation - ArgoCD for GitOps deployments - CI/CD pipeline with Docker Hub integration - Infrastructure as Code with Terraform
1 parent 0362552 commit 7740ec7

6 files changed

Lines changed: 113 additions & 3 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,18 @@ jobs:
8282
run: |
8383
docker push ${{ env.DOCKER_IMAGE }}:${{ env.SHORT_SHA }}
8484
docker push ${{ env.DOCKER_IMAGE }}:latest
85+
- name: Configure Git Author
86+
run: |
87+
git config --local user.email "hello@ozzyi.com"
88+
git config --local user.name "ozzyi0b"
89+
- name: Update Helm Chart with new image tag
90+
run: |
91+
sed -i.bak "s|tag: .*|tag: \"${{ env.SHORT_SHA }}\"|g" devops-project-time/values.yaml
92+
rm devops-project-time/values.yaml.bak
93+
git add devops-project-time/values.yaml
94+
git commit -m "Update Helm chart with new image tag ${{ env.SHORT_SHA }}"
95+
git push
96+
8597
8698
terraform:
8799
needs: [test, build_and_push]

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,8 @@ logs/
6666
# Temporary files
6767
*.tmp
6868
*.temp
69+
70+
# ArgoCD CLI binaries
71+
argocd-darwin-*
72+
argocd-linux-*
73+
argocd-windows-*

argocd-app.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
apiVersion: argoproj.io/v1alpha1
2+
kind: Application
3+
metadata:
4+
name: devops-project
5+
namespace: argocd
6+
spec:
7+
project: default
8+
source:
9+
repoURL: "https://github.com/ozzyib/devops-project"
10+
targetRevision: HEAD
11+
path: devops-project
12+
destination:
13+
server: "https://kubernetes.default.svc"
14+
namespace: default
15+
syncPolicy:
16+
automated:
17+
prune: true
18+
selfHeal: true
19+

argocd.tf

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
resource "helm_release" "argocd" {
2+
count = var.create_k8s_resources ? 1 : 0
3+
4+
name = "argocd"
5+
chart = "argo-cd"
6+
repository = "https://argoproj.github.io/argo-helm"
7+
namespace = kubernetes_namespace.argocd[0].metadata[0].name
8+
version = "9.0.5"
9+
10+
values = [
11+
<<EOF
12+
server:
13+
service:
14+
type: ClusterIP
15+
EOF
16+
]
17+
18+
depends_on = [kubernetes_namespace.argocd]
19+
}

main.tf

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,33 @@ terraform {
44
source = "hashicorp/kubernetes"
55
version = "~> 2.38"
66
}
7+
helm = {
8+
source = "hashicorp/helm"
9+
version = "~> 2.10"
10+
}
11+
minikube = {
12+
source = "scott-the-programmer/minikube"
13+
version = "~> 0.6"
14+
}
715
local = {
816
source = "hashicorp/local"
917
version = "~> 2.1"
1018
}
1119
}
1220
}
1321

22+
# Minikube cluster for local development
23+
resource "minikube_cluster" "minikube_docker" {
24+
count = var.create_k8s_resources ? 1 : 0
25+
26+
driver = "docker"
27+
cluster_name = "devops-project"
28+
addons = [
29+
"default-storageclass",
30+
"storage-provisioner"
31+
]
32+
}
33+
1434
# This is a sample Kubernetes configuration that can be validated in CI
1535
# For local development, you can still use minikube separately
1636
resource "kubernetes_namespace" "devops_app" {
@@ -25,6 +45,19 @@ resource "kubernetes_namespace" "devops_app" {
2545
}
2646
}
2747

48+
# ArgoCD namespace
49+
resource "kubernetes_namespace" "argocd" {
50+
count = var.create_k8s_resources ? 1 : 0
51+
52+
metadata {
53+
name = "argocd"
54+
labels = {
55+
name = "argocd"
56+
app = "argocd"
57+
}
58+
}
59+
}
60+
2861
resource "kubernetes_deployment" "flask_app" {
2962
count = var.create_k8s_resources ? 1 : 0
3063

@@ -103,3 +136,8 @@ output "deployment_name" {
103136
description = "The name of the created Kubernetes deployment"
104137
value = var.create_k8s_resources ? kubernetes_deployment.flask_app[0].metadata[0].name : "Not created (create_k8s_resources = false)"
105138
}
139+
140+
output "argocd_namespace" {
141+
description = "The name of the ArgoCD namespace"
142+
value = var.create_k8s_resources ? kubernetes_namespace.argocd[0].metadata[0].name : "Not created (create_k8s_resources = false)"
143+
}

providers.tf

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,25 @@
1+
# Minikube provider configuration
2+
provider "minikube" {
3+
kubernetes_version = "v1.30.0"
4+
}
5+
16
# Kubernetes provider configuration
27
# For CI/CD: This will be skipped when create_k8s_resources = false
3-
# For local development: Configure this to point to your local cluster
8+
# For local development: Uses kubectl config to connect to existing cluster
49
provider "kubernetes" {
5-
# Only configure if we're actually creating resources
6-
# In CI/CD, validation will work without cluster connection
10+
# Use default kubectl config when creating resources
11+
# Skip cluster connection when create_k8s_resources = false for CI/CD validation
712
config_path = var.create_k8s_resources ? "~/.kube/config" : null
13+
config_context = var.create_k8s_resources ? "devops-project" : null
14+
15+
# Ignore missing context during initial plan
16+
ignore_annotations = []
17+
}
18+
19+
# Helm provider configuration
20+
provider "helm" {
21+
kubernetes {
22+
config_path = var.create_k8s_resources ? "~/.kube/config" : null
23+
config_context = var.create_k8s_resources ? "devops-project" : null
24+
}
825
}

0 commit comments

Comments
 (0)