Skip to content

Commit 4a4800c

Browse files
committed
fix build
1 parent ff3c1b0 commit 4a4800c

1 file changed

Lines changed: 33 additions & 27 deletions

File tree

.github/workflows/build.yml

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,79 +10,85 @@ jobs:
1010
runs-on: ubuntu-latest
1111

1212
steps:
13-
- name: Checkout code
13+
- name: 📥 Checkout code
1414
uses: actions/checkout@v2
1515

16-
- name: Set up Python
16+
- name: 🐍 Set up Python
1717
uses: actions/setup-python@v2
1818
with:
1919
python-version: '3.8'
2020

21-
- name: Install dependencies
21+
- name: 📦 Install Python dependencies
2222
run: |
2323
python -m pip install --upgrade pip
2424
pip install -r requirements.txt
2525
26-
deploy_to_production:
26+
deploy-to-production:
2727
runs-on: ubuntu-latest
2828
needs: build-and-test
2929

3030
steps:
31-
- name: Checkout code
31+
- name: 📥 Checkout code
3232
uses: actions/checkout@v2
3333

34-
- name: Configure AWS credentials
34+
- name: 🔐 Configure AWS credentials
3535
run: |
3636
aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS_KEY_ID }}
3737
aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY }}
3838
aws configure set region ${{ vars.AWS_REGION }}
3939
40-
- name: Install AWS CLI & kubectl
40+
- name: 🧰 Install AWS CLI & kubectl
4141
run: |
4242
curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
4343
chmod +x ./kubectl
4444
sudo mv ./kubectl /usr/local/bin/kubectl
4545
pip install --upgrade awscli
4646
aws --version
47+
kubectl version --client
4748
48-
- name: Log in to AWS ECR
49+
- name: 🔐 Authenticate to AWS ECR
4950
run: |
50-
aws ecr get-login-password --region ${{ vars.AWS_REGION }} | docker login --username AWS --password-stdin ${{ vars.IMAGE_REGISTRY }}
51+
aws ecr get-login-password --region ${{ vars.AWS_REGION }} | \
52+
docker login --username AWS --password-stdin ${{ vars.IMAGE_REGISTRY }}
5153
52-
- name: Update kubeconfig for EKS
54+
- name: 🔄 Update kubeconfig for EKS
5355
run: |
5456
aws eks update-kubeconfig --name eks-code2cloud-test --region ${{ vars.AWS_REGION }}
5557
56-
- name: Build Docker image
58+
- name: 🏗️ Build Docker image
5759
run: |
5860
LATEST_SHA=$(git rev-parse HEAD)
5961
echo "LATEST_SHA=$LATEST_SHA" >> $GITHUB_ENV
6062
docker build -t ${{ vars.IMAGE_REGISTRY }}:$LATEST_SHA .
6163
docker tag ${{ vars.IMAGE_REGISTRY }}:$LATEST_SHA ${{ vars.IMAGE_REGISTRY }}:latest
6264
63-
- name: Push Docker image to AWS ECR
65+
- name: 🚀 Push Docker image to AWS ECR
6466
run: |
6567
docker push ${{ vars.IMAGE_REGISTRY }}:$LATEST_SHA
6668
docker push ${{ vars.IMAGE_REGISTRY }}:latest
6769
68-
- name: Deploy to EKS
70+
- name: 🔍 Check if deployment exists
71+
id: check-deployment
6972
run: |
70-
# Set deployment name
7173
DEPLOYMENT_NAME=${{ vars.DEPLOYMENT_NAME }}
72-
73-
# Check if the deployment exists
7474
DEPLOYMENT_EXISTS=$(kubectl get deployment $DEPLOYMENT_NAME -n default --ignore-not-found)
75+
76+
echo "deployment_exists=$([ -z "$DEPLOYMENT_EXISTS" ] && echo "false" || echo "true")" >> $GITHUB_OUTPUT
7577
76-
if [ -z "$DEPLOYMENT_EXISTS" ]; then
77-
echo "Deployment does not exist. Creating deployment."
78-
kubectl create deployment $DEPLOYMENT_NAME --image=${{ vars.IMAGE_REGISTRY }}:$LATEST_SHA -n default
79-
else
80-
echo "Deployment exists. Updating..."
78+
- name: 🛠️ Create deployment (if not exists)
79+
if: steps.check-deployment.outputs.deployment_exists == 'false'
80+
run: |
81+
echo "Creating new deployment: ${{ vars.DEPLOYMENT_NAME }}"
82+
kubectl create deployment ${{ vars.DEPLOYMENT_NAME }} \
83+
--image=${{ vars.IMAGE_REGISTRY }}:$LATEST_SHA -n default
8184
82-
# Automatically detect the container name from the deployment
83-
CONTAINER_NAME=$(kubectl get deployment $DEPLOYMENT_NAME -n default -o jsonpath='{.spec.template.spec.containers[0].name}')
85+
- name: 🔄 Update deployment image (if exists)
86+
if: steps.check-deployment.outputs.deployment_exists == 'true'
87+
run: |
88+
DEPLOYMENT_NAME=${{ vars.DEPLOYMENT_NAME }}
89+
echo "Fetching container name from deployment $DEPLOYMENT_NAME..."
90+
CONTAINER_NAME=$(kubectl get deployment $DEPLOYMENT_NAME -n default -o jsonpath='{.spec.template.spec.containers[0].name}')
91+
echo "Container name detected: $CONTAINER_NAME"
8492
85-
# Use the detected container name to update the image
86-
echo "Container name detected: $CONTAINER_NAME"
87-
kubectl set image deployment/$DEPLOYMENT_NAME $CONTAINER_NAME=${{ vars.IMAGE_REGISTRY }}:$LATEST_SHA -n default
88-
fi
93+
echo "Updating deployment image..."
94+
kubectl set image deployment/$DEPLOYMENT_NAME $CONTAINER_NAME=${{ vars.IMAGE_REGISTRY }}:$LATEST_SHA -n default

0 commit comments

Comments
 (0)