Skip to content

Deploy to Digital Ocean #31

Deploy to Digital Ocean

Deploy to Digital Ocean #31

Workflow file for this run

name: Deploy
on:
workflow_run:
workflows: ["CI"]
types:
- completed
workflow_dispatch:
inputs:
branch:
description: 'Branch to deploy'
required: true
default: 'main'
jobs:
deploy:
runs-on: ubuntu-latest
if: |
github.event_name == 'workflow_dispatch' ||
(github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.head_branch == 'main')
steps:
- name: Get branch name
id: branch
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "BRANCH=${{ github.event.inputs.branch }}" >> $GITHUB_OUTPUT
else
echo "BRANCH=main" >> $GITHUB_OUTPUT
fi
- name: Deploy to droplet
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.DROPLET_IP }}
username: root
key: ${{ secrets.DROPLET_SSH_PRIVATE_KEY }}
script: |
echo "${{ secrets.GH_PAT }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
# Stop and remove all running containers
docker stop $(docker ps -aq) || true
docker rm $(docker ps -aq) || true
# Pull the latest image for the specified branch
docker pull ghcr.io/loftwah/linkarooie:${{ steps.branch.outputs.BRANCH }}
# Run the new container
docker run -d --name linkarooie-app -p 80:3000 -e RAILS_ENV=production -e SECRET_KEY_BASE=${{ secrets.SECRET_KEY_BASE }} ghcr.io/loftwah/linkarooie:${{ steps.branch.outputs.BRANCH }}