Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the automation code #1

Merged
merged 9 commits into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: CI

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
validate-helm:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup Helm
uses: azure/setup-helm@v1
with:
version: v3.8.0

- name: Validate Helm charts
run: |
helm lint helm-charts/redis
helm lint helm-charts/rollouts-demo

terraform-plan:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_version: 1.0.0

- name: Terraform Init
run: terraform init

- name: Terraform Validate
run: terraform validate

- name: Terraform Plan
id: plan
run: terraform plan
5 changes: 5 additions & 0 deletions helm-charts/redis/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
apiVersion: v2
name: redis
description: A Helm chart for Redis
version: 0.1.0
19 changes: 19 additions & 0 deletions helm-charts/redis/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: redis-ingress
spec:
ingressClassName: nginx
rules:
- host: {{ .Values.ingressHost }}
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: service-redis
port:
number: 6379

10 changes: 10 additions & 0 deletions helm-charts/redis/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: Service
metadata:
name: redis-svc
namespace: default
spec:
ports:
- port: 6379
selector:
app: redis
33 changes: 33 additions & 0 deletions helm-charts/redis/templates/statefulset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: redis
namespace: default
spec:
serviceName: "redis"
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app: redis
template:
metadata:
labels:
app: redis
spec:
containers:
- name: redis
image: {{ .Values.image }}
ports:
- containerPort: 6379
volumeMounts:
- name: redis-data
mountPath: /data
volumeClaimTemplates:
- metadata:
name: redis-data
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: {{ .Values.storage }}
5 changes: 5 additions & 0 deletions helm-charts/redis/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
replicaCount: 1
image: "redis:latest"
storage: "1Gi"
ingressHost: "redis.local"
5 changes: 5 additions & 0 deletions helm-charts/rollouts-demo/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
apiVersion: v2
name: rollouts-demo
description: A Helm chart for Rollouts Demo
version: 0.1.0
18 changes: 18 additions & 0 deletions helm-charts/rollouts-demo/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: rollouts-demo-primary
spec:
ingressClassName: nginx
rules:
- host: {{ .Values.ingressHost }}
http:
paths:
- path: /
pathType: Prefix
backend:
service:
name: rollouts-demo-primary
port:
number: 80
38 changes: 38 additions & 0 deletions helm-charts/rollouts-demo/templates/rollout.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
apiVersion: argoproj.io/v1alpha1
kind: Rollout
metadata:
name: rollouts-demo
spec:
replicas: {{ .Values.replicas }}
strategy:
canary:
canaryService: rollouts-demo-canary
stableService: rollouts-demo-primary
trafficRouting:
nginx:
stableIngress: rollouts-demo-primary
steps:
- setWeight: 20
- pause: {}
revisionHistoryLimit: 2
selector:
matchLabels:
app: rollouts-demo
template:
metadata:
labels:
app: rollouts-demo
spec:
containers:
- name: rollouts-demo
image: {{ .Values.image }}
ports:
- name: http
containerPort: 8080
protocol: TCP
resources:
requests:
memory: 32Mi
cpu: 5m

13 changes: 13 additions & 0 deletions helm-charts/rollouts-demo/templates/service-canary.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
apiVersion: v1
kind: Service
metadata:
name: rollouts-demo-canary
spec:
ports:
- port: 80
targetPort: http
protocol: TCP
name: http
selector:
app: rollouts-demo
14 changes: 14 additions & 0 deletions helm-charts/rollouts-demo/templates/service-primary.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
apiVersion: v1
kind: Service
metadata:
name: rollouts-demo-primary
spec:
ports:
- port: 80
targetPort: http
protocol: TCP
name: http
selector:
app: rollouts-demo

4 changes: 4 additions & 0 deletions helm-charts/rollouts-demo/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
replicas: 4
image: "argoproj/rollouts-demo:green"
ingressHost: "rollouts-demo.local"
32 changes: 32 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
provider "kubernetes" {
config_path = "~/.kube/config"
}

provider "helm" {
kubernetes {
config_path = "~/.kube/config"
}
}

resource "helm_release" "redis" {
name = "redis"
chart = "./helm-charts/redis"

values = [
file("./helm-charts/redis/values.yaml")
]
}

resource "helm_release" "rollouts_demo" {
name = "rollouts-demo"
chart = "./helm-charts/rollouts-demo"

values = [
file("./helm-charts/rollouts-demo/values.yaml")
]

provisioner "local-exec" {
command = "kubectl argo rollouts set image rollouts-demo rollouts-demo=argoproj/rollouts-demo:blue"
on_failure = continue
}
}
Loading