Merge pull request #4 from i-mader/dev #23
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: Continuous Deployment | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
build_and_deployment: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Install dependencies | |
run: npm install | |
- name: Create tarball of the repository | |
run: | | |
mkdir -p archive | |
tar --exclude='./archive' --exclude='./node_modules' --exclude='./.git' -czf archive/i-mader-landing-page.tar.gz . | |
- name: Adding private SSH key to ssh-agent | |
env: | |
SSH_AUTH_SOCK: /tmp/ssh_agent.sock | |
run: | | |
mkdir -p ~/.ssh | |
ssh-agent -a $SSH_AUTH_SOCK > /dev/null | |
ssh-keyscan github.com >> ~/.ssh/known_hosts | |
ssh-add - <<< "${{ secrets.SSH_PRIVATE_KEY }}" | |
- name: scp binary to GCE and apply latest version | |
env: | |
SSH_AUTH_SOCK: /tmp/ssh_agent.sock | |
run: | | |
ssh -o StrictHostKeyChecking=no ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} " | |
rm -rf /root/i-mader-landing-page/* | |
echo '** old files removed **' | |
" | |
scp -o StrictHostKeyChecking=no -r archive/i-mader-landing-page.tar.gz ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }}:/root/i-mader-landing-page | |
ssh -o StrictHostKeyChecking=no ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} " | |
cd i-mader-landing-page && tar -xzf i-mader-landing-page.tar.gz | |
echo '** files extracted **' | |
rm i-mader-lending-page.tar.gz | |
echo "** restarting service tof apply new version **" | |
ls -la /root/i-mader-landing-page # Debugging step to list contents of out directory | |
npm install | |
npm run build | |
pm2 stop i-mader.tech | |
pm2 start npm --name "i-mader.tech" -- start | |
# Save the PM2 process list | |
pm2 save | |
# Set up PM2 to start on system boot | |
pm2 startup systemd | |
echo "** service started **" | |
" || exit 1 |