Skip to content

Commit 8198bf4

Browse files
author
oscarj007
committed
ci: complete blue-green deploy workflow (add kubeconfig, deploy, rollback; enable manual dispatch)
1 parent 78f3423 commit 8198bf4

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Blue-Green Deploy to EKS
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
workflow_dispatch: {}
7+
8+
jobs:
9+
build-and-deploy:
10+
runs-on: ubuntu-latest
11+
env:
12+
IMAGE_NAME: ghcr.io/${{ github.repository }}/myapp
13+
K8S_NAMESPACE: default
14+
AWS_REGION: ${{ secrets.AWS_REGION }}
15+
EKS_CLUSTER_NAME: ${{ secrets.EKS_CLUSTER_NAME }}
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
20+
- name: Configure AWS credentials
21+
if: env.AWS_REGION != ''
22+
uses: aws-actions/configure-aws-credentials@v2
23+
with:
24+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
25+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
26+
aws-region: ${{ secrets.AWS_REGION }}
27+
28+
- name: Set up Docker Buildx
29+
uses: docker/setup-buildx-action@v2
30+
31+
- name: Log in to GitHub Container Registry
32+
uses: docker/login-action@v2
33+
with:
34+
registry: ghcr.io
35+
username: ${{ github.actor }}
36+
password: ${{ secrets.GITHUB_TOKEN }}
37+
38+
- name: Build and push image
39+
id: build
40+
uses: docker/build-push-action@v4
41+
with:
42+
push: true
43+
tags: |
44+
"${{ env.IMAGE_NAME }}:latest"
45+
"${{ env.IMAGE_NAME }}:${{ github.sha }}"
46+
- name: Configure kubectl (EKS)
47+
if: env.AWS_REGION != ''
48+
run: |
49+
aws eks update-kubeconfig --region ${{ secrets.AWS_REGION }} --name ${{ secrets.EKS_CLUSTER_NAME }}
50+
51+
- name: Deploy (Blue-Green)
52+
env:
53+
IMAGE: ${{ env.IMAGE_NAME }}:${{ github.sha }}
54+
K8S_NAMESPACE: ${{ env.K8S_NAMESPACE }}
55+
run: |
56+
chmod +x ./scripts/blue-green-deploy.sh
57+
./scripts/blue-green-deploy.sh "$IMAGE" "$K8S_NAMESPACE"
58+
59+
- name: Notify on failure and rollback
60+
if: failure()
61+
run: |
62+
chmod +x ./scripts/blue-green-rollback.sh
63+
./scripts/blue-green-rollback.sh "$K8S_NAMESPACE"

0 commit comments

Comments
 (0)