Adjust code_update pipeline (#41) #18
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
name: Update Source Code of WebApp on the EC2 | |
on: | |
push: | |
branches: | |
- main | |
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.EC2_HOST }} | |
USER_NAME: ${{ secrets.EC2_USER }} | |
run: | | |
echo "$HOSTANAME" | |
echo "$USER_NAME" | |
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 . | |
set -e | |
if pgrep -f "python3 app.py"; then | |
sudo kill $(pgrep -f "python3 app.py") | |
fi | |
cd /home/$USER_NAME | |
sudo chown -R $USER_NAME:$USER_NAME /home/$USER_NAME | |
sudo rm -rf DALLE-WZIM/ | |
sudo git clone https://github.com/AKhart1/DALLE-WZIM.git | |
ls -la /home/$USER_NAME/DALLE-WZIM | |
cd /home/$USER_NAME/DALLE-WZIM/app/ | |
ls -la /home/$USER_NAME/DALLE-WZIM/app/ | |
sudo nohup python3 app.py > app.log 2>&1 & disown | |
EOF | |