-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
97 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
name: Smart-Exchange-Deployment | ||
|
||
on: | ||
push: | ||
branches: [main, master] | ||
|
||
permissions: | ||
id-token: write | ||
contents: read | ||
|
||
jobs: | ||
Deploy: | ||
name: Deploy Changes to EC2 | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Use Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: "20.x" | ||
|
||
- name: SSH and Deploy | ||
env: | ||
PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} | ||
HOSTNAME: ${{ secrets.EC2_REMOTE_HOST }} | ||
USER_NAME: ubuntu | ||
|
||
run: | | ||
echo "$PRIVATE_KEY" > private_key | ||
chmod 600 private_key | ||
ssh -o StrictHostKeyChecking=no -i private_key ${USER_NAME}@${HOSTNAME} << 'EOF' | ||
# Now we have got the access of EC2 and we will start the deploy. | ||
cd /home/ubuntu/app/smartchange-backend-v1 | ||
sudo systemctl stop smart | ||
git pull | ||
npm install | ||
sudo systemctl restart smart | ||
EOF | ||
rm private_key | ||
# - name: rsync deployments | ||
# uses: burnett01/[email protected] | ||
# with: | ||
# switches: -avzr --delete | ||
# path: ./* | ||
# remote_path: /home/ubuntu/app/smartchange-backend-v1 | ||
# remote_host: ${{ secrets.EC2_REMOTE_HOST }} | ||
# remote_user: ubuntu | ||
# remote_key: private_key | ||
# remote_port: 22 | ||
|
||
# - name: Stop smart service | ||
# run: | | ||
# ssh -o StrictHostKeyChecking=no -i private_key ubuntu@${{ secrets.EC2_REMOTE_HOST }} 'sudo systemctl stop smart' | ||
# continue-on-error: true | ||
|
||
# - name: Start smart service | ||
# run: | | ||
# ssh -o StrictHostKeyChecking=no -i private_key ubuntu@${{ secrets.EC2_REMOTE_HOST }} 'sudo systemctl start smart' | ||
# continue-on-error: true | ||
|
||
# - name: Clean up | ||
# run: rm private_key | ||
# if: always() | ||
|
||
# on: | ||
# push: | ||
# branches: [main, master] | ||
|
||
# jobs: | ||
# Deploy: | ||
# name: Deploy to EC2 | ||
# runs-on: ubuntu-latest | ||
|
||
# steps: | ||
# - uses: actions/checkout@v2 | ||
# - name: Build & Deploy | ||
# env: | ||
# PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} | ||
# HOSTNAME: ${{secrets.SSH_HOST}} | ||
# USER_NAME: ${{secrets.USER_NAME}} | ||
|
||
# run: | | ||
# echo "$PRIVATE_KEY" > private_key && chmod 600 private_key | ||
# ssh -o StrictHostKeyChecking=no -i private_key ${USER_NAME}@${HOSTNAME} ' | ||
|
||
# # Now we have got the access of EC2 and we will start the deploy . | ||
# cd /home/ubuntu/<PROJECT_DIRECTORY> && | ||
# git checkout dev && | ||
# git fetch --all && | ||
# git reset --hard origin/dev && | ||
# git pull origin dev && | ||
# sudo npm i && | ||
# sudo npm run build && | ||
# sudo pm2 stop ./dist/index.js && |