Skip to content

Deploy to Digital Ocean #20

Deploy to Digital Ocean

Deploy to Digital Ocean #20

Workflow file for this run

name: Deploy
on:
workflow_run:
workflows: ["CI"]
types:
- completed
jobs:
deploy:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GH_PAT }}
- name: Build and push Docker image
run: |
echo "${{ secrets.GH_PAT }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
GITHUB_TOKEN=${{ secrets.GH_PAT }} docker buildx build --no-cache --secret id=GITHUB_TOKEN -t ghcr.io/loftwah/linkarooie:latest --push .
- 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
docker pull ghcr.io/loftwah/linkarooie:latest
# 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:latest