v0.0.1.3 #15
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 EC2 | |
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 EC2 | |
uses: appleboy/ssh-action@master | |
with: | |
host: ${{ secrets.EC2_HOST }} | |
username: ${{ secrets.EC2_USERNAME }} | |
key: ${{ secrets.EC2_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}} |