Skip to content

Commit 38161cc

Browse files
feat(health): add health checks for postgres and minio services
ci: add github workflows for ci/cd pipeline ci: add dependabot configuration for dependency updates chore: ignore .vs directory in gitignore docs: add ci/cd documentation in readme-ci-cd.md
1 parent 9fa2dd6 commit 38161cc

26 files changed

+673
-1202
lines changed

.editorconfig

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = crlf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 4
9+
trim_trailing_whitespace = true
10+
11+
[*.{cs,csx,vb,vbx}]
12+
indent_size = 4
13+
14+
[*.{json,js,ts,yml,yaml}]
15+
indent_size = 2
16+
17+
[*.md]
18+
trim_trailing_whitespace = false
19+
20+
# C# files
21+
[*.cs]
22+
23+
# New line preferences
24+
csharp_new_line_before_open_brace = all
25+
csharp_new_line_before_else = true
26+
csharp_new_line_before_catch = true
27+
csharp_new_line_before_finally = true
28+
csharp_new_line_before_members_in_object_initializers = true
29+
csharp_new_line_before_members_in_anonymous_types = true
30+
csharp_new_line_between_query_expression_clauses = true
31+
32+
# Indentation preferences
33+
csharp_indent_case_contents = true
34+
csharp_indent_switch_labels = true
35+
csharp_indent_labels = flush_left
36+
37+
# Space preferences
38+
csharp_space_after_cast = false
39+
csharp_space_after_keywords_in_control_flow_statements = true
40+
csharp_space_between_method_call_parameter_list_parentheses = false
41+
csharp_space_between_method_declaration_parameter_list_parentheses = false
42+
csharp_space_between_parentheses = false
43+
csharp_space_before_colon_in_inheritance_clause = true
44+
csharp_space_after_colon_in_inheritance_clause = true
45+
csharp_space_around_binary_operators = before_and_after
46+
csharp_space_between_method_declaration_empty_parameter_list_parentheses = false
47+
csharp_space_between_method_call_name_and_opening_parenthesis = false
48+
csharp_space_between_method_call_empty_parameter_list_parentheses = false
49+
50+
# Wrapping preferences
51+
csharp_preserve_single_line_statements = true
52+
csharp_preserve_single_line_blocks = true
53+
54+
# Code style rules
55+
dotnet_style_qualification_for_field = false:suggestion
56+
dotnet_style_qualification_for_property = false:suggestion
57+
dotnet_style_qualification_for_method = false:suggestion
58+
dotnet_style_qualification_for_event = false:suggestion
59+
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
60+
dotnet_style_predefined_type_for_member_access = true:suggestion
61+
dotnet_style_require_accessibility_modifiers = for_non_interface_members:suggestion
62+
dotnet_style_readonly_field = true:suggestion
63+
64+
# Expression-level preferences
65+
dotnet_style_object_initializer = true:suggestion
66+
dotnet_style_collection_initializer = true:suggestion
67+
dotnet_style_explicit_tuple_names = true:suggestion
68+
dotnet_style_null_propagation = true:suggestion
69+
dotnet_style_coalesce_expression = true:suggestion
70+
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
71+
dotnet_style_prefer_inferred_tuple_names = true:suggestion
72+
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
73+
dotnet_style_prefer_auto_properties = true:silent
74+
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
75+
dotnet_style_prefer_conditional_expression_over_return = true:silent

.github/dependabot.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
version: 2
2+
updates:
3+
# Enable version updates for .NET dependencies
4+
- package-ecosystem: "nuget"
5+
directory: "/"
6+
schedule:
7+
interval: "weekly"
8+
day: "monday"
9+
time: "09:00"
10+
open-pull-requests-limit: 10
11+
reviewers:
12+
- "@octocat"
13+
assignees:
14+
- "@octocat"
15+
commit-message:
16+
prefix: "chore"
17+
include: "scope"
18+
19+
# Enable version updates for Docker
20+
- package-ecosystem: "docker"
21+
directory: "/"
22+
schedule:
23+
interval: "weekly"
24+
day: "monday"
25+
time: "09:00"
26+
open-pull-requests-limit: 5
27+
28+
# Enable version updates for GitHub Actions
29+
- package-ecosystem: "github-actions"
30+
directory: "/"
31+
schedule:
32+
interval: "weekly"
33+
day: "monday"
34+
time: "09:00"
35+
open-pull-requests-limit: 5

.github/workflows/ci-cd.yml

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
name: CI/CD Pipeline
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
env:
10+
DOTNET_VERSION: '8.0.x'
11+
REGISTRY: ghcr.io
12+
IMAGE_NAME: ${{ github.repository }}
13+
14+
jobs:
15+
test:
16+
runs-on: ubuntu-latest
17+
name: Build and Test
18+
19+
services:
20+
postgres:
21+
image: postgres:15
22+
env:
23+
POSTGRES_PASSWORD: postgres
24+
POSTGRES_USER: postgres
25+
POSTGRES_DB: paymentcoredb
26+
options: >-
27+
--health-cmd pg_isready
28+
--health-interval 10s
29+
--health-timeout 5s
30+
--health-retries 5
31+
ports:
32+
- 5432:5432
33+
34+
steps:
35+
- uses: actions/checkout@v4
36+
37+
- name: Setup .NET
38+
uses: actions/setup-dotnet@v4
39+
with:
40+
dotnet-version: ${{ env.DOTNET_VERSION }}
41+
42+
- name: Restore dependencies
43+
run: dotnet restore
44+
45+
- name: Build
46+
run: dotnet build --no-restore --configuration Release
47+
48+
- name: Test
49+
run: dotnet test --no-build --configuration Release --verbosity normal
50+
51+
build-and-push:
52+
needs: test
53+
runs-on: ubuntu-latest
54+
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop')
55+
56+
permissions:
57+
contents: read
58+
packages: write
59+
60+
steps:
61+
- name: Checkout repository
62+
uses: actions/checkout@v4
63+
64+
- name: Log in to Container Registry
65+
uses: docker/login-action@v3
66+
with:
67+
registry: ${{ env.REGISTRY }}
68+
username: ${{ github.actor }}
69+
password: ${{ secrets.GITHUB_TOKEN }}
70+
71+
- name: Extract metadata
72+
id: meta
73+
uses: docker/metadata-action@v5
74+
with:
75+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
76+
tags: |
77+
type=ref,event=branch
78+
type=ref,event=pr
79+
type=sha,prefix={{branch}}-
80+
type=raw,value=latest,enable={{is_default_branch}}
81+
82+
- name: Build and push Docker image
83+
uses: docker/build-push-action@v5
84+
with:
85+
context: .
86+
push: true
87+
tags: ${{ steps.meta.outputs.tags }}
88+
labels: ${{ steps.meta.outputs.labels }}
89+
90+
deploy-staging:
91+
needs: build-and-push
92+
runs-on: ubuntu-latest
93+
if: github.ref == 'refs/heads/develop'
94+
environment: staging
95+
96+
steps:
97+
- name: Deploy to Staging
98+
run: |
99+
echo "Deploying to staging environment..."
100+
# Add your staging deployment commands here
101+
# Example: kubectl apply -f k8s/staging/
102+
# Example: docker-compose -f docker-compose.staging.yml up -d
103+
104+
deploy-production:
105+
needs: build-and-push
106+
runs-on: ubuntu-latest
107+
if: github.ref == 'refs/heads/main'
108+
environment: production
109+
110+
steps:
111+
- name: Deploy to Production
112+
run: |
113+
echo "Deploying to production environment..."
114+
# Add your production deployment commands here
115+
# Example: kubectl apply -f k8s/production/
116+
# Example: docker-compose -f docker-compose.prod.yml up -d

.github/workflows/docker-build.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Docker Build and Test
2+
3+
on:
4+
push:
5+
branches: [ main, develop ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
env:
10+
REGISTRY: ghcr.io
11+
IMAGE_NAME: ${{ github.repository }}
12+
13+
jobs:
14+
docker-build-test:
15+
runs-on: ubuntu-latest
16+
name: Docker Build and Integration Test
17+
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
22+
- name: Set up Docker Buildx
23+
uses: docker/setup-buildx-action@v3
24+
25+
- name: Build Docker image for testing
26+
uses: docker/build-push-action@v5
27+
with:
28+
context: .
29+
load: true
30+
tags: payment-api:test
31+
cache-from: type=gha
32+
cache-to: type=gha,mode=max
33+
34+
- name: Start services for integration test
35+
run: |
36+
docker-compose -f docker-compose.ci.yml up -d postgres minio
37+
sleep 30
38+
39+
- name: Run database migrations
40+
run: |
41+
docker run --rm --network payment-core-service-api_payment-network \
42+
-e ConnectionStrings__DefaultConnection="Host=postgres;Database=paymentcoredb;Username=postgres;Password=postgres" \
43+
payment-api:test \
44+
dotnet ef database update
45+
46+
- name: Run integration tests
47+
run: |
48+
docker-compose -f docker-compose.ci.yml up -d app
49+
sleep 30
50+
51+
# Health check
52+
curl -f http://localhost:8080/health || exit 1
53+
54+
# API tests
55+
curl -f http://localhost:8080/api/auth/health || echo "Auth endpoint check"
56+
57+
- name: Cleanup
58+
if: always()
59+
run: |
60+
docker-compose -f docker-compose.ci.yml down -v
61+
docker system prune -f
62+
63+
vulnerability-scan:
64+
runs-on: ubuntu-latest
65+
name: Container Security Scan
66+
67+
steps:
68+
- name: Checkout repository
69+
uses: actions/checkout@v4
70+
71+
- name: Build image for scanning
72+
run: docker build -t payment-api:scan .
73+
74+
- name: Run Trivy vulnerability scanner
75+
uses: aquasecurity/trivy-action@master
76+
with:
77+
image-ref: 'payment-api:scan'
78+
format: 'sarif'
79+
output: 'trivy-results.sarif'
80+
81+
- name: Upload Trivy scan results
82+
uses: github/codeql-action/upload-sarif@v3
83+
if: always()
84+
with:
85+
sarif_file: 'trivy-results.sarif'

0 commit comments

Comments
 (0)