add dockerfile and github actions workflow for deploy

This commit is contained in:
2024-04-13 13:01:49 +02:00
parent 616626b4ce
commit 82484be19c
4 changed files with 109 additions and 0 deletions

38
.github/workflows/deploy.yml vendored Normal file
View File

@@ -0,0 +1,38 @@
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: |
docker pull ershisan99/flashcards:latest
docker stop flashcards || true
docker rm flashcards || true
docker run -d --name flashcards -p 80:3333 ershisan99/flashcards:latest