diff --git a/.github/workflows/aws-deployment.yml b/.github/workflows/aws-deployment.yml index ee428dc..a440a80 100644 --- a/.github/workflows/aws-deployment.yml +++ b/.github/workflows/aws-deployment.yml @@ -57,10 +57,14 @@ jobs: # Start the application with pm2 pm2 start npm --name "portfolio-app" -- start - + # Deploy the application to EC2 - echo "${{ secrets.EC2_KEY_PAIR }}" | scp -i - -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -r portfolio-app/. ${{ env.EC2_USERNAME }}@${{ env.EC2_PUBLIC_IP }}:${{ env.DEPLOY_PATH }} + echo "${{ secrets.EC2_KEY_PAIR }}" > ec2_key.pem + chmod 600 ec2_key.pem + scp -i ec2_key.pem -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -r portfolio-app/. ${{ env.EC2_USERNAME }}@${{ env.EC2_PUBLIC_IP }}:${{ env.DEPLOY_PATH }} # Restart the application on EC2 using pm2 - echo "${{ secrets.EC2_KEY_PAIR }}" | ssh -i - -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ${{ env.EC2_USERNAME }}@${{ env.EC2_PUBLIC_IP }} "cd ${{ env.DEPLOY_PATH }} && pm2 restart portfolio-app" + ssh -i ec2_key.pem -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ${{ env.EC2_USERNAME }}@${{ env.EC2_PUBLIC_IP }} "cd ${{ env.DEPLOY_PATH }} && pm2 restart portfolio-app" + # Cleanup + rm ec2_key.pem