-
Notifications
You must be signed in to change notification settings - Fork 0
74 lines (63 loc) · 2.69 KB
/
master_eventhubapiserver.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
name: Build, push, and deploy Docker image for EventHub API
on:
push:
branches:
- master
workflow_dispatch:
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: 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
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 }}
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
"