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
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy | |
# More GitHub Actions for Azure: https://github.com/Azure/actions | |
name: Build and deploy ASP.Net Core app to Azure Web App - EventHubAPIServer | |
on: | |
push: | |
branches: | |
- master | |
workflow_dispatch: | |
env: | |
PLATFORM: "linux" | |
TAG: "latest" | |
DOCKER_REGISTRY: "tranvuongduy2003" | |
DOCKER_IMAGE_NAME: $DOCKER_REGISTRY/eventhub-api:$PLATFORM-$TAG # Replace with your Docker Hub repo name | |
CONTAINER_NAME: "eventhub.api" | |
jobs: | |
build-and-push: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Log in to Docker Hub | |
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin | |
- name: Build Docker image | |
run: | | |
docker build -t $DOCKER_IMAGE_NAME source/EventHub.Presentation/Dockerfile | |
- name: Push Docker image to Docker Hub | |
run: docker push $DOCKER_IMAGE_NAME | |
deploy: | |
runs-on: ubuntu-latest | |
needs: build-and-push | |
steps: | |
- name: Setup SSH | |
uses: webfactory/[email protected] | |
with: | |
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | |
- name: Install expect for SSH password automation | |
run: sudo apt-get install -y expect | |
- name: Deploy Docker container on remote server | |
env: | |
SERVER_IP: ${{ secrets.SERVER_IP }} | |
SERVER_USER: ${{ secrets.SERVER_USERNAME }} | |
SERVER_PASSWORD: ${{ secrets.SERVER_PASSWORD }} | |
CONTAINER_NAME: ${{ env.CONTAINER_NAME }} | |
DOCKER_IMAGE_NAME: ${{ env.DOCKER_IMAGE_NAME }} | |
run: | |
expect -c " | |
spawn ssh -o StrictHostKeyChecking=no $SERVER_USER@$SERVER_IP | |
expect \"password:\" | |
send \"$SERVER_PASSWORD\r\" | |
expect \"# \" | |
send \"docker pull $DOCKER_IMAGE_NAME\r\" | |
expect \"# \" | |
send \"docker stop $CONTAINER_NAME || true && docker rm $CONTAINER_NAME || true\r\" | |
expect \"# \" | |
send \"docker run -d --name $CONTAINER_NAME \ | |
--network eventhub \ | |
--restart always \ | |
-p 5002:80 \ | |
-e ASPNETCORE_ENVIRONMENT=Development \ | |
-e ASPNETCORE_URLS=http://+:80 \ | |
-e "ConnectionStrings:DefaultConnectionString=Server=eventhub.db,1433;Database=EventHubDB;User Id=sa;Password=@Admin123;TrustServerCertificate=True;Multipleactiveresultsets=true" \ | |
-e "ConnectionStrings:CacheConnectionString=eventhub.cache:6379" \ | |
-e "SeqConfiguration:ServerUrl=http://eventhub.seq:5341" \ | |
-e "HangfireSettings:Storage:ConnectionString=mongodb://admin:[email protected]:27017/hangfire-webapi?authSource=admin" \ | |
-v "${APPDATA}/Microsoft/UserSecrets:/home/app/.microsoft/usersecrets:ro" \ | |
-v "${APPDATA}/ASP.NET/Https:/home/app/.aspnet/https:ro" \ | |
$DOCKER_IMAGE_NAME\r\" | |
expect \"# \" | |
send \"exit\r\" | |
interact | |
" |