Skip to content

Instantly share code, notes, and snippets.

@hrsetyono
Created January 2, 2021 03:36
Show Gist options
  • Save hrsetyono/ba5160476c2435f16926b70d20862fd3 to your computer and use it in GitHub Desktop.
Save hrsetyono/ba5160476c2435f16926b70d20862fd3 to your computer and use it in GitHub Desktop.
Clone Private Github repo to Digital Ocean (with Password)

Warning: This only works if you enable Password authentication in Digital Ocean.

If you want to use Key authentication, most tutorials in Google already cover that.

Step 1 - Create deploy.yml

In your repo, create .github/workflow/deploy.yml containing this:

name: Deploy via SSH
on: push
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
    - name: Deploy app
      uses: appleboy/ssh-action@v0.1.4
      with:
        host: 123.45.67.89
        username: ${{ secrets.DO_USERNAME }}
        password: ${{ secrets.DO_PASSWORD }}
        
        script: |
          cd ~/var/www
          git clone https://${{ secrets.ACCESS_TOKEN }}:x-oauth-basic@github.com/USERNAME/REPO_NAME.git
          echo "Deployment successful to Digital Ocean"

Don't forget to change the target directory (the one you cd into), host IP Address, and github link.

Step 2 - Setup Secrets

In your repo, click "Settings" tab then choose "Secrets" from sidebar.

Enter in these 3 credentials:

  • DO_USERNAME - your Digital Ocean's username
  • DO_PASSWORD - your Digital Ocean's password
  • ACCESS_TOKEN - your Github's access token. Generate it from here https://github.com/settings/tokens

Step 3 - Test it

Push something and see the log in "Actions" tab. A common error is your user has no permission in the specified directory.

Done!

@hrsetyono
Copy link
Author

Hi @pj8912 I haven't tried to deploy 2 websites with 1 repo before, I think it should be doable. You just need to configure the server

@pj8912
Copy link

pj8912 commented Sep 1, 2023

how many .yml files would I need and where?

@hrsetyono
Copy link
Author

Still 1 yml, but you configure the server so the root folder of 1st website is on /admin and the 2nd web is on /main. I don't know the server config for that though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment