Skip to content

Commit

Permalink
Added CI/CD Pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
anoopkarnik committed Jun 12, 2024
1 parent bafeea0 commit cecace2
Showing 1 changed file with 6 additions and 22 deletions.
28 changes: 6 additions & 22 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@ jobs:
- name: Check Out Repo
uses: actions/checkout@v2

- name: Determine Changed Directories
id: changes
uses: tj-actions/changed-files@v34
with:
files: |
apps/**/*

- name: Log in to Docker Hub
uses: docker/login-action@v1
Expand All @@ -27,14 +21,9 @@ jobs:

- name: Build and Push Docker image
run: |
for dir in $(echo "${{ steps.changes.outputs.modified_files }}" | tr ',' '\n' | sed 's|^\([^/]*\)/\([^/]*\).*|\1/\2|' | sort | uniq); do
if [[ $dir == apps/* ]]; then
app_name=$(basename $dir)
echo "Building and pushing $app_name"
docker-compose build $app_name
docker-compose push $app_name
fi
done
docker-compose build
docker-compose push
- name: Deploy to EC2
uses: appleboy/ssh-action@master
Expand All @@ -45,11 +34,6 @@ jobs:
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
script: |
CHANGED_APPS=$(echo "${{ steps.changes.outputs.modified_files }}" | tr ',' '\n' | sed 's|^\([^/]*\)/\([^/]*\).*|\1/\2|' | sort | uniq | grep '^apps/' | xargs -n 1 basename)
cd /home/ubuntu/saas-apps
for app in $CHANGED_APPS; do
echo "Deploying $app"
cd /home/ubuntu/saas-apps && sudo docker-compose pull $app
cd /home/ubuntu/saas-apps && sudo docker-compose rm -f $app
cd /home/ubuntu/saas-apps && sudo docker-compose up -d $app
done
cd /home/ubuntu/saas-apps && sudo docker-compose pull
cd /home/ubuntu/saas-apps && sudo docker-compose rm -f
cd /home/ubuntu/saas-apps && sudo docker-compose up -d

0 comments on commit cecace2

Please sign in to comment.