Skip to content

Commit 4e5ec4f

Browse files
committed
Add ArgoCD and Monitoring workflows, refactor CI and deployment scripts for improved structure and clarity
1 parent 4528179 commit 4e5ec4f

File tree

8 files changed

+224
-132
lines changed

8 files changed

+224
-132
lines changed

.github/workflows/argocd.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: ArgoCD Deployment
2+
on:
3+
workflow_dispatch:
4+
workflow_call:
5+
inputs:
6+
image-tag:
7+
description: 'Docker image tag to deploy'
8+
required: false
9+
default: ''
10+
type: string
11+
12+
jobs:
13+
argocd:
14+
name: ArgoCD & Monitoring Deployment
15+
runs-on: ubuntu-latest
16+
environment: production
17+
18+
steps:
19+
- name: Checkout Repository
20+
uses: actions/checkout@v5
21+
22+
- name: Login to AWS
23+
uses: aws-actions/[email protected]
24+
with:
25+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
26+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
27+
aws-region: us-east-1
28+
29+
- name: Update kubeconfig
30+
run: aws eks update-kubeconfig --name ${{ vars.CLUSTER_NAME }} --region us-east-1
31+
32+
- name: Install Helm
33+
uses: azure/[email protected]
34+
with:
35+
version: v3.14.0
36+
37+
- name: Add ArgoCD Helm Repo
38+
run: |
39+
helm repo add argo https://argoproj.github.io/argo-helm
40+
helm repo update
41+
42+
- name: Install/Upgrade ArgoCD
43+
run: |
44+
helm upgrade --install argocd argo/argo-cd \
45+
--namespace ${{ vars.ARGOCD_NAMESPACE }} \
46+
--create-namespace \
47+
--set server.service.type=LoadBalancer \
48+
--wait
49+
50+
- name: Create Application Namespace
51+
run: |
52+
kubectl create namespace ${{ vars.APP_NAMESPACE }} --dry-run=client -o yaml | kubectl apply -f -
53+
54+
- name: Deploy Helm Chart
55+
run: |
56+
helm upgrade --install ${{ vars.APP_NAME }} ./helm \
57+
--namespace ${{ vars.APP_NAMESPACE }} \
58+
--set mongo.uri="${{ secrets.MONGO_URI }}" \
59+
--set mongo.username="${{ secrets.MONGO_USERNAME }}" \
60+
--set mongo.password="${{ secrets.MONGO_PASSWORD }}" \
61+
--set image.tag="${{ inputs.image-tag || github.sha }}"
62+
63+
- name: Deploy ArgoCD Applications
64+
run: |
65+
export APP_NAME=${{ vars.APP_NAME }}
66+
export APP_NAMESPACE=${{ vars.APP_NAMESPACE }}
67+
export ARGOCD_NAMESPACE=${{ vars.ARGOCD_NAMESPACE }}
68+
envsubst < ./argocd/application.yml | kubectl apply -f -

.github/workflows/ci.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,6 @@ on:
88
description: "Test execution result"
99
value: ${{ jobs.code-coverage.outputs.result }}
1010

11-
env:
12-
MONGO_URI: ${{ secrets.MONGO_URI }}
13-
MONGO_USERNAME: ${{ secrets.MONGO_USERNAME }}
14-
MONGO_PASSWORD: ${{ secrets.MONGO_PASSWORD }}
15-
1611
jobs:
1712
unit-testing:
1813
name: Unit Testing

.github/workflows/deploy.yml

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,9 @@ on:
66
image-tag:
77
description: 'Docker image tag to deploy'
88
required: false
9-
default: 'latest'
9+
default: ''
1010
type: string
1111

