Skip to content

Commit

Permalink
Update deploy.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
farooqpk authored Sep 17, 2024
1 parent 1589953 commit 9c32456
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,33 +31,33 @@ jobs:
echo "Pushing Docker image to Docker Hub..."
docker push ${{ secrets.DOCKER_USERNAME }}/talker:latest
echo "Docker image pushed successfully."
# Add host key to known_hosts
- name: Add host key to known_hosts
run: |
mkdir -p ~/.ssh
ssh-keyscan -H ${{ secrets.VPS_HOST }} >> ~/.ssh/known_hosts
# Deploy to VPS
- name: Deploy to VPS
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.VPS_HOST }}
username: ${{ secrets.VPS_USERNAME }}
key: ${{ secrets.VPS_SSH_KEY }}
script_stop: true
command_timeout: 200m
script: |
echo "Starting deployment to VPS..."
# Disable strict host key checking for this session
mkdir -p ~/.ssh
echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config
# Ensure necessary directories exist on the VPS
# echo "Creating necessary directories on the VPS..."
# sudo mkdir -p /home/${{ secrets.VPS_USERNAME }}/app /etc/nginx
# Copy docker-compose.yml to VPS
echo "Copying docker-compose.yml to VPS..."
scp ./docker-compose.yml ${{ secrets.VPS_USERNAME }}@${{ secrets.VPS_HOST }}:/home/${{ secrets.VPS_USERNAME }}/app
scp -o StrictHostKeyChecking=no ./docker-compose.yml ${{ secrets.VPS_USERNAME }}@${{ secrets.VPS_HOST }}:/home/${{ secrets.VPS_USERNAME }}/app
# Copy and update nginx.conf on VPS
echo "Copying and updating nginx.conf on VPS..."
scp ./nginx/default.conf ${{ secrets.VPS_USERNAME }}@${{ secrets.VPS_HOST }}:/tmp/default.conf
ssh ${{ secrets.VPS_USERNAME }}@${{ secrets.VPS_HOST }} "envsubst '\$PORT' < /tmp/default.conf > /etc/nginx/nginx.conf"
scp -o StrictHostKeyChecking=no ./nginx/default.conf ${{ secrets.VPS_USERNAME }}@${{ secrets.VPS_HOST }}:/tmp/default.conf
ssh -o StrictHostKeyChecking=no ${{ secrets.VPS_USERNAME }}@${{ secrets.VPS_HOST }} "envsubst '\$PORT' < /tmp/default.conf > /etc/nginx/nginx.conf"
# SSH into the VPS and restart containers using Docker Compose
echo "Restarting Docker containers on the VPS..."
ssh ${{ secrets.VPS_USERNAME }}@${{ secrets.VPS_HOST }} '
ssh -o StrictHostKeyChecking=no ${{ secrets.VPS_USERNAME }}@${{ secrets.VPS_HOST }} '
cd /home/${{ secrets.VPS_USERNAME }}/app &&
docker-compose down &&
docker-compose pull &&
Expand Down

0 comments on commit 9c32456

Please sign in to comment.