Question
Automatic deployment using Github Actions, Digital Ocean Registry into a Droplet,
Hi,
I am currently woking on a workflow for my automatic deployment of dockerized application to digital ocean droplet.
Currently I am creating a docker image and pushing it to digital ocean registry using github actions.
Now I want to pull the image into my droplet from digital ocean registry and run the image.
What should be the command I should execute for this?
name: Docker
on:
push:
# Publish `master` as Docker `latest` image.
branches:
- master
# Publish `v1.2.3` tags as releases.
tags:
- v*
# Run tests for any PRs.
pull_request:
env:
# TODO: Change variable to your image's name.
IMAGE_NAME: myimagename
jobs:
# Run tests.
# See also https://docs.docker.com/docker-hub/builds/automated-testing/
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Run tests
run: |
if [ -f docker-compose.test.yml ]; then
docker-compose --file docker-compose.test.yml build
docker-compose --file docker-compose.test.yml run sut
else
docker build . --file Dockerfile
fi
#Push to Digital Ocean private Registry
pushToDORegistry:
# Ensure test job passes before pushing image.
needs: test
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- uses: actions/checkout@v2
- name: Build image
run: docker build . --file Dockerfile --tag $IMAGE_NAME
- name: Install doctl # install the doctl on the runner
uses: digitalocean/action-doctl@v2
with:
token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }}
- name: push image to digitalocean
run: |
doctl registry login
docker tag $IMAGE_NAME registry.digitalocean.com/<My Registry>/$IMAGE_NAME
docker push registry.digitalocean.com/<My Registry>/$IMAGE_NAME
#Run the container in droplet
deploy:
needs: pushToDORegistry
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- uses: actions/checkout@v2
- name: Executing remote command
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
USERNAME: ${{ secrets.USERNAME }}
PORT: ${{ secrets.PORT }}
password: ${{ secrets.PASSWORD }}
script: |
<WHAT IS COMMAND NEEDED TO PULL IMAGE FROM DIGITAL OCEAN REGISTRY and RUN THE DOCKER IMAGE>
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
×