12-
env:
13-
MONGO_URI: ${{ secrets.MONGO_URI }}
14-
MONGO_USERNAME: ${{ secrets.MONGO_USERNAME }}
15-
MONGO_PASSWORD: ${{ secrets.MONGO_PASSWORD }}
16-
1712
jobs:
1813
deploy:
1914
name: Deploy to Kubernetes
@@ -53,27 +48,4 @@ jobs:
5348
export APP_NAME=${{ vars.APP_NAME }}
5449
export APP_NAMESPACE=${{ vars.APP_NAMESPACE }}
5550
export ARGOCD_NAMESPACE=${{ vars.ARGOCD_NAMESPACE }}
56-
envsubst < ./argocd/application.yml | kubectl apply -f -
57-
58-
- name: Print Service Endpoints
59-
run: |
60-
echo "================= SERVICE ENDPOINTS ================="
61-
62-
ARGOCD_HOST=$(kubectl get svc argocd-server -n ${{ vars.ARGOCD_NAMESPACE }} -o jsonpath='{.status.loadBalancer.ingress[0].hostname}' 2>/dev/null || echo 'Not found')
63-
PROM_HOST=$(kubectl get svc kube-prometheus-stack-prometheus -n ${{ vars.MONITORING_NAMESPACE }} -o jsonpath='{.status.loadBalancer.ingress[0].hostname}' 2>/dev/null || echo 'Not found')
64-
GRAFANA_HOST=$(kubectl get svc kube-prometheus-stack-grafana -n ${{ vars.MONITORING_NAMESPACE }} -o jsonpath='{.status.loadBalancer.ingress[0].hostname}' 2>/dev/null || echo 'Not found')
65-
APP_HOST=$(kubectl get svc ${{ vars.APP_NAME }}-svc -n ${{ vars.APP_NAMESPACE }} -o jsonpath='{.status.loadBalancer.ingress[0].hostname}' 2>/dev/null || echo 'Not found')
66-
67-
echo "ArgoCD: http://$ARGOCD_HOST"
68-
echo "Prometheus: http://$PROM_HOST:9090"
69-
echo "Grafana: http://$GRAFANA_HOST"
70-
echo "App: http://$APP_HOST"
71-
72-
echo "================= DEFAULT CREDENTIALS ================="
73-
ARGOCD_PASS=$(kubectl -n ${{ vars.ARGOCD_NAMESPACE }} get secret argocd-initial-admin-secret -o jsonpath='{.data.password}' 2>/dev/null | base64 -d || echo 'Not found')
74-
75-
echo "ArgoCD -> Username: admin"
76-
echo "ArgoCD -> Password: $ARGOCD_PASS"
77-
echo "Grafana -> Username: admin"
78-
echo "Grafana -> Password: ${{ secrets.GRAFANA_PASSWORD }}"
79-
echo "Prometheus -> No login needed (anonymous access by default)"
51+
envsubst < ./argocd/application.yml | kubectl apply -f -

.github/workflows/docker.yml

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,6 @@ name: Docker Build and Push
33
on:
44
workflow_dispatch:
55
workflow_call:
6-
inputs:
7-
push-image:
8-
description: 'Whether to push the Docker image'
9-
required: false
10-
default: true
11-
type: boolean
12-
outputs:
13-
image-tag:
14-
description: "Docker image tag"
15-
value: ${{ jobs.docker-build.outputs.image-tag }}
16-
17-
env:
18-
MONGO_URI: ${{ secrets.MONGO_URI }}
19-
MONGO_USERNAME: ${{ secrets.MONGO_USERNAME }}
20-
MONGO_PASSWORD: ${{ secrets.MONGO_PASSWORD }}
216

227
jobs:
238
docker-build:
@@ -48,7 +33,7 @@ jobs:
4833
uses: docker/build-push-action@v6
4934
with:
5035
context: .
51-
push: true
36+
push: false
5237
tags: |
5338
docker.io/${{ secrets.DOCKER_USERNAME }}/${{ github.event.repository.name }}:${{ github.sha }}
5439
ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ github.sha }}
@@ -60,15 +45,15 @@ jobs:
6045
6146
# Debug: Check if secrets are available
6247
echo "Checking environment variables:"
63-
echo "MONGO_URI length: ${#MONGO_URI}"
48+
echo "MONGO_URI length: ${#${{ secrets.MONGO_URI }}}"
6449
echo "MONGO_USERNAME: $MONGO_USERNAME"
6550
6651
# Start the container
6752
docker run --name solar-system-app -d \
6853
-p 3000:3000 \
69-
-e MONGO_URI="$MONGO_URI" \
70-
-e MONGO_USERNAME="$MONGO_USERNAME" \
71-
-e MONGO_PASSWORD="$MONGO_PASSWORD" \
54+
-e MONGO_URI="${{ secrets.MONGO_URI }}" \
55+
-e MONGO_USERNAME="${{ secrets.MONGO_USERNAME }}" \
56+
-e MONGO_PASSWORD="${{ secrets.MONGO_PASSWORD }}" \
7257
ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:${{ github.sha }}
7358
7459
# Wait for container to start
@@ -98,7 +83,6 @@ jobs:
9883
fi
9984
10085
- name: Push Docker Image
101-
if: ${{ inputs.push-image != false }}
10286
uses: docker/build-push-action@v6
10387
with:
10488
context: .

.github/workflows/main-pipeline.yml

Lines changed: 70 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,18 @@ on:
1919
required: false
2020
default: false
2121
type: boolean
22+
skip-argocd:
23+
description: 'Skip ArgoCD deployment'
24+
required: false
25+
default: false
26+
type: boolean
27+
skip-monitoring:
28+
description: 'Skip Monitoring deployment'
29+
required: false
30+
default: false
31+
type: boolean
2232
skip-deployment:
23-
description: 'Skip Kubernetes deployment'
33+
description: 'Skip Application deployment'
2434
required: false
2535
default: false
2636
type: boolean
@@ -44,8 +54,10 @@ jobs:
4454
outputs:
4555
app-changed: ${{ steps.changes.outputs.app }}
4656
terraform-changed: ${{ steps.changes.outputs.terraform }}
47-
k8s-changed: ${{ steps.changes.outputs.k8s }}
48-
any-changed: ${{ steps.changes.outputs.app == 'true' || steps.changes.outputs.terraform == 'true' || steps.changes.outputs.k8s == 'true' }}
57+
argocd-changed: ${{ steps.changes.outputs.argocd }}
58+
deployment-changed: ${{ steps.changes.outputs.deployment }}
59+
monitoring-changed: ${{ steps.changes.outputs.monitoring }}
60+
any-changed: ${{ steps.changes.outputs.app == 'true' || steps.changes.outputs.terraform == 'true' || steps.changes.outputs.argocd == 'true' || steps.changes.outputs.deployment == 'true' || steps.changes.outputs.monitoring == 'true' }}
4961
steps:
5062
- name: Checkout
5163
uses: actions/checkout@v5
@@ -69,15 +81,23 @@ jobs:
6981
- '.github/workflows/docker.yml'
7082
terraform:
7183
- 'Terraform/**'
84+
- 'terraform.tfvars'
7285
- '.github/workflows/terraform.yml'
73-
k8s:
86+
argocd:
7487
- 'argocd/**'
88+
- '.github/workflows/argocd.yml'
89+
deployment:
90+
- 'argocd/application.yml'
7591
- '.github/workflows/deploy.yml'
92+
monitoring:
93+
- 'argocd/monitoring.yml'
94+
- '.github/workflows/monitoring.yml'
7695
96+
# App changes: CI + Docker only
7797
ci:
7898
name: Run CI Tests
7999
needs: [detect-changes]
80-
if: ${{ !inputs.skip-tests && (inputs.force-all || needs.detect-changes.outputs.app-changed == 'true' || github.event_name == 'workflow_dispatch') }}
100+
if: ${{ !inputs.skip-tests && (inputs.force-all || needs.detect-changes.outputs.app-changed == 'true') }}
81101
uses: ./.github/workflows/ci.yml
82102
secrets: inherit
83103
permissions:
@@ -88,7 +108,7 @@ jobs:
88108

89109
docker:
90110
name: Build Docker Image
91-
if: ${{ !inputs.skip-docker && (success() || inputs.skip-tests) && (inputs.force-all || needs.detect-changes.outputs.app-changed == 'true' || github.event_name == 'workflow_dispatch') }}
111+
if: ${{ !inputs.skip-docker && (success() || inputs.skip-tests) && (inputs.force-all || needs.detect-changes.outputs.app-changed == 'true') }}
92112
needs: [ci, detect-changes]
93113
permissions:
94114
contents: write
@@ -100,10 +120,11 @@ jobs:
100120
with:
101121
push-image: true
102122

123+
# Terraform changes: Terraform + ArgoCD + Deploy + Monitoring
103124
terraform:
104125
name: Deploy Infrastructure
105-
if: ${{ !inputs.skip-terraform && (success() || (inputs.skip-tests && inputs.skip-docker)) && (inputs.force-all || needs.detect-changes.outputs.terraform-changed == 'true' || github.event_name == 'workflow_dispatch') }}
106-
needs: [docker, detect-changes]
126+
if: ${{ !inputs.skip-terraform && (inputs.force-all || needs.detect-changes.outputs.terraform-changed == 'true') }}
127+
needs: [detect-changes]
107128
uses: ./.github/workflows/terraform.yml
108129
secrets: inherit
109130
permissions:
@@ -114,16 +135,52 @@ jobs:
114135
with:
115136
terraform-action: 'apply'
116137

