Skip to content

Commit

Permalink
Create GitHub actions workflow for Staging environment. (#73)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zifah authored Aug 5, 2024
1 parent 297b478 commit 21f7d12
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/api-deploy-staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Deploy to EC2 staging

on:
push:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up .NET
uses: actions/setup-dotnet@v2
with:
dotnet-version: '6.0.x'

- name: Build project
run: dotnet publish -c Release -o out

- name: Deploy to EC2
env:
SSH_PRIVATE_KEY: ${{ secrets.DEPLOY_KEY }}
EC2_INSTANCE_IP: ${{ vars.EC2_INSTANCE_IP}}
SERVICE_NAME: ${{ vars.API_SERVICE_NAME }}
SERVICE_PATH: ${{ vars.API_SERVICE_PATH }}
run: |
echo "$SSH_PRIVATE_KEY" > private_key
chmod 600 private_key
rsync -avz --exclude 'appsettings.json' -e "ssh -i private_key -o StrictHostKeyChecking=no" out/ ec2-user@$EC2_INSTANCE_IP:$SERVICE_PATH
ssh -i private_key -o StrictHostKeyChecking=no ec2-user@$EC2_INSTANCE_IP '
sudo systemctl restart $SERVICE_NAME
sleep 3
STATUS=$(sudo systemctl is-active $SERVICE_NAME)
if [ "$STATUS" != "active" ]; then
sudo systemctl status $SERVICE_NAME --no-pager
exit 1
fi
'
shell: bash

0 comments on commit 21f7d12

Please sign in to comment.