Skip to content

Deploy to DROPLET

Deploy to DROPLET #1

Workflow file for this run

name: Deploy to DROPLET
on:
release:
types: [ created ]
jobs:
deploy:
runs-on: ubuntu-latest
permissions: write-all
steps:
- uses: actions/checkout@v4
- name: Set up .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0'
- name: Build
run: dotnet build --configuration Release
- name: Run Tests
run: dotnet test
- name: Variable Substitution in appsettings.json
uses: microsoft/variable-substitution@v1
with:
files: '**/appsettings.json'
env:
Trello.AppKey: ${{ secrets.TRELLO_APP_KEY }}
Trello.UserToken: ${{ secrets.TRELLO_USER_TOKEN }}
Trello.BoardId: ${{ secrets.TRELLO_BOARD_ID }}
Trello.ListId: ${{ secrets.TRELLO_LIST_ID }}
GitHub.PatToken: ${{ secrets.GH_PAT }}
Telegram.BotToken: ${{ secrets.TELEGRAM_BOT_TOKEN }}
Telegram.ChannelId: ${{ secrets.TELEGRAM_CHANNEL_ID }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Push Docker Image
run: |
docker build -t ghcr.io/bardin08/eduautomation:${{ github.event.release.tag_name}} .
docker tag ghcr.io/bardin08/eduautomation:${{ github.event.release.tag_name}} ghcr.io/bardin08/eduautomation:latest
docker push ghcr.io/bardin08/eduautomation --all-tags
- name: Deploy to DROPLET
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.DROPLET_HOST }}
username: ${{ secrets.DROPLET_USERNAME }}
key: ${{ secrets.DROPLET_KEY }}
script: |
docker container ls -q --filter name=edu-automation > /tmp/current_container_id || true # Get the container ID if it exists
if [ -s /tmp/current_container_id ]; then # Check if previous container exists and is running
docker stop $(cat /tmp/current_container_id) || true # Stop the old container
docker rm $(cat /tmp/current_container_id) || true # Remove the old container
fi
docker login ghcr.io -u bardin08 -p ${{ secrets.GITHUB_TOKEN }}
docker pull ghcr.io/bardin08/eduautomation:${{ github.event.release.tag_name}}
docker run -d -p 5217:8080 --name edu-automation ghcr.io/bardin08/eduautomation:${{ github.event.release.tag_name}}