Skip to content

Commit 723b991

Browse files
Merge pull request #1 from dariemcarlosdev/Dev
Merging into Marter Branch,
2 parents f1689b4 + 0a449e3 commit 723b991

File tree

130 files changed

+45828
-78
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

130 files changed

+45828
-78
lines changed

.dockerignore

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# ===========================================================================================
2+
# .dockerignore - BlueTreadApp
3+
# ===========================================================================================
4+
# Prevents unnecessary files from being copied to Docker build context
5+
# Benefits:
6+
# - Faster builds (smaller context to upload)
7+
# - Smaller images (excludes unnecessary files)
8+
# - Better security (excludes sensitive files)
9+
# - Cleaner builds (no build artifacts or temporary files)
10+
# ===========================================================================================
11+
12+
# ===== BUILD ARTIFACTS & OUTPUT DIRECTORIES =====
13+
# Exclude compiled binaries and build output
14+
# These are regenerated during Docker build
15+
**/bin/
16+
**/obj/
17+
**/out/
18+
# NOTE: /publish/ is NOT ignored because we use pre-published apps in the Dockerfile
19+
**/build/
20+
21+
# ===== VISUAL STUDIO & RIDER FILES =====
22+
# IDE-specific files and folders
23+
.vs/
24+
.vscode/
25+
.idea/
26+
*.suo
27+
*.user
28+
*.userosscache
29+
*.sln.docstates
30+
*.userprefs
31+
.DS_Store
32+
33+
# ===== NUGET PACKAGES =====
34+
# NuGet packages are restored during docker build
35+
# No need to copy local packages
36+
**/packages/
37+
*.nupkg
38+
*.snupkg
39+
40+
# ===== GIT FILES =====
41+
# Version control files not needed in container
42+
.git/
43+
.gitignore
44+
.gitattributes
45+
.github/
46+
47+
# ===== DOCKER FILES =====
48+
# Don't include Docker-related files in the build context
49+
# (except Dockerfile itself, which is automatically excluded)
50+
.dockerignore
51+
docker-compose*.yml
52+
*.Dockerfile
53+
Dockerfile*
54+
55+
# ===== DOCUMENTATION & README FILES =====
56+
# Exclude documentation files
57+
*.md
58+
README*
59+
LICENSE
60+
CHANGELOG*
61+
docs/
62+
documentation/
63+
64+
# ===== TEST FILES & COVERAGE =====
65+
# Exclude test projects and code coverage
66+
**/*Tests/
67+
**/*.Tests/
68+
**/TestResults/
69+
**/coverage/
70+
**/*.coverage
71+
**/*.coveragexml
72+
73+
# ===== NODE.JS (if you have frontend build tools) =====
74+
# Exclude Node.js dependencies if using npm/yarn for frontend
75+
node_modules/
76+
npm-debug.log
77+
yarn-error.log
78+
package-lock.json
79+
yarn.lock
80+
81+
# ===== ENVIRONMENT & CONFIGURATION FILES =====
82+
# Exclude local environment files
83+
# Production config should be injected via environment variables
84+
.env
85+
.env.local
86+
.env.*.local
87+
*.local.json
88+
appsettings.Development.json
89+
90+
# ===== TEMPORARY FILES =====
91+
# Exclude temporary and cache files
92+
**/tmp/
93+
**/temp/
94+
*.tmp
95+
*.cache
96+
*.log
97+
*.bak
98+
*.swp
99+
*~
100+
101+
# ===== AZURE & CLOUD FILES =====
102+
# Exclude Azure-specific files not needed in container
103+
**/.azure/
104+
azds.yaml
105+
charts/
106+
107+
# ===== DEPLOYMENT SCRIPTS =====
108+
# Exclude deployment and infrastructure files
109+
deploy/
110+
scripts/
111+
*.sh
112+
*.ps1
113+
*.bat
114+
*.cmd
115+
116+
# ===== MISCELLANEOUS =====
117+
# Other files to exclude
118+
*.DotSettings
119+
*.ncrunch*
120+
*.VisualState.xml
121+
TestResult.xml
122+
_ReSharper*/
123+
[Tt]est[Rr]esult*/
124+
[Bb]uild[Ll]og.*
125+
*.pidb
126+
*.svclog
127+
*.scc
128+
129+
# ===== KEEP THESE (Examples of files to NOT ignore) =====
130+
# !appsettings.json (already included by default)
131+
# !appsettings.Production.json (if needed)
132+
# !wwwroot/** (static files - automatically included)

.github/workflows/azure-deploy.yml

Lines changed: 237 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,237 @@
1+
name: Build and Deploy to Azure App Service
2+
3+
# ===================================================================
4+
# WORKFLOW TRIGGER CONFIGURATION
5+
# ===================================================================
6+
# This workflow triggers on:
7+
# 1. Push to Master: Builds, tests, and DEPLOYS to Azure (Production)
8+
# 2. Push to Dev: Builds and tests only (NO deployment)
9+
# 3. Pull Requests to Master/Dev: Builds, tests, and runs security scan (NO deployment)
10+
# 4. For more details, see the JOB comments below and visit documentation at: Docs/Deployment/AzureAppService/DEPLOYMENT_GUIDE.md and Docs/CICD/CICD_PIPELINE_GUIDE.md
11+
on:
12+
push:
13+
branches:
14+
- Master # Production deployment
15+
- Dev # Build/test only, no deployment
16+
pull_request:
17+
branches:
18+
- Master
19+
- Dev
20+
21+
env:
22+
DOTNET_VERSION: '8.0.x'
23+
AZURE_WEBAPP_PACKAGE_PATH: './publish'
24+
25+
# ===================================================================
26+
# JOB 1: BUILD AND TEST
27+
# ===================================================================
28+
# Purpose: Compiles the application and runs tests
29+
# Runs on: All branches (Master, Dev) and all pull requests
30+
# Output: Build artifact uploaded for deployment job
31+
jobs:
32+
build:
33+
name: Build and Test
34+
runs-on: ubuntu-latest
35+
36+
steps:
37+
- name: Checkout code
38+
uses: actions/checkout@v4
39+
40+
- name: Setup .NET
41+
uses: actions/setup-dotnet@v4
42+
with:
43+
dotnet-version: ${{ env.DOTNET_VERSION }}
44+
45+
# ===== Cache NuGet packages for faster builds =====
46+
# Caches packages to reduce build time from ~3min to ~1.5min (50% faster)
47+
- name: Cache NuGet packages
48+
uses: actions/cache@v3
49+
with:
50+
path: ~/.nuget/packages
51+
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
52+
restore-keys: |
53+
${{ runner.os }}-nuget-
54+
55+
- name: Restore dependencies
56+
run: dotnet restore
57+
58+
- name: Build
59+
run: dotnet build --configuration Release --no-restore
60+
61+
# ===== Run tests only if test projects exist =====
62+
# continue-on-error: true allows workflow to succeed even without test projects
63+
# Remove this flag once unit tests are added to make tests required
64+
- name: Test
65+
run: dotnet test --no-build --verbosity normal --configuration Release
66+
continue-on-error: true
67+
68+
- name: Publish
69+
run: dotnet publish -c Release -o ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
70+
71+
# ===== Upload build artifacts for debugging =====
72+
# Artifacts can be downloaded from GitHub Actions UI for troubleshooting
73+
- name: Upload artifact for deployment job
74+
uses: actions/upload-artifact@v3
75+
with:
76+
name: dotnet-app
77+
path: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
78+
79+
# ===================================================================
80+
# JOB 2: DEPLOY TO AZURE
81+
# ===================================================================
82+
# Purpose: Deploys the application to Azure App Service (Production)
83+
#
84+
# *** 1. DEPLOY JOB CONDITION ***
85+
# This job ONLY runs when:
86+
# - Event is a 'push' (not a pull request)
87+
# - AND branch is 'Master' (production branch)
88+
#
89+
# Result:
90+
# ✅ Master push → Deploys to Azure
91+
# ❌ Dev push → Builds only, NO deployment
92+
# ❌ Pull Request → Builds only, NO deployment
93+
#
94+
# This ensures only production-ready code from Master reaches Azure.
95+
deploy:
96+
name: Deploy to Azure
97+
runs-on: ubuntu-latest
98+
needs: build # Waits for build job to succeed
99+
if: github.event_name == 'push' && github.ref == 'refs/heads/Master' # Deploy ONLY on push to Master
100+
101+
# *** 2. ENVIRONMENT CONFIGURATION ***
102+
# GitHub Environment: 'production'
103+
# - Can be configured in GitHub repo settings to require manual approval
104+
# - Provides deployment history and protection rules
105+
# - URL displays the deployed application URL in GitHub Actions UI
106+
environment:
107+
name: 'production'
108+
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
109+
110+
steps:
111+
- name: Download artifact from build job
112+
uses: actions/download-artifact@v3
113+
with:
114+
name: dotnet-app
115+
path: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
116+
117+
- name: Deploy to Azure Web App
118+
id: deploy-to-webapp
119+
uses: azure/webapps-deploy@v3
120+
with:
121+
app-name: ${{ secrets.AZURE_WEBAPP_NAME }}
122+
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
123+
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
124+
125+
# ===== Configure App Settings in Azure =====
126+
# Sets configuration values directly in Azure App Service
127+
# These persist across deployments and override appsettings.json
128+
- name: Azure Login
129+
uses: azure/login@v1
130+
with:
131+
creds: ${{ secrets.AZURE_CREDENTIALS }}
132+
continue-on-error: true # Optional: if service principal not configured yet
133+
134+
# *** 3. ASPNETCORE_ENVIRONMENT CONFIGURATION ***
135+
# Sets ASPNETCORE_ENVIRONMENT to "Production" in Azure App Service
136+
# This determines which appsettings file is loaded:
137+
# - appsettings.json (base)
138+
# - appsettings.Production.json (overrides for production)
139+
#
140+
# Effects in application:
141+
# - Production: Uses Azure Key Vault for secrets, production logging
142+
# - Development: Uses local appsettings.Development.json
143+
#
144+
# Since only Master deploys, this is always "Production"
145+
- name: Set Azure App Settings
146+
uses: azure/appservice-settings@v1
147+
with:
148+
app-name: ${{ secrets.AZURE_WEBAPP_NAME }}
149+
app-settings-json: |
150+
[
151+
{
152+
"name": "ThirdPartyApi__BaseUrl",
153+
"value": "${{ secrets.THIRDPARTY_API_BASEURL }}",
154+
"slotSetting": false
155+
},
156+
{
157+
"name": "ASPNETCORE_ENVIRONMENT",
158+
"value": "Production",
159+
"slotSetting": false
160+
}
161+
]
162+
continue-on-error: true # Optional: if service principal not configured yet
163+
164+
# ===== Health Check =====
165+
# Verifies the deployed application is running by calling /health endpoint
166+
# Waits 30 seconds for application startup before checking
167+
- name: Health Check
168+
run: |
169+
echo "Waiting 30 seconds for app to start..."
170+
sleep 30
171+
curl -f https://${{ secrets.AZURE_WEBAPP_NAME }}.azurewebsites.net/health || echo "Health check failed, but deployment completed"
172+
continue-on-error: true
173+
174+
# ===================================================================
175+
# JOB 3: SECURITY SCAN (OPTIONAL)
176+
# ===================================================================
177+
# Purpose: Scans for security vulnerabilities using Trivy
178+
# Runs on: Pull requests only (not on direct pushes)
179+
# Output: Security report uploaded to GitHub Security tab
180+
security-scan:
181+
name: Security Scan
182+
runs-on: ubuntu-latest
183+
if: github.event_name == 'pull_request' # Only run on PRs
184+
185+
steps:
186+
- name: Checkout code
187+
uses: actions/checkout@v4
188+
189+
- name: Run Trivy vulnerability scanner
190+
uses: aquasecurity/trivy-action@master
191+
with:
192+
scan-type: 'fs'
193+
scan-ref: '.'
194+
format: 'sarif'
195+
output: 'trivy-results.sarif'
196+
continue-on-error: true
197+
198+
- name: Upload Trivy results to GitHub Security tab
199+
uses: github/codeql-action/upload-sarif@v2
200+
with:
201+
sarif_file: 'trivy-results.sarif'
202+
continue-on-error: true
203+
204+
# ===================================================================
205+
# *** WORKFLOW BEHAVIOR SUMMARY ***
206+
# ===================================================================
207+
#
208+
# ┌─────────────────┬───────┬───────┬────────┬─────────────┐
209+
# │ Trigger │ Build │ Test │ Deploy │ Environment │
210+
# ├─────────────────┼───────┼───────┼────────┼─────────────┤
211+
# │ Push to Master │ ✅ │ ✅ │ ✅ │ Production │
212+
# │ Push to Dev │ ✅ │ ✅ │ ❌ │ N/A │
213+
# │ PR to Master │ ✅ │ ✅ │ ❌ │ N/A │
214+
# │ PR to Dev │ ✅ │ ✅ │ ❌ │ N/A │
215+
# └─────────────────┴───────┴───────┴────────┴─────────────┘
216+
#
217+
# DEPLOYMENT FLOW (Master branch only):
218+
# 1. Developer pushes to Master
219+
# 2. Build job: Restore → Build → Test → Publish → Upload artifact
220+
# 3. Deploy job: Download artifact → Deploy to Azure → Configure settings
221+
# 4. Health check verifies deployment success
222+
# 5. Application runs with ASPNETCORE_ENVIRONMENT=Production
223+
#
224+
# DEVELOPMENT FLOW (Dev branch):
225+
# 1. Developer pushes to Dev
226+
# 2. Build job: Restore → Build → Test → Publish → Upload artifact
227+
# 3. Deploy job: SKIPPED (does not run)
228+
# 4. Artifact available for manual inspection if needed
229+
#
230+
# PULL REQUEST FLOW:
231+
# 1. Developer opens PR
232+
# 2. Build job: Restore → Build → Test → Publish
233+
# 3. Security scan job: Runs Trivy vulnerability scanner
234+
# 4. Deploy job: SKIPPED (does not run)
235+
# 5. Results available for review before merging
236+
#
237+
# ===================================================================

0 commit comments

Comments
 (0)