Last active
November 7, 2023 06:30
-
-
Save Vincenius/2e3763334562e6266bc11d47aa2158a1 to your computer and use it in GitHub Desktop.
Github Action - Deploy to Linux using password
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: Deploy to Server | |
on: | |
push: | |
branches: [ "main" ] | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Set up SSH agent | |
run: | | |
mkdir -p ~/.ssh | |
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa | |
chmod 600 ~/.ssh/id_rsa | |
- name: SSH into the server and run a command | |
run: | | |
ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa ubuntu@YOUR_IP << 'EOF' | |
echo "Connected!!!" | |
export PATH="$PATH:/root/.nvm/versions/node/YOUR_NODE_VERSION/bin" | |
cd ~/your/application | |
git pull | |
yarn | |
yarn build | |
pm2 restart your-application | |
echo "Deployment done!" | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment