We can use an ssh key we created and copied to our Digital Ocean droplit to test ssh access from GitHub Actions using the appleboy/ssh-action
workflow.
Make sure to specify the keys in the GH secrets panel so the workflow has access to them.
name: remote ssh commandon: [push]jobs:build:name: Buildruns-on: ubuntu-lateststeps:- name: executing remote ssh commandsuses: appleboy/ssh-action@masterwith:host: ${{ secrets.DIGITAL_OCEAN_IP }}username: ${{ secrets.DIGITAL_OCEAN_USER }}key: ${{ secrets.DIGITAL_OCEAN_KEY }}port: 22script: |echo "what"whoami
Successful output will look like this:
======CMD======echo "what"whoami======END======out: whatout: ***==============================================✅ Successfully executed commands to all host.==============================================
Now that we know everything is working, this is a GitHub Action that
scp
s the .tar file to the Digital Ocean Droplitdocker load
to load the tar file as an imagename: build and deploy corgo-boton: [push]jobs:build:name: Buildruns-on: ubuntu-lateststeps:- uses: actions/checkout@v2- name: build docker imagerun: |docker build -t biscarch/corgo-bot .docker save -o corgo-bot.tar biscarch/corgo-bot- name: scp docker image to DOuses: appleboy/scp-action@masterwith:host: ${{ secrets.DIGITAL_OCEAN_IP }}username: ${{ secrets.DIGITAL_OCEAN_USER }}key: ${{ secrets.DIGITAL_OCEAN_KEY }}port: 22source: corgo-bot.tartarget: /opt- name: executing remote ssh commandsuses: appleboy/ssh-action@masterwith:host: ${{ secrets.DIGITAL_OCEAN_IP }}username: ${{ secrets.DIGITAL_OCEAN_USER }}key: ${{ secrets.DIGITAL_OCEAN_KEY }}port: 22script: |docker load -i /opt/corgo-bot.tarrm /opt/corgo-bot.tardocker kill $(docker ps -q)docker run --env-file /opt/corgo-bot.env -d biscarch/corgo-bot:latestdocker system prune -f