Skip to content

Commit 33be129

Browse files
committed
CodeDeploy with CICD
1 parent 88d556b commit 33be129

File tree

2 files changed

+34
-25
lines changed

2 files changed

+34
-25
lines changed

.github/workflows/cicd.yaml

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -63,33 +63,42 @@ jobs:
6363
6464
- name: Tag Docker Image
6565
run: |
66-
docker tag text-classification:latest 843369994444.dkr.ecr.eu-north-1.amazonaws.com/text-classification:latest
66+
docker tag text-classification:latest 843369994444.dkr.ecr.eu-north-1.amazonaws.com/text-classification:v3
6767
6868
- name: Push Docker Image to AWS ECR
6969
run: |
70-
docker push 843369994444.dkr.ecr.eu-north-1.amazonaws.com/text-classification:latest
70+
docker push 843369994444.dkr.ecr.eu-north-1.amazonaws.com/text-classification:v3
7171
7272
73-
Deploy-to-EC2:
74-
runs-on: ubuntu-latest
75-
needs: test-and-package
73+
# Deploy:
74+
# runs-on: ubuntu-latest
75+
# needs: test-and-package
7676

77-
steps:
77+
# steps:
7878

79-
- name: Deploy to EC2
80-
uses: appleboy/[email protected]
81-
with:
82-
host: ${{ secrets.EC2_HOST }}
83-
username: ${{ secrets.EC2_USER }}
84-
key: ${{ secrets.EC2_SSH_KEY }}
85-
script: |
86-
aws configure set aws_access_key_id ${{secrets.AWS_ACCESS_KEY_ID }}
87-
aws configure set aws_secret_access_key ${{secrets.AWS_SECRET_ACCESS_KEY }}
88-
aws configure set default.region eu-north-1
89-
90-
aws ecr get-login-password --region eu-north-1 | docker login --username AWS --password-stdin 843369994444.dkr.ecr.eu-north-1.amazonaws.com
91-
92-
docker pull 843369994444.dkr.ecr.eu-north-1.amazonaws.com/text-classification:latest
93-
docker stop text-classification || true
94-
docker rm text-classification || true
95-
docker run -d -p 80:5000 -e DAGSHUB_PAT=${{ secrets.DAGSHUB_PAT }} --name text-classification 843369994444.dkr.ecr.eu-north-1.amazonaws.com/text-classification:latest
79+
80+
# Zip the required files
81+
- name: Zip files for deployment
82+
run: |
83+
zip -r deployment.zip appspec.yml deploy/scripts/install_dependencies.sh deploy/scripts/start_docker.sh
84+
85+
# Upload the ZIP file to S3
86+
- name: Upload ZIP to S3
87+
if: success()
88+
run: |
89+
aws s3 cp deployment.zip s3://text-classification-appspec-bucket/deployment.zip
90+
91+
# Deploy to AWS CodeDeploy using the uploaded ZIP file
92+
- name: Deploy to AWS CodeDeploy
93+
if: success()
94+
run: |
95+
aws configure set aws_access_key_id ${{ secrets.AWS_ACCESS_KEY_ID }}
96+
aws configure set aws_secret_access_key ${{ secrets.AWS_SECRET_ACCESS_KEY }}
97+
aws deploy create-deployment \
98+
--application-name MyDockerApp \
99+
--deployment-config-name CodeDeployDefault.OneAtATime \
100+
--deployment-group-name MyDeploymentGroup \
101+
--s3-location bucket=text-classification-appspec-bucket,key=deployment.zip,bundleType=zip \
102+
--file-exists-behavior OVERWRITE \
103+
--region eu-north-1
104+

deploy/scripts/start_docker.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ aws ecr get-login-password --region eu-north-1 | docker login --username AWS --p
44
# Pull the latest image
55
docker pull 843369994444.dkr.ecr.eu-north-1.amazonaws.com/text-classification:v3
66

7-
# Check if the container 'campusx-app' is running
7+
# Check if the container 'text-classification' is running
88
if [ "$(docker ps -q -f name=text-classification)" ]; then
99
# Stop the running container
1010
docker stop text-classification
1111
fi
1212

13-
# Check if the container 'campusx-app' exists (stopped or running)
13+
# Check if the container 'text-classification' exists (stopped or running)
1414
if [ "$(docker ps -aq -f name=text-classification)" ]; then
1515
# Remove the container if it exists
1616
docker rm text-classification

0 commit comments

Comments
 (0)