Skip to content

Commit d97d996

Browse files
committed
[NEW] ELK
1 parent a085fde commit d97d996

File tree

8 files changed

+98
-4
lines changed

8 files changed

+98
-4
lines changed

.github/workflows/ci-cd.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: Docker CI/CD
22

33
on:
44
push:
5-
branches: [ main ]
5+
branches: [ master ]
66
pull_request:
7-
branches: [ main ]
7+
branches: [ master ]
88

99
env:
1010
API_IMAGE_NAME: github-api

.github/workflows/dockerhub.yml

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Github Actions CI/CD
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
env:
10+
API_CONTAINER_NAME: dotnet-api
11+
UI_CONTAINER_NAME: dotnet-ui
12+
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
13+
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
14+
SSH_HOST: ${{ secrets.SERVER_IP }}
15+
SSH_USER: ${{ secrets.SERVER_USERNAME }}
16+
SSH_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
17+
UI_PORT: 4000:4000
18+
API_PORT: 4001:4001
19+
20+
jobs:
21+
build_and_push:
22+
runs-on: ubuntu-latest
23+
24+
steps:
25+
- name: Checkout code
26+
uses: actions/checkout@v3
27+
28+
- name: Set up Docker Buildx
29+
uses: docker/setup-buildx-action@v3
30+
31+
- name: Log in to DockerHub
32+
uses: docker/login-action@v3
33+
with:
34+
username: ${{ env.DOCKERHUB_USERNAME }}
35+
password: ${{ env.DOCKERHUB_TOKEN }}
36+
37+
- name: Build and push API Docker image
38+
uses: docker/build-push-action@v5
39+
with:
40+
context: .
41+
file: ./API.Dockerfile
42+
push: true
43+
tags: ${{ env.DOCKERHUB_USERNAME }}/${{ env.API_CONTAINER_NAME }}:${{ github.sha }}
44+
- name: Build and push UI Docker image
45+
uses: docker/build-push-action@v5
46+
with:
47+
context: .
48+
file: ./UI.Dockerfile
49+
push: true
50+
tags: ${{ env.DOCKERHUB_USERNAME }}/${{ env.UI_CONTAINER_NAME }}:${{ github.sha }}
51+
52+
deploy:
53+
needs: build_and_push
54+
runs-on: ubuntu-latest
55+
56+
steps:
57+
- name: Executing remote SSH commands to deploy
58+
uses: appleboy/ssh-action@master
59+
with:
60+
host: ${{ env.SSH_HOST }}
61+
username: ${{ env.SSH_USER }}
62+
key: ${{ env.SSH_KEY }}
63+
script: |
64+
docker login -u ${{ env.DOCKERHUB_USERNAME }} -p ${{ env.DOCKERHUB_TOKEN }}
65+
docker pull ${{ env.DOCKERHUB_USERNAME }}/${{ env.API_CONTAINER_NAME }}:${{ github.sha }}
66+
docker pull ${{ env.DOCKERHUB_USERNAME }}/${{ env.UI_CONTAINER_NAME }}:${{ github.sha }}
67+
docker stop ${{ env.API_CONTAINER_NAME }} || true
68+
docker stop ${{ env.UI_CONTAINER_NAME }} || true
69+
docker rm ${{ env.API_CONTAINER_NAME }} || true
70+
docker rm ${{ env.UI_CONTAINER_NAME }} || true
71+
docker run -d --name ${{ env.API_CONTAINER_NAME }} -p ${{ env.API_PORT }} ${{ env.DOCKERHUB_USERNAME }}/${{ env.API_CONTAINER_NAME }}:${{ github.sha }}
72+
docker run -d --name ${{ env.UI_CONTAINER_NAME }} -p ${{ env.UI_PORT }} ${{ env.DOCKERHUB_USERNAME }}/${{ env.UI_CONTAINER_NAME }}:${{ github.sha }}

GitHub.Actions.API/GitHub.Actions.API.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<ItemGroup>
1010
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.13" />
1111
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
12+
<PackageReference Include="Elastic.Apm.NetCoreAll" Version="1.27.0" />
1213
</ItemGroup>
1314

1415
</Project>

GitHub.Actions.API/Program.cs

+3
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,7 @@
2020

2121
app.MapControllers();
2222

23+
app.UseAllElasticApm(Configuration);
24+
25+
2326
app.Run();

GitHub.Actions.API/appsettings.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,11 @@
55
"Microsoft.AspNetCore": "Warning"
66
}
77
},
8-
"AllowedHosts": "*"
8+
"AllowedHosts": "*",
9+
"ElasticApm": {
10+
"SecretToken": "",
11+
"ServerUrls": "http://10.128.0.12:8200",
12+
"ServiceName": "github-actions-api",
13+
"Environment": "development"
14+
}
915
}

GitHub.Actions/GitHub.Actions.csproj

+4
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@
66
<ImplicitUsings>enable</ImplicitUsings>
77
</PropertyGroup>
88

9+
<ItemGroup>
10+
<PackageReference Include="Elastic.Apm.NetCoreAll" Version="1.27.0" />
11+
</ItemGroup>
12+
913
</Project>

GitHub.Actions/Program.cs

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
app.UseRouting();
2424

25+
app.UseAllElasticApm(Configuration);
26+
2527
app.MapBlazorHub();
2628
app.MapFallbackToPage("/_Host");
2729

GitHub.Actions/appsettings.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,11 @@
55
"Microsoft.AspNetCore": "Warning"
66
}
77
},
8-
"AllowedHosts": "*"
8+
"AllowedHosts": "*",
9+
"ElasticApm": {
10+
"SecretToken": "",
11+
"ServerUrls": "http://10.128.0.12:8200",
12+
"ServiceName": "github-actions-api",
13+
"Environment": "development"
14+
}
915
}

0 commit comments

Comments
 (0)