Skip to content

Commit 807dfd7

Browse files
authored
Merge pull request #586 from oscarj007/add/blue-green-deploy-workflow
Add/blue green deploy workflow
2 parents 3b35fc0 + 30eeb3e commit 807dfd7

2 files changed

Lines changed: 112 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"

docs/SECRETS.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Adding repository secrets for CI
2+
3+
Use repository secrets to store AWS credentials and cluster name for GitHub Actions. Do NOT commit any keys or kubeconfig files.
4+
5+
Recommended secrets to add (names used by the workflow):
6+
7+
- `AWS_ACCESS_KEY_ID`
8+
- `AWS_SECRET_ACCESS_KEY`
9+
- `AWS_REGION`
10+
- `EKS_CLUSTER_NAME`
11+
12+
Add via GitHub UI:
13+
14+
1. Go to your repository on GitHub.
15+
2. Settings → Secrets and variables → Actions → New repository secret.
16+
3. Add each secret with the names above.
17+
18+
Add via GitHub CLI (`gh`) if you have it authenticated:
19+
20+
```bash
21+
gh secret set AWS_ACCESS_KEY_ID -b "<your-access-key-id>"
22+
gh secret set AWS_SECRET_ACCESS_KEY -b "<your-secret-access-key>"
23+
gh secret set AWS_REGION -b "us-east-1"
24+
gh secret set EKS_CLUSTER_NAME -b "strellerminds-staging"
25+
```
26+
27+
Local testing (temporary environment variables):
28+
29+
For Bash/WSL:
30+
```bash
31+
export AWS_ACCESS_KEY_ID="<your-access-key-id>"
32+
export AWS_SECRET_ACCESS_KEY="<your-secret-access-key>"
33+
export AWS_REGION="us-east-1"
34+
export EKS_CLUSTER_NAME="strellerminds-staging"
35+
```
36+
37+
For PowerShell (temporary for session):
38+
```powershell
39+
$env:AWS_ACCESS_KEY_ID="<your-access-key-id>"
40+
$env:AWS_SECRET_ACCESS_KEY="<your-secret-access-key>"
41+
$env:AWS_REGION="us-east-1"
42+
$env:EKS_CLUSTER_NAME="strellerminds-staging"
43+
```
44+
45+
After setting secrets or environment variables, the workflow can be triggered manually from Actions (select the `Blue-Green Deploy to EKS` workflow and click "Run workflow") or by pushing to `main`.
46+
47+
PR link (branch pushed by me):
48+
49+
https://github.com/oscarj007/StrellerMinds-SmartContracts/pull/new/add/blue-green-deploy-workflow

0 commit comments

Comments
 (0)