Skip to content

Commit 233c31c

Browse files
author
gurekam
committed
LAP-30: Update GitHub Actions workflow to explicitly use EKS cluster
1 parent ab9fd96 commit 233c31c

File tree

1 file changed

+50
-47
lines changed

1 file changed

+50
-47
lines changed

.github/workflows/ci-cd.yml

Lines changed: 50 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ on:
66
pull_request:
77
branches: [ LAP-30 ]
88

9+
env:
10+
AWS_REGION: us-west-2
11+
EKS_CLUSTER_NAME: spreadsheet-app-cluster
12+
913
jobs:
1014
test:
1115
runs-on: ubuntu-latest
@@ -147,69 +151,68 @@ jobs:
147151
steps:
148152
- uses: actions/checkout@v4
149153

150-
- name: Install Minikube
154+
- name: Configure AWS credentials
155+
uses: aws-actions/configure-aws-credentials@v1
156+
with:
157+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
158+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
159+
aws-region: ${{ env.AWS_REGION }}
160+
161+
- name: Install eksctl
151162
run: |
152-
curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64
153-
chmod +x minikube
154-
sudo mv minikube /usr/local/bin/
163+
curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
164+
sudo mv /tmp/eksctl /usr/local/bin
155165
156-
- name: Start Minikube
166+
- name: Install kubectl
157167
run: |
158-
minikube start --driver=docker
168+
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
169+
sudo install -o root -g root -m 0755 kubectl /usr/local/bin/kubectl
170+
171+
- name: Check if cluster exists
172+
id: check-cluster
173+
run: |
174+
if eksctl get cluster --name ${{ env.EKS_CLUSTER_NAME }} --region ${{ env.AWS_REGION }} 2>/dev/null; then
175+
echo "cluster_exists=true" >> $GITHUB_OUTPUT
176+
else
177+
echo "cluster_exists=false" >> $GITHUB_OUTPUT
178+
fi
159179
160-
# - name: Set up Minikube
161-
# uses: manuel-packeisen/[email protected]
162-
# with:
163-
# minikube version: 'latest'
164-
# kubernetes version: 'v1.28.0'
165-
# driver: 'docker'
166-
# start args: '--cpus=2 --memory=4g --disk-size=20g'
180+
- name: Create cluster if not exists
181+
if: steps.check-cluster.outputs.cluster_exists == 'false'
182+
run: eksctl create cluster -f kubernetes/eks-cluster.yaml
167183

168-
- name: Configure kubectl
184+
- name: Update kubeconfig and set context
169185
run: |
170-
minikube kubectl -- get nodes
171-
minikube kubectl -- config view --flatten > kubeconfig.yaml
172-
export KUBECONFIG=kubeconfig.yaml
186+
aws eks update-kubeconfig --name ${{ env.EKS_CLUSTER_NAME }} --region ${{ env.AWS_REGION }}
187+
kubectl config use-context arn:aws:eks:${{ env.AWS_REGION }}:${{ secrets.AWS_ACCOUNT_ID }}:cluster/${{ env.EKS_CLUSTER_NAME }}
188+
kubectl config current-context
173189
174-
- name: Deploy to Minikube
190+
- name: Deploy to EKS
175191
run: |
176192
# Create namespace if it doesn't exist
177-
minikube kubectl -- create namespace spreadsheet-app --dry-run=client -o yaml | minikube kubectl -- apply -f -
193+
kubectl create namespace spreadsheet-app --dry-run=client -o yaml | kubectl apply -f -
178194
179-
# Deploy application
180-
minikube kubectl -- apply -f kubernetes/ -n spreadsheet-app
195+
# Deploy Redis
196+
kubectl apply -f kubernetes/redis.yaml
197+
198+
# Deploy main application
199+
kubectl apply -f kubernetes/deployment.yaml
200+
201+
# Deploy ingress
202+
kubectl apply -f kubernetes/ingress.yaml
181203
182204
# Update deployment with new image
183-
minikube kubectl -- set image deployment/spreadsheet-app spreadsheet-app=${{ secrets.DOCKERHUB_USERNAME }}/spreadsheet-app:${{ github.sha }} -n spreadsheet-app
205+
kubectl set image deployment/spreadsheet-app spreadsheet-app=${{ secrets.DOCKERHUB_USERNAME }}/spreadsheet-app:${{ github.sha }} -n spreadsheet-app
184206
185207
# Wait for deployment to be ready
186-
minikube kubectl -- rollout status deployment/spreadsheet-app -n spreadsheet-app
208+
kubectl rollout status deployment/spreadsheet-app -n spreadsheet-app
187209
188-
# Get the service URL and test the application
189-
SERVICE_URL=$(minikube service spreadsheet-app-service -n spreadsheet-app --url)
190-
echo "Waiting for service to be available..."
191-
MAX_WAIT=60 # Wait for max 60 seconds
192-
WAITED=0
193-
until curl -f $SERVICE_URL/health || [ $WAITED -ge $MAX_WAIT ]; do
194-
echo "Service not ready yet, waiting..."
195-
sleep 5
196-
WAITED=$((WAITED + 5))
197-
done
198-
199-
if [ $WAITED -ge $MAX_WAIT ]; then
200-
echo "ERROR: Service did not become available in time"
201-
exit 1
202-
fi
203-
204-
echo "Application is available at: $SERVICE_URL"
210+
# Get the service URL
211+
SERVICE_URL=$(kubectl get svc spreadsheet-app-service -n spreadsheet-app -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')
212+
echo "Application is available at: http://$SERVICE_URL"
205213
206214
# Verify all pods are running
207-
minikube kubectl -- get pods -n spreadsheet-app
215+
kubectl get pods -n spreadsheet-app
208216
209217
# Check application logs
210-
minikube kubectl -- logs deployment/spreadsheet-app -n spreadsheet-app
211-
212-
# Verify service is accessible
213-
214-
# Optional: Run additional tests against the deployed application
215-
# Example: curl -f $SERVICE_URL/api/endpoint || exit 1
218+
kubectl logs deployment/spreadsheet-app -n spreadsheet-app

0 commit comments

Comments
 (0)