Skip to content

Commit

Permalink
cicd: use sh file to restart app in remote
Browse files Browse the repository at this point in the history
  • Loading branch information
hoang-rio committed Nov 26, 2024
1 parent 6608870 commit a9b7256
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
10 changes: 3 additions & 7 deletions .github/workflows/deploy_with_git.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ on:
env:
SSH_KEY_FILE_DIR: .keys
SSH_KEY_FILE_PATH: .keys/deploy_key.pem
SSH_COMMAND_FILE: ssh_command.sh

jobs:
ssh_deploy:
Expand All @@ -24,7 +23,7 @@ jobs:
chmod 600 ${{env.SSH_KEY_FILE_PATH}}
- name: Deploy with git
run: |
echo "cd ${{secrets.SSH_DEPLOY_PATH}} && git pull" >> ${{env.SSH_COMMAND_FILE}}
SSH_DEPLOY_COMMAND="cd ${{secrets.SSH_DEPLOY_PATH}} && git pull"
HAS_PYTHON_CHANGE=true
GIT_CHANGED_FILE=$(git show --name-only)
if [[ $(echo $GIT_CHANGED_FILE | grep ".py") == "" ]]; then
Expand All @@ -35,11 +34,8 @@ jobs:
fi
if [[ $HAS_PYTHON_CHANGE == true ]]; then
echo "kill \$(ps | grep app.py | grep -v grep | awk '{print \$1}') && nohup python app.py &" >> ${{env.SSH_COMMAND_FILE}}
SSH_DEPLOY_COMMAND="$SSH_DEPLOY_COMMAND && ./restart-app.sh"
fi
cat ${{env.SSH_COMMAND_FILE}}
chmod +x ${{env.SSH_COMMAND_FILE}}
cat ${{env.SSH_COMMAND_FILE}} | ssh -i ${{env.SSH_KEY_FILE_PATH}} -o StrictHostKeyChecking=no ${{secrets.SSH_DEPLOY_USER}}@${{secrets.SSH_DEPLOY_HOST}}
rm -rf ${{env.SSH_COMMAND_FILE}}
ssh -i ${{env.SSH_KEY_FILE_PATH}} -o StrictHostKeyChecking=no ${{secrets.SSH_DEPLOY_USER}}@${{secrets.SSH_DEPLOY_HOST}}
- name: Clean deploy key file
run: rm -rf ${{env.SSH_KEY_FILE_PATH}}
4 changes: 4 additions & 0 deletions restart-app.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
PID=$(ps | grep app.py | grep -v grep | awk '{print \$1}')
echo $PID
kill $PID
nohup python app.py & >> /dev/null
2 changes: 1 addition & 1 deletion web_viewer/device_manager.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from aiohttp.aiohttp import web
def register(request: web.Request):
print(request.path)
print(request.url)

0 comments on commit a9b7256

Please sign in to comment.