Github Action to deploy Docker Image from Github Packages

Posted December 22, 2020 3.9k views
Node.jsDockerDigitalOcean DropletsGitHub Actions

I am coming from Heroku and want to get used to Docker and learn more about DevOps. So I informed myself about Github Actions and Github Packages.

Now I am searching for a starting point for my problem as I want to deploy via commit to a Digital Ocean Dropplet.

I have found the doctl lib. and some another question which unfortunately is using digital ocean registry.

If someone could share the actions.yml file for me, this would help me a lot.


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.

Submit an Answer
2 answers

I successfully pushed my image to Github Container Registry with the following workflow

name: GHCR-DigitalOcean

  # Trigger the workflow on push
      - main

    name: Push to GHCR -> DigitlOcean
    runs-on: ubuntu-latest

      # Checkout the Repository
      - name: Checking out the repository
        uses: actions/checkout@v2

      # Setting up Docker Builder
      - name: Set up Docker Builder
        uses: docker/setup-buildx-action@v1

      # Set Github Access Token with "write:packages" scope for Github Container Registry.
      # Then go to repository setings and add the copied token as a secret called "CR_PAT"
      - name: Log into GitHub Container Registry
        uses: docker/login-action@v1
          username: ${{ github.repository_owner }}
          password: ${{ secrets.CR_PAT }}

      # Push to Github Container Registry
      - name: Push to Github Container Registry
        uses: docker/build-push-action@v2
          context: .
          version: latest
          file: dockerfile
          push: true
          tags:${{ github.repository }}:latest

Unfortunately I got stuck by the ssh handshake as I try to provide the credentials instead of a key.

2020/12/*** 13:30:13 ssh: handshake failed: ssh: unable to authenticate, attempted methods [none password], no supported methods remain

    name: Deploy to Digital Ocean Droplet
    runs-on: ubuntu-latest
    needs: push_to_github_container_registry

      - name: Deploy to Digital Ocean droplet via SSH action
        uses: appleboy/ssh-action@v0.1.3
          HOST: ${{ secrets.HOST }}
          USERNAME: ${{ secrets.USERNAME }}
          PASSWORD: ${{ secrets.PASSWORD }}
          PORT: ${{ secrets.PORT }}
          script: |
            # Stop running container
            docker stop ${{ github.repository_owner }}

            # Remove old container
            docker rm ${{ github.repository_owner }}

            # Login to Github Container Registry
            docker login -u ${{ github.repository_owner }} -p ${{ secrets.CR_PAT }}

            # Pull the Docker Image 
            docker pull${{ github.repository }}:latest

            # Run a new container from a new image
            docker run -d \
            --restart always \
            --env-file .env \
            -p 8000:8080 \
            --name $(echo $${{ github.repository }})