update script #2
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |