Skip to content

Commit aef06d2

Browse files
committed
Add node sample app
1 parent 8fcf9e8 commit aef06d2

Some content is hidden

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

93 files changed

+15383
-0
lines changed

Diff for: az400.code-workspace

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"folders": [
3+
{
4+
"path": "."
5+
}
6+
],
7+
"settings": {
8+
"terminal.integrated.profiles.windows": {
9+
"PowerShell (Admin)": {
10+
"path": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
11+
"args": [
12+
"-NoExit",
13+
"-Command",
14+
"Start-Process pwsh -Verb RunAs"
15+
]
16+
}
17+
},
18+
"terminal.integrated.defaultProfile.windows": "PowerShell (Admin)"
19+
}
20+
}

Diff for: nodeapp-1/.azure/cd.yml

+111
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
trigger: none # Keeps manual trigger option
2+
3+
# Add trigger for CI pipeline completion
4+
resources:
5+
pipelines:
6+
- pipeline: nodeci
7+
source: node-simple-ci
8+
trigger: true # Triggers when CI pipeline completes successfully
9+
10+
variables:
11+
- group: nodeapp-cd-variables
12+
13+
pool:
14+
vmImage: 'ubuntu-latest'
15+
16+
stages:
17+
- stage: Infrastructure
18+
jobs:
19+
- job: DeployInfrastructure
20+
steps:
21+
- download: nodeci # Download artifacts from the CI pipeline
22+
artifact: drop
23+
24+
- task: AzureResourceManagerTemplateDeployment@3
25+
inputs:
26+
deploymentScope: 'Resource Group'
27+
azureResourceManagerConnection: 'Azure Pass Azure Subscription'
28+
subscriptionId: '$(subscriptionId)'
29+
action: 'Create Or Update Resource Group'
30+
resourceGroupName: '$(resourceGroup)'
31+
location: '$(location)'
32+
templateLocation: 'Linked artifact'
33+
csmFile: '$(System.DefaultWorkingDirectory)/azuredeploy.json'
34+
overrideParameters: '-site_host_name "$(webAppName)" -app_svc_plan_name "$(webAppName)-plan"'
35+
deploymentMode: 'Incremental'
36+
37+
- stage: Staging
38+
dependsOn: Infrastructure
39+
jobs:
40+
- job: DeployStaging
41+
steps:
42+
- task: AzureWebApp@1
43+
inputs:
44+
azureSubscription: 'Azure Pass Azure Subscription'
45+
appName: '$(webAppName)-staging'
46+
package: '$(Pipeline.Workspace)/nodeci/drop/$(Build.BuildId).zip'
47+
deployToSlotOrASE: true
48+
resourceGroupName: '$(resourceGroup)'
49+
slotName: 'staging'
50+
51+
- task: AzureAppServiceManage@0
52+
inputs:
53+
azureSubscription: 'Azure Pass Azure Subscription'
54+
Action: 'Start Azure App Service'
55+
WebAppName: '$(webAppName)'
56+
SpecifySlot: true
57+
ResourceGroupName: '$(resourceGroup)'
58+
Slot: 'staging'
59+
60+
- task: AzureMonitor@1
61+
inputs:
62+
azureSubscription: 'Azure Pass Azure Subscription'
63+
ResourceGroupName: '$(resourceGroup)'
64+
ResourceType: 'Microsoft.Web/sites'
65+
ResourceName: '$(webAppName)'
66+
AlertRules: |
67+
[
68+
{
69+
"alertName": "HTTP 5xx Errors",
70+
"metric": "Http5xx",
71+
"operator": "GreaterThan",
72+
"threshold": "0",
73+
"timeAggregation": "Count",
74+
"actionGroupId": "/subscriptions/$(subscriptionId)/resourceGroups/$(resourceGroup)/providers/microsoft.insights/actionGroups/emailalert"
75+
}
76+
]
77+
78+
- stage: Production
79+
dependsOn: Staging
80+
jobs:
81+
- deployment: Production
82+
environment: Production
83+
strategy:
84+
runOnce:
85+
deploy:
86+
steps:
87+
- task: AzureWebApp@1
88+
inputs:
89+
azureSubscription: 'Azure Pass Azure Subscription'
90+
appName: '$(webAppName)'
91+
package: '$(Pipeline.Workspace)/nodeci/drop/$(Build.BuildId).zip'
92+
deployToSlotOrASE: false
93+
94+
- task: AzureAppServiceSettings@1
95+
inputs:
96+
azureSubscription: 'Azure Pass Azure Subscription'
97+
appName: '$(webAppName)'
98+
resourceGroupName: '$(resourceGroup)'
99+
appSettings: |
100+
[
101+
{
102+
"name": "WEBSITE_NODE_DEFAULT_VERSION",
103+
"value": "~18",
104+
"slotSetting": false
105+
},
106+
{
107+
"name": "APPINSIGHTS_INSTRUMENTATIONKEY",
108+
"value": "$(appInsightsKey)",
109+
"slotSetting": false
110+
}
111+
]

