Skip to content

Commit

Permalink
fix cicd and docker compose file
Browse files Browse the repository at this point in the history
  • Loading branch information
tranvuongduy2003 committed Nov 17, 2024
1 parent 19698ae commit 59de992
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 43 deletions.
57 changes: 20 additions & 37 deletions .github/workflows/master_eventhubapiserver.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ on:
workflow_dispatch:

env:
DOCKER_IMAGE_NAME: tranvuongduy2003/eventhub-api:linux-latest # Replace with your Docker Hub repo name
REGISTRY: ${{ secrets.SERVER_IP }}:5000
DOCKER_IMAGE_NAME: eventhub-api # Replace with your Docker Hub repo name
CONTAINER_NAME: "eventhub.api"

jobs:
Expand All @@ -16,16 +17,20 @@ jobs:

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 -f source/EventHub.Presentation/Dockerfile .
- name: Push Docker image to Docker Hub
run: docker push $DOCKER_IMAGE_NAME
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
config-inline: |
[registry."${{ secrets.SERVER_IP }}:5000"]
http = true
insecure = true
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./source/EventHub.Presentation/Dockerfile
push: true
tags: ${{ secrets.SERVER_IP }}:5000/eventhub-api:linux-latest

deploy:
runs-on: ubuntu-latest
Expand All @@ -43,37 +48,15 @@ jobs:
sudo apt-get install -y sshpass
- 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: |
sshpass -p "$SERVER_PASSWORD" ssh -o StrictHostKeyChecking=no $SERVER_USERNAME@$SERVER_IP << EOF
# Login to Docker Hub
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin
# Pull the latest image from Docker Hub
docker pull $DOCKER_IMAGE_NAME
# Stop and remove the old container if it exists
sshpass -p "${{ secrets.SERVER_PASSWORD }}" ssh -o StrictHostKeyChecking=no ${{ secrets.SERVER_USERNAME}}@${{ secrets.SERVER_IP }} << EOF
docker pull "127.0.0.1:5000/${DOCKER_IMAGE_NAME}:linux-latest"
docker stop $CONTAINER_NAME || true
docker rm $CONTAINER_NAME || true
# Run the new container
docker container rm $CONTAINER_NAME || true
docker run -d --name $CONTAINER_NAME \
--network eventhub \
-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
"${{ secrets.SERVER_IP }}:5000/${DOCKER_IMAGE_NAME}:linux-latest"
EOF
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -456,4 +456,3 @@ riderModule.iml
dotnet-tools.json
aspire/EventHub.AppHost/appsettings.Development.json
source/EventHub.Presentation/appsettings.Aspire.json
source/EventHub.Presentation/appsettings.Development.json
5 changes: 3 additions & 2 deletions deploy/docker-compose.development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ services:
volumes:
- sqlserver_data:/var/lib/sqlserver/data
ports:
- "1437:1433"
- "1433:1433"

eventhub.seq:
image: datalust/seq:latest
container_name: eventhub.seq
restart: always
environment:
- ACCEPT_EULA=Y
ports:
Expand All @@ -38,7 +39,7 @@ services:
image: mongo
container_name: eventhub.hangfire
ports:
- "27018:27017"
- "27017:27017"
volumes:
- hangfire_mongo_data:/data/db
restart: always
Expand Down
3 changes: 0 additions & 3 deletions deploy/docker-compose.production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ services:
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:
Expand Down
69 changes: 69 additions & 0 deletions source/EventHub.Presentation/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"DefaultConnectionString": "Server=localhost,1437;Database=EventHubDB;User Id=sa;Password=@Admin123;TrustServerCertificate=True;Multipleactiveresultsets=true",
"CacheConnectionString": "localhost:6379",
"AzureSignalRConnectionString": ""
},
"JwtOptions": {
"Secret": "VERY STRONG SECRET KEY BY TRAN VUONG DUY",
"Issuer": "eventhub-auth-api",
"Audience": "eventhub-client"
},
"SeqConfiguration": {
"ServerUrl": "http://localhost:5341"
},
"AzureBlobStorage": {
"StorageAccount": "eventhubstorage27072024",
"Key": "zka6DrmOLJ1ejftXWJWMuHyf2wVehs470V4Z2D4zEigDBnx9dBGEtdpCsto3DDYTCwXqhn2Z7Vyy+AStjJUYJQ==",
"ConnectionString": "DefaultEndpointsProtocol=https;AccountName=eventhubstorage27072024;AccountKey=zka6DrmOLJ1ejftXWJWMuHyf2wVehs470V4Z2D4zEigDBnx9dBGEtdpCsto3DDYTCwXqhn2Z7Vyy+AStjJUYJQ==;EndpointSuffix=core.windows.net",
"ContainerName": "files"
},
"Authentication": {
"Google": {
"ClientSecret": "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",
"ClientId": "561476722239-kimb64ln11mqfpo2adm5rd60gcv96sud.apps.googleusercontent.com"
},
"Facebook": {
"ClientSecret": "4f9c952dbd98eba1390f04d09ee62e2f",
"ClientId": "426547706699316"
}
},
"EmailSettings": {
"Email": "[email protected]",
"Password": "jqvckxgzkuwrynre",
"Host": "smtp.gmail.com",
"DisplayName": "EventHub",
"Port": 587
},
"HangfireSettings": {
"Route": "/jobs",
"ServerName": "Hangfire Server",
"Dashboard": {
"AppPath": "/",
"StatsPollingInterval": 2000,
"DashboardTitle": "Jobs"
},
"Storage": {
"DBProvider": "mongodb",
"ConnectionString": "mongodb://admin:admin@localhost:27018/hangfire-webapi?authSource=admin"
}
},
"Serilog": {
"MinimumLevel": {
"Default": "Information",
"Override": {
"Microsoft": "Information",
"Microsoft.Hosting.Lifetime": "Information",
"Microsoft.AspNetCore.Authentication": "Debug",
"System": "Warning"
}
}
}
}

0 comments on commit 59de992

Please sign in to comment.