Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"recommendations": [
"ms-azuretools.vscode-azurefunctions",
"ms-vscode.PowerShell"
]
}
20 changes: 14 additions & 6 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,24 @@
"request": "launch",
"module": "flask",
"env": {
"FLASK_APP": "ops_api.ops:create_app()",
"FLASK_DEBUG": "1",
"FLASK_RUN_PORT": "8080",
"PYTHONPATH": "./backend"
"FLASK_APP": "ops_api.ops:create_app()",
"FLASK_DEBUG": "1",
"FLASK_RUN_PORT": "8080",
"PYTHONPATH": "./backend"
},
"args": [
"run"
"run"
],
"jinja": true,
"justMyCode": true
}
},
{
"name": "Attach to PowerShell Functions",
"type": "PowerShell",
"request": "attach",

"runspaceId": 1,
"preLaunchTask": "func: host start"
}
]
}
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,10 @@
"database": "postgres",
"username": "ops"
}
]
],
"azureFunctions.deploySubpath": "backend/data_tools/scripts/azure",
"azureFunctions.projectLanguage": "PowerShell",
"azureFunctions.projectRuntime": "~4",
"debug.internalConsoleOptions": "neverOpen",
"azureFunctions.projectSubpath": "backend/data_tools/scripts/azure"
}
14 changes: 13 additions & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
{
"type": "docker-run",
"label": "docker-run: debug",
"dependsOn": ["docker-build"],
"dependsOn": [
"docker-build"
],
"dockerRun": {
"containerName": "ops-api",
"image": "ops-api:debug-latest",
Expand Down Expand Up @@ -64,6 +66,16 @@
"kind": "build",
"isDefault": true
}
},
{
"type": "func",
"label": "func: host start",
"command": "host start",
"problemMatcher": "$func-powershell-watch",
"isBackground": true,
"options": {
"cwd": "${workspaceFolder}/backend/data_tools/scripts/azure"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"bindings": [
{
"name": "InputBlob",
"type": "blobTrigger",
"direction": "in",
"path": "spreadsheet-ingest/{name}",
"source": "EventGrid",
"connection": "0f8545_STORAGE"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# EventGridBlobTrigger - PowerShell

The `EventGridBlobTrigger` makes it incredibly easy to react to new Blobs using [Event Grid](https://learn.microsoft.com/en-us/azure/event-grid/overview).
This sample demonstrates a simple use case of processing data from a given Blob using PowerShell.

## How it works

For a `EventGridBlobTrigger` to work, you provide a path which dictates where the blobs are located inside your container, and can also help restrict the types of blobs you wish to return. For instance, you can set the path to `samples/{name}.png` to restrict the trigger to only the samples path and only blobs with ".png" at the end of their name.

## Learn more

For more information, please check out [this tutorial](https://learn.microsoft.com/en-us/azure/azure-functions/functions-event-grid-blob-trigger?tabs=isolated-process%2Cnodejs-v4&pivots=programming-language-powershell) on this new version of the Blob Storage trigger.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Input bindings are passed in via param block.
param([byte[]] $InputBlob, $TriggerMetadata)

# Write out the blob name and size to the information log.
Write-Host "PowerShell Blob trigger function Processed blob! Name: $($TriggerMetadata.Name) Size: $($InputBlob.Length) bytes"
az containerapp job start --name "opre-ops-dev-app-blis-myltest" --resource-group "opre-ops-dev-app-rg" --cpu 0.5 --memory "1Gi" --image ghcr.io/hhs/opre-ops/ops-data-tools:d1d5a0d742c8d60797cdc1ba51b6fe85cf8b0fd9 --command "/bin/sh" "./data_tools/scripts/load_data.sh" --args "dev" "master_spreadsheet_budget_lines" $TriggerMetadata.Name
# az containerapp job start --name "opre-ops-dev-app-blis-myltest" --resource-group "opre-ops-dev-app-rg" --cpu 0.5 --memory "1Gi" --image ghcr.io/hhs/opre-ops/ops-data-tools:d1d5a0d742c8d60797cdc1ba51b6fe85cf8b0fd9 --command "ls" "./data_tools/scripts"
12 changes: 12 additions & 0 deletions backend/data_tools/scripts/azure/host.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": "2.0",
"isDefaultHostConfig": true,
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[4.*, 5.0.0)"
},
"concurrency": {
"dynamicConcurrencyEnabled": true,
"snapshotPersistenceEnabled": true
}
}
8 changes: 8 additions & 0 deletions backend/data_tools/scripts/azure/local.settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"IsEncrypted": false,
"Values": {
"0f8545_STORAGE": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "powershell",
"AzureWebJobsStorage": "UseDevelopmentStorage=true"
}
}
22 changes: 22 additions & 0 deletions backend/data_tools/scripts/azure/profile.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Azure Functions profile.ps1
#
# This profile.ps1 will get executed every "cold start" of your Function App.
# "cold start" occurs when:
#
# * A Function App starts up for the very first time
# * A Function App starts up after being de-allocated due to inactivity
#
# You can define helper functions, run commands, or specify environment variables
# NOTE: any variables defined that are not environment variables will get reset after the first execution

# Authenticate with Azure PowerShell using MSI.
# Remove this if you are not planning on using MSI or Azure PowerShell.
if ($env:MSI_SECRET) {
Disable-AzContextAutosave -Scope Process | Out-Null
Connect-AzAccount -Identity
}

# Uncomment the next line to enable legacy AzureRm alias in Azure PowerShell.
# Enable-AzureRmAlias

# You can also define functions or aliases that can be referenced in any of your PowerShell functions.
8 changes: 8 additions & 0 deletions backend/data_tools/scripts/azure/requirements.psd1
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# This file enables modules to be automatically managed by the Functions service.
# See https://aka.ms/functionsmanageddependency for additional information.
#
@{
# For latest supported version, go to 'https://www.powershellgallery.com/packages/Az'.
# To use the Az module in your function app, please uncomment the line below.
# 'Az' = '13.*'
}