From d5bddf7a203c86e0645afe6142a04b934f42d46e Mon Sep 17 00:00:00 2001 From: Alexin Date: Thu, 18 Jul 2024 02:27:45 +0100 Subject: [PATCH] use ssh agent in deploy yml --- .github/workflows/deploy.yml | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 59ad7cb..0d7f5ee 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,47 +1,36 @@ name: Deploy Roomey Project - on: push: branches: - main - jobs: deploy: runs-on: ubuntu-latest if: github.ref == 'refs/heads/main' - steps: - name: Checkout code uses: actions/checkout@v3 - - name: Set up Node.js uses: actions/setup-node@v3 with: node-version: '20' - - name: Install dependencies run: npm install - - name: Build the project run: npm run build - + - name: Set up SSH + uses: webfactory/ssh-agent@v0.5.4 + with: + ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} - name: Copy deployment script - run: | - mkdir -p ~/.ssh - echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa - chmod 600 ~/.ssh/id_rsa - scp -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa ./.github/scripts/deploy.sh ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_IP }}:/home/${{ secrets.SERVER_USER }}/deploy.sh - + run: scp -o StrictHostKeyChecking=no ./.github/scripts/deploy.sh ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_IP }}:/home/${{ secrets.SERVER_USER }}/deploy.sh - name: Deploy to server env: SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} SERVER_USER: ${{ secrets.SERVER_USER }} SERVER_IP: ${{ secrets.SERVER_IP }} run: | - mkdir -p ~/.ssh - echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa - chmod 600 ~/.ssh/id_rsa - ssh -vvv -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_IP }} << 'EOF' + ssh -vvv -o StrictHostKeyChecking=no ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_IP }} << 'EOF' chmod +x /home/${{ secrets.SERVER_USER }}/deploy.sh /home/${{ secrets.SERVER_USER }}/deploy.sh - EOF + EOF \ No newline at end of file