117-
deploy:
138+
# ArgoCD changes OR when terraform changes
139+
argocd:
140+
name: Deploy ArgoCD Applications
141+
if: ${{ !inputs.skip-argocd && (inputs.force-all || needs.detect-changes.outputs.terraform-changed == 'true' || needs.detect-changes.outputs.argocd-changed == 'true') }}
142+
needs: [detect-changes, terraform]
143+
uses: ./.github/workflows/argocd.yml
144+
secrets: inherit
145+
permissions:
146+
contents: write
147+
packages: write
148+
id-token: write
149+
actions: read
150+
151+
# Deploy when: terraform changes OR application.yml changes
152+
deployment:
118153
name: Deploy Application
119-
if: ${{ !inputs.skip-deployment && (success() || (inputs.skip-tests && inputs.skip-docker && inputs.skip-terraform)) && (inputs.force-all || needs.detect-changes.outputs.k8s-changed == 'true' || needs.detect-changes.outputs.app-changed == 'true' || github.event_name == 'workflow_dispatch') }}
120-
needs: [terraform, docker, detect-changes]
154+
if: ${{ !inputs.skip-deployment && (inputs.force-all || needs.detect-changes.outputs.terraform-changed == 'true' || needs.detect-changes.outputs.deployment-changed == 'true') }}
155+
needs: [detect-changes, argocd]
121156
uses: ./.github/workflows/deploy.yml
122157
secrets: inherit
123158
permissions:
124159
contents: write
125160
packages: write
126161
id-token: write
127162
actions: read
128-
with:
129-
image-tag: ${{ github.sha }}
163+
164+
# Monitoring when: terraform changes OR monitoring.yml changes
165+
monitoring:
166+
name: Deploy Monitoring Stack
167+
if: ${{ !inputs.skip-monitoring && (inputs.force-all || needs.detect-changes.outputs.terraform-changed == 'true' || needs.detect-changes.outputs.monitoring-changed == 'true') }}
168+
needs: [detect-changes, argocd]
169+
uses: ./.github/workflows/monitoring.yml
170+
secrets: inherit
171+
permissions:
172+
contents: write
173+
packages: write
174+
id-token: write
175+
actions: read
176+
177+
# Print service endpoints when any deployment happens
178+
show-endpoints:
179+
name: Show Service Endpoints
180+
if: always() && needs.detect-changes.outputs.any-changed == 'true' && (needs.argocd.result == 'success' || needs.deployment.result == 'success' || needs.monitoring.result == 'success')
181+
needs: [detect-changes, argocd, deployment, monitoring]
182+
uses: ./.github/workflows/endpoints.yml
183+
secrets: inherit
184+
permissions:
185+
contents: read
186+
id-token: write

.github/workflows/monitoring.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Monitoring Deployment
2+
on:
3+
workflow_dispatch:
4+
5+
jobs:
6+
monitoring:
7+
name: Deploy Monitoring Stack
8+
runs-on: ubuntu-latest
9+
environment: production
10+
11+
steps:
12+
- name: Checkout Repository
13+
uses: actions/checkout@v5
14+
15+
- name: Login to AWS
16+
uses: aws-actions/[email protected]
17+
with:
18+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
19+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
20+
aws-region: us-east-1
21+
22+
- name: Update kubeconfig
23+
run: aws eks update-kubeconfig --name ${{ vars.CLUSTER_NAME }} --region us-east-1
24+
25+
- name: Create Grafana Secret
26+
run: |
27+
kubectl create namespace ${{ vars.MONITORING_NAMESPACE }} --dry-run=client -o yaml | kubectl apply -f -
28+
kubectl create secret generic grafana-admin-secret \
29+
--from-literal=admin-user=admin \
30+
--from-literal=admin-password='${{ secrets.GRAFANA_ADMIN_PASSWORD }}' \
31+
--namespace ${{ vars.MONITORING_NAMESPACE }} \
32+
--dry-run=client -o yaml | kubectl apply -f -
33+
34+
- name: Deploy Monitoring
35+
run: |
36+
export MONITORING_NAMESPACE=${{ vars.MONITORING_NAMESPACE }}
37+
export ARGOCD_NAMESPACE=${{ vars.ARGOCD_NAMESPACE }}
38+
envsubst < ./argocd/monitoring.yml | kubectl apply -f -

0 commit comments

Comments
 (0)