doctl
is designed to help manage DigitalOcean resources. You can use it to create Droplets, databases, Kubernetes cluster, etc. If you’re looking to copy files and execute a script on an already existing Droplet, you might want to look at some of the GitHub Actions that exist for working with SHH and SCP. Here’s an example using appleboy/ssh-action and appleboy/scp-action
:
name: Deploy
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Copy file via scp
uses: appleboy/scp-action@master
env:
HOST: ${{ secrets.HOST }}
USERNAME: ${{ secrets.USERNAME }}
PORT: ${{ secrets.PORT }}
KEY: ${{ secrets.SSHKEY }}
with:
source: "."
target: "/opt/app"
- name: Executing remote command
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
USERNAME: ${{ secrets.USERNAME }}
PORT: ${{ secrets.PORT }}
KEY: ${{ secrets.SSHKEY }}
script: cat /opt/app/README.md
This copies the git repo to /opt/app
on the remote machine. Then, just as an example, it runs a remote command cat /opt/app/README.md
A couple things to note:
- It expects the SSH private key, the Droplet’s IP address, the port being used for SSH (e.g. 22), and the username (e.g.
root
) to be configured as GitHub secrets.
- I would strongly recommend creating an SSH key specifically for this action/repo rather than re-using an existing one.
Check out the README files for the specific actions for more info.