-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2b9d31d
commit 753ce72
Showing
2 changed files
with
72 additions
and
46 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,75 @@ | ||
# 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 | ||
name: Build, push, and deploy Docker image for EventHub API | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
runs-on: windows-latest | ||
env: | ||
DOCKER_IMAGE_NAME: tranvuongduy2003/eventhub-api:linux-latest # 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: Set up .NET Core | ||
uses: actions/setup-dotnet@v4 | ||
with: | ||
dotnet-version: "8.x" | ||
|
||
- name: Store dependencies | ||
run: dotnet restore source/EventHub.Presentation/EventHub.Presentation.csproj | ||
- name: Log in to Docker Hub | ||
run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin | ||
|
||
- name: Build with dotnet | ||
run: dotnet build source/EventHub.Presentation/EventHub.Presentation.csproj -c Release -o ./build | ||
- name: Build Docker image | ||
run: | | ||
docker build -t $DOCKER_IMAGE_NAME -f source/EventHub.Presentation/Dockerfile . | ||
- name: dotnet publish | ||
run: dotnet publish source/EventHub.Presentation/EventHub.Presentation.csproj -c Release -o ./publish | ||
|
||
- name: Upload artifact for deployment job | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: .net-app | ||
path: ./publish | ||
- name: Push Docker image to Docker Hub | ||
run: docker push $DOCKER_IMAGE_NAME | ||
|
||
deploy: | ||
runs-on: windows-latest | ||
needs: build | ||
environment: | ||
name: "Production" | ||
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} | ||
|
||
runs-on: ubuntu-latest | ||
needs: build-and-push | ||
|
||
steps: | ||
- name: Download artifact from build job | ||
uses: actions/download-artifact@v4 | ||
- name: Setup SSH | ||
uses: webfactory/[email protected] | ||
with: | ||
name: .net-app | ||
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }} | ||
|
||
- name: Install expect for SSH password automation | ||
run: sudo apt-get install -y expect | ||
|
||
- name: Deploy to Azure Web App | ||
id: deploy-to-webapp | ||
uses: azure/webapps-deploy@v3 | ||
with: | ||
app-name: "EventHubAPIServer" | ||
slot-name: "Production" | ||
package: . | ||
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_2E162A0AE3134EF8992B4DD6656A4E66 }} | ||
- name: Deploy Docker container on remote server | ||
env: | ||
SERVER_IP: ${{ secrets.SERVER_IP }} | ||
SERVER_USERNAME: ${{ secrets.SERVER_USERNAME }} | ||
SERVER_PASSWORD: ${{ secrets.SERVER_PASSWORD }} | ||
DATABASE_USERNAME: ${{ secrets.DATABASE_USERNAME }} | ||
DATABASE_PASSWORD: ${{ secrets.DATABASE_PASSWORD }} | ||
MONGO_DB_ROOT_USERNAME: ${{ secrets.MONGO_DB_ROOT_USERNAME }} | ||
MONGO_DB_ROOT_PASSWORD: ${{ secrets.MONGO_DB_ROOT_PASSWORD }} | ||
run: | | ||
ssh -o StrictHostKeyChecking=no $SERVER_USERNAME@$SERVER_IP << EOF | ||
# Pull the latest image from Docker Hub | ||
docker pull $DOCKER_IMAGE_NAME | ||
# Stop and remove the old container if it exists | ||
docker stop $CONTAINER_NAME || true | ||
docker rm $CONTAINER_NAME || true | ||
# Run the new container | ||
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=$DATABASE_USERNAME;Password=$DATABASE_PASSWORD;TrustServerCertificate=True;Multipleactiveresultsets=true" \ | ||
-e "ConnectionStrings:CacheConnectionString=eventhub.cache:6379" \ | ||
-e "SeqConfiguration:ServerUrl=http://eventhub.seq:5341" \ | ||
-e "HangfireSettings:Storage:ConnectionString=mongodb://$MONGO_DB_ROOT_USERNAME:[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 | ||
EOF |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,16 +2,26 @@ version: '3.8' | |
|
||
services: | ||
eventhub.api: | ||
image: eventhubcontainer.azurecr.io/eventhub-api:linux-latest | ||
image: ${DOCKER_REGISTRY-}eventhub-api:${PLATFORM:-linux}-${TAG:-latest} | ||
container_name: eventhub.api | ||
environment: | ||
- ASPNETCORE_ENVIRONMENT=Production | ||
- ASPNETCORE_ENVIRONMENT=Development | ||
- ASPNETCORE_URLS=http://+:80 | ||
- "ConnectionStrings:DefaultConnectionString=Server=eventhub.db,1433;Database=EventHubDB;User Id=sa;Password=@Admin123;TrustServerCertificate=True;Multipleactiveresultsets=true" | ||
- "ConnectionStrings:CacheConnectionString=eventhub.cache:6379" | ||
- "SeqConfiguration:ServerUrl=http://eventhub.seq:5341" | ||
- "HangfireSettings:Storage:ConnectionString=mongodb://admin:[email protected]:27017/hangfire-webapi?authSource=admin" | ||
build: | ||
context: ../source/EventHub.Presentation | ||
dockerfile: Dockerfile | ||
restart: always | ||
context: .. | ||
dockerfile: source/EventHub.Presentation/Dockerfile | ||
restart: always | ||
ports: | ||
- "5002:80" | ||
volumes: | ||
- ${APPDATA}/Microsoft/UserSecrets:/home/app/.microsoft/usersecrets:ro | ||
- ${APPDATA}/ASP.NET/Https:/home/app/.aspnet/https:ro | ||
|
||
networks: | ||
default: | ||
name: eventhub | ||
driver: bridge |