Skip to content

Commit 26cf684

Browse files
authored
Update build.yml
1 parent 304799c commit 26cf684

1 file changed

Lines changed: 29 additions & 9 deletions

File tree

.github/workflows/build.yml

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
name: CI/CD
1+
name: CI/CD Pipeline
22

33
on:
44
push:
55
branches:
66
- main # or specify your branch here
77

88
jobs:
9-
build-and-push:
9+
build-and-test:
1010
runs-on: ubuntu-latest
1111

1212
steps:
@@ -16,20 +16,35 @@ jobs:
1616
- name: Set up Python
1717
uses: actions/setup-python@v2
1818
with:
19-
python-version: '3.8'
19+
python-version: '3.8' # Change the Python version if needed
2020

2121
- name: Install dependencies
2222
run: |
2323
python -m pip install --upgrade pip
2424
pip install -r requirements.txt
2525
26+
build-and-push-image:
27+
runs-on: ubuntu-latest
28+
needs: build-and-test
29+
steps:
30+
- name: Checkout code
31+
uses: actions/checkout@v2
32+
2633
- name: Set up AWS Credentials
2734
run: |
2835
echo "${{ secrets.AWS_ACCESS_KEY_ID }}" > aws_access_key_id
2936
echo "${{ secrets.AWS_SECRET_ACCESS_KEY }}" > aws_secret_access_key
3037
aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS_KEY_ID }}
3138
aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY }}
32-
aws configure set region ${{ secrets.AWS_REGION }}
39+
aws configure set region ${{ secrets.AWS_REGION }} # Ensure AWS_REGION is set as a secret in GitHub
40+
41+
- name: Install kubectl and AWS CLI
42+
run: |
43+
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
44+
chmod +x ./kubectl
45+
sudo mv ./kubectl /usr/local/bin/kubectl
46+
pip install awscli --upgrade
47+
aws --version
3348
3449
- name: Log in to AWS ECR
3550
run: |
@@ -38,23 +53,28 @@ jobs:
3853
- name: Build Docker image
3954
run: |
4055
LATEST_SHA=$(git rev-parse HEAD)
56+
echo "LATEST_SHA: $LATEST_SHA"
57+
if [[ -z "$LATEST_SHA" ]]; then
58+
echo "Error: LATEST_SHA is empty, aborting."
59+
exit 1
60+
fi
4161
docker build -t ${{ secrets.IMAGE_REGISTRY }}:$LATEST_SHA .
4262
docker tag ${{ secrets.IMAGE_REGISTRY }}:$LATEST_SHA ${{ secrets.IMAGE_REGISTRY }}:latest
4363
4464
- name: Push Docker image to AWS ECR
4565
run: |
66+
echo "Pushing image to AWS ECR..."
4667
docker push ${{ secrets.IMAGE_REGISTRY }}:$LATEST_SHA
4768
docker push ${{ secrets.IMAGE_REGISTRY }}:latest
4869
49-
deploy:
70+
deploy-to-eks:
5071
runs-on: ubuntu-latest
51-
needs: build-and-push # Ensures the deploy job runs only after the build-and-push job
52-
72+
needs: build-and-push-image
5373
steps:
5474
- name: Checkout code
5575
uses: actions/checkout@v2
5676

57-
- name: Set up AWS Credentials
77+
- name: Set up AWS Credentials for EKS deployment
5878
run: |
5979
echo "${{ secrets.AWS_ACCESS_KEY_ID }}" > aws_access_key_id
6080
echo "${{ secrets.AWS_SECRET_ACCESS_KEY }}" > aws_secret_access_key
@@ -64,7 +84,7 @@ jobs:
6484
6585
- name: Update kubeconfig for EKS
6686
run: |
67-
aws eks update-kubeconfig --name ${{ secrets.CLUSTER_NAME }} --region ${{ secrets.AWS_REGION }}
87+
aws eks update-kubeconfig --name ${{ secrets.EKS_CLUSTER_NAME }} --region ${{ secrets.AWS_REGION }}
6888
6989
- name: Check if the deployment exists
7090
id: deployment

0 commit comments

Comments
 (0)