Skip to content

Commit

Permalink
[NEW] ELK
Browse files Browse the repository at this point in the history
  • Loading branch information
ismoilovdevml committed May 13, 2024
1 parent a085fde commit d97d996
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Docker CI/CD

on:
push:
branches: [ main ]
branches: [ master ]
pull_request:
branches: [ main ]
branches: [ master ]

env:
API_IMAGE_NAME: github-api
Expand Down
72 changes: 72 additions & 0 deletions .github/workflows/dockerhub.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Github Actions CI/CD

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

env:
API_CONTAINER_NAME: dotnet-api
UI_CONTAINER_NAME: dotnet-ui
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}
SSH_HOST: ${{ secrets.SERVER_IP }}
SSH_USER: ${{ secrets.SERVER_USERNAME }}
SSH_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
UI_PORT: 4000:4000
API_PORT: 4001:4001

jobs:
build_and_push:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to DockerHub
uses: docker/login-action@v3
with:
username: ${{ env.DOCKERHUB_USERNAME }}
password: ${{ env.DOCKERHUB_TOKEN }}

- name: Build and push API Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./API.Dockerfile
push: true
tags: ${{ env.DOCKERHUB_USERNAME }}/${{ env.API_CONTAINER_NAME }}:${{ github.sha }}
- name: Build and push UI Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./UI.Dockerfile
push: true
tags: ${{ env.DOCKERHUB_USERNAME }}/${{ env.UI_CONTAINER_NAME }}:${{ github.sha }}

deploy:
needs: build_and_push
runs-on: ubuntu-latest

steps:
- name: Executing remote SSH commands to deploy
uses: appleboy/ssh-action@master
with:
host: ${{ env.SSH_HOST }}
username: ${{ env.SSH_USER }}
key: ${{ env.SSH_KEY }}
script: |
docker login -u ${{ env.DOCKERHUB_USERNAME }} -p ${{ env.DOCKERHUB_TOKEN }}
docker pull ${{ env.DOCKERHUB_USERNAME }}/${{ env.API_CONTAINER_NAME }}:${{ github.sha }}
docker pull ${{ env.DOCKERHUB_USERNAME }}/${{ env.UI_CONTAINER_NAME }}:${{ github.sha }}
docker stop ${{ env.API_CONTAINER_NAME }} || true
docker stop ${{ env.UI_CONTAINER_NAME }} || true
docker rm ${{ env.API_CONTAINER_NAME }} || true
docker rm ${{ env.UI_CONTAINER_NAME }} || true
docker run -d --name ${{ env.API_CONTAINER_NAME }} -p ${{ env.API_PORT }} ${{ env.DOCKERHUB_USERNAME }}/${{ env.API_CONTAINER_NAME }}:${{ github.sha }}
docker run -d --name ${{ env.UI_CONTAINER_NAME }} -p ${{ env.UI_PORT }} ${{ env.DOCKERHUB_USERNAME }}/${{ env.UI_CONTAINER_NAME }}:${{ github.sha }}
1 change: 1 addition & 0 deletions GitHub.Actions.API/GitHub.Actions.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.13" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Elastic.Apm.NetCoreAll" Version="1.27.0" />
</ItemGroup>

</Project>
3 changes: 3 additions & 0 deletions GitHub.Actions.API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@

app.MapControllers();

app.UseAllElasticApm(Configuration);


app.Run();
8 changes: 7 additions & 1 deletion GitHub.Actions.API/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,11 @@
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"ElasticApm": {
"SecretToken": "",
"ServerUrls": "http://10.128.0.12:8200",
"ServiceName": "github-actions-api",
"Environment": "development"
}
}
4 changes: 4 additions & 0 deletions GitHub.Actions/GitHub.Actions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Elastic.Apm.NetCoreAll" Version="1.27.0" />
</ItemGroup>

</Project>
2 changes: 2 additions & 0 deletions GitHub.Actions/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

app.UseRouting();

app.UseAllElasticApm(Configuration);

app.MapBlazorHub();
app.MapFallbackToPage("/_Host");

Expand Down
8 changes: 7 additions & 1 deletion GitHub.Actions/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,11 @@
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"ElasticApm": {
"SecretToken": "",
"ServerUrls": "http://10.128.0.12:8200",
"ServiceName": "github-actions-api",
"Environment": "development"
}
}

0 comments on commit d97d996

Please sign in to comment.