2

I'm trying to deploy a PHP Project using github action

The connection on the target server works but I'm stuck at the part when deployer tries to clone the repository.

I'm storing a private ssh key in the github secret in order to access the server and I try to use the same ssh key to access the github repository (the key is added in the deploy key of the repository).

Here the command that fails :

cd {releasePath} && (/usr/bin/git clone -b "develop" --recursive  git@github.com:arnaudschaeffer/myprivaterepo.git {releasePath} /releases/3 2>&1)
 Command failed with exit code 1: bin/dep deploy staging -vvv

Deployer works from my local environment. I can make it work with both my personnal SSH Keys and the one I've had in a secret in order to connect to the target server.

Here's my github yml file :

# This is a basic workflow to help you get started with Actions
name: Deploy develop

# Controls when the action will run.
on:
  # Triggers the workflow on push or pull request events but only for the main branch
  push:
    branches: [ develop ]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  deploy:
    name: Deploy to develop
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
        with:
          ref: 'develop'
          ssh-key: ${{ secrets.SSH_PRIVATE_KEY }}
          persist-credentials: true

      - name: Setup PHP
        uses: shivammathur/setup-php@v2
        with:
          php-version: 7.4

      - name: Configure SSH
        env:
          SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
          SSH_HOST: ${{ secrets.SSH_HOST }}
          SSH_USER: ${{ secrets.SSH_USER }}
          SSH_PORT: ${{ secrets.SSH_PORT }}
        run: |
          mkdir -p ~/.ssh/
          echo "$SSH_PRIVATE_KEY" > ~/.ssh/staging.key
          chmod 600 ~/.ssh/staging.key
          cat >>~/.ssh/config <<END
            Host github
              Hostname github.com
              IdentityFile ~/.ssh/staging.key
              IdentitiesOnly yes
            Host host_name
              HostName $SSH_HOST
              User $SSH_USER
              Port $SSH_PORT
              IdentityFile ~/.ssh/staging.key
              StrictHostKeyChecking no
          END

      - name: Set Up Deployer
        run: |
          curl -LO https://deployer.org/deployer.phar && mkdir bin && mv deployer.phar bin/dep && sudo chmod +x bin/dep

      # Add deploy key in GitHub account
      - name: Deploy
        uses: deployphp/action@master
        with:
          private-key: ${{ secrets.SSH_PRIVATE_KEY }}
          #Both target server and github known hosts
          known-hosts: ${{ secrets.KNOWN_HOSTS }}
          dep: deploy staging -vvv

Is there some extra step to clone the repository in deployer ?

Thank in advance !

aschaeffer
  • 31
  • 4
  • I found my mistake. Turns out it wasn't related to an authentication issue. In `deploy.php`, you shouldn't allocate tty for git clone, so I should remove `set('git_tty', true);` or explicity set it to false. – aschaeffer Aug 05 '21 at 07:30

0 Answers0