mirror of
https://github.com/ershisan99/flashcards-api.git
synced 2026-02-02 05:12:05 +00:00
50 lines
1.4 KiB
YAML
50 lines
1.4 KiB
YAML
name: Deploy to DigitalOcean
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- master
|
|
|
|
jobs:
|
|
build-and-deploy:
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v2
|
|
|
|
- name: Log in to Docker Hub
|
|
uses: docker/login-action@v1
|
|
with:
|
|
username: ${{ secrets.DOCKER_USERNAME }}
|
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
|
|
|
- name: Build and push Docker image
|
|
uses: docker/build-push-action@v2
|
|
with:
|
|
push: true
|
|
tags: ershisan99/flashcards:latest
|
|
|
|
- name: SSH and Deploy to Droplet
|
|
uses: appleboy/ssh-action@master
|
|
with:
|
|
host: ${{ secrets.DROPLET_IP }}
|
|
username: root
|
|
password: ${{ secrets.SSH_PASSWORD }} # Using password instead of key
|
|
script: |
|
|
echo "Pulling latest Docker image..."
|
|
docker pull ershisan99/flashcards:latest
|
|
|
|
echo "Checking if the container 'flashcards' exists..."
|
|
if [ $(docker ps -a -q -f name=^/flashcards$) ]; then
|
|
echo "Container exists. Stopping and removing..."
|
|
docker stop flashcards
|
|
docker rm flashcards
|
|
else
|
|
echo "No existing container to stop or remove."
|
|
fi
|
|
|
|
echo "Starting new container..."
|
|
docker run -d --name flashcards -p 80:3333 ershisan99/flashcards:latest
|
|
|