Diff for: nodeapp-1/.azure/ci.yml

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
trigger:
2+
- main
3+
4+
variables:
5+
NODE_VERSION: '18.x'
6+
# Add feed variables
7+
npm_config_registry: 'https://pkgs.dev.azure.com/certstarorg/_packaging/az400-npm-feed/npm/registry/'
8+
9+
pool:
10+
vmImage: 'ubuntu-latest'
11+
12+
steps:
13+
- task: NodeTool@0
14+
inputs:
15+
versionSpec: $(NODE_VERSION)
16+
displayName: 'Install Node.js'
17+
18+
- task: npmAuthenticate@0
19+
inputs:
20+
workingFile: .npmrc
21+
22+
- script: |
23+
npm install
24+
npm install -g mocha
25+
npm install mochawesome
26+
displayName: 'Install Dependencies'
27+
28+
- script: |
29+
node app.js & sleep 5
30+
npm test -- --reporter mochawesome
31+
kill %1
32+
displayName: 'Start App and Run Tests'
33+
continueOnError: true
34+
35+
- task: PublishTestResults@2
36+
inputs:
37+
testResultsFormat: 'JUnit'
38+
testResultsFiles: '**/mochawesome.xml'
39+
mergeTestResults: true
40+
testRunTitle: 'Mocha Tests'
41+
42+
- task: ArchiveFiles@2
43+
inputs:
44+
rootFolderOrFile: '$(System.DefaultWorkingDirectory)'
45+
includeRootFolder: false
46+
archiveType: 'zip'
47+
archiveFile: '$(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip'
48+
replaceExistingArchive: true
49+
exclude: |
50+
node_modules/**
51+
test/**
52+
.git/**
53+
displayName: 'Archive Build'
54+
55+
- task: PublishBuildArtifacts@1
56+
inputs:
57+
pathToPublish: '$(Build.ArtifactStagingDirectory)'
58+
artifactName: 'drop'
59+
displayName: 'Publish Build Artifacts'
60+
61+
# Add package publishing step
62+
- script: |
63+
npm version patch
64+
npm publish --registry=https://pkgs.dev.azure.com/certstarorg/_packaging/az400-npm-dev/npm/registry/
65+
displayName: 'Publish to Development Feed'
66+
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/main'))

Diff for: nodeapp-1/.azure/package-promotion.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
trigger: none # Manual trigger only
2+
3+
parameters:
4+
- name: packageVersion
5+
type: string
6+
displayName: 'Package Version to Promote'
7+
- name: environment
8+
type: string
9+
displayName: 'Target Environment'
10+
default: 'prod'
11+
values:
12+
- prod
13+
14+
variables:
15+
- group: npm-publish-variables
16+
17+
pool:
18+
vmImage: 'ubuntu-latest'
19+
20+
steps:
21+
- task: npmAuthenticate@0
22+
inputs:
23+
workingFile: .npmrc
24+
25+
- script: |
26+
# Download from dev feed
27+
npm install @certstarorg/node-express-azure@${{ parameters.packageVersion }} --registry=https://pkgs.dev.azure.com/certstarorg/_packaging/az400-npm-dev/npm/registry/
28+
29+
# Run validation tests
30+
npm test
31+
displayName: 'Download and Validate Package'
32+
33+
- task: ManualValidation@0
34+
inputs:
35+
notifyUsers: '$(approverEmail)'
36+
instructions: 'Please validate package version ${{ parameters.packageVersion }} before promotion to ${{ parameters.environment }}'
37+
38+
- script: |
39+
# Publish to production feed
40+
npm publish --registry=https://pkgs.dev.azure.com/certstarorg/_packaging/az400-npm-${{ parameters.environment }}/npm/registry/
41+
displayName: 'Promote Package'
42+
condition: succeeded()

Diff for: nodeapp-1/.azure/push-to-github.yml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Push to GitHub
2+
3+
on:
4+
# Manual trigger
5+
workflow_dispatch:
6+
# Optional: Automatically push on changes to main
7+
push:
8+
branches:
9+
- main
10+
11+
jobs:
12+
push-to-github:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
20+
- name: Configure Git
21+
run: |
22+
git config --global user.name "GitHub Actions"
23+
git config --global user.email "[email protected]"
24+
25+
- name: Push to target repository
26+
env:
27+
GITHUB_TOKEN: ${{ secrets.PUSH_TOKEN }}
28+
run: |
29+
git remote add target https://${{ secrets.PUSH_TOKEN }}@github.com/timothywarner/nodeapp.git
30+
git push --force target HEAD:main

Diff for: nodeapp-1/.devcontainer/devcontainer.json

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
{
2+
"name": "AZ-400 Node.js Development Environment",
3+
"image": "mcr.microsoft.com/devcontainers/javascript-node:18-bullseye",
4+
"features": {
5+
"ghcr.io/devcontainers/features/node:1": {
6+
"version": "18",
7+
"nodeGypDependencies": false
8+
},
9+
"ghcr.io/devcontainers/features/azure-cli:1": {},
10+
"ghcr.io/devcontainers/features/github-cli:1": {},
11+
"ghcr.io/devcontainers/features/docker-in-docker:2": {
12+
"version": "latest",
13+
"moby": true,
14+
"dockerDashComposeVersion": "v2"
15+
}
16+
},
17+
"customizations": {
18+
"vscode": {
19+
"extensions": [
20+
"dbaeumer.vscode-eslint",
21+
"esbenp.prettier-vscode",
22+
"GitHub.copilot",
23+
"GitHub.copilot-chat",
24+
"ms-azuretools.vscode-azureappservice",
25+
"ms-azuretools.vscode-docker",
26+
"ms-azure-devops.azure-pipelines",
27+
"ms-vscode.azure-account",
28+
"GitHub.vscode-pull-request-github"
29+
],
30+
"settings": {
31+
"terminal.integrated.defaultProfile.linux": "bash",
32+
"files.exclude": {
33+
"**/node_modules": true,
34+
"**/.git": true,
35+
"**/.DS_Store": true
36+
},
37+
"files.watcherExclude": {
38+
"**/node_modules/**": true,
39+
"**/dist/**": true
40+
},
41+
"search.exclude": {
42+
"**/node_modules": true,
43+
"**/bower_components": true
44+
}
45+
}
46+
}
47+
},
48+
"postCreateCommand": "npm ci && az extension add --name azure-devops --yes",
49+
"postStartCommand": "echo 'Container started at: ' $(date) >> /workspaces/.codespaces/.persistedshare/creation-time.log",
50+
"postAttachCommand": {
51+
"server": "npm start"
52+
},
53+
"forwardPorts": [3000],
54+
"portsAttributes": {
55+
"3000": {
56+
"label": "Node App",
57+
"onAutoForward": "openPreview"
58+
}
59+
},
60+
"hostRequirements": {
61+
"cpus": 4,
62+
"memory": "8gb",
63+
"storage": "32gb"
64+
},
65+
"remoteUser": "node",
66+
"remoteEnv": {
67+
"NODE_ENV": "development",
68+
"NPM_CONFIG_LOGLEVEL": "error",
69+
"CHOKIDAR_USEPOLLING": "false",
70+
"COMPOSE_HTTP_TIMEOUT": "120"
71+
},
72+
"mounts": [
73+
"source=${localEnv:HOME}${localEnv:USERPROFILE}/.azure,target=/home/node/.azure,type=bind",
74+
"source=node_modules,target=${containerWorkspaceFolder}/node_modules,type=volume"
75+
]
76+
}

Diff for: nodeapp-1/.gitattributes

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
public/* linguist-vendored
2+
views/* linguist-vendored

Diff for: nodeapp-1/.github/dependabot.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "npm"
4+
directory: "/"
5+
schedule:
6+
interval: "daily"

0 commit comments

Comments
 (0)