Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scheduled polling v1 #78

Merged
merged 60 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
77c83fd
try adding webjob resource
somesylvie Jul 8, 2024
2f7b800
add webjob script?
somesylvie Jul 8, 2024
5d117fe
update pathing
somesylvie Jul 8, 2024
63a093a
switch to source file not dir
somesylvie Jul 8, 2024
d7efc52
try some other command
somesylvie Jul 8, 2024
6f8a67e
try login first
somesylvie Jul 8, 2024
f45443b
take name off command
somesylvie Jul 8, 2024
566cbd8
make the name an empty string
somesylvie Jul 8, 2024
8f80514
take out webjob attempt
somesylvie Jul 8, 2024
f72c5fa
Start making an Azure Function for timer control
somesylvie Jul 8, 2024
cba6b43
update some TODOs
somesylvie Jul 8, 2024
ffd27d8
Add a bunch more notes, start TF for new queue
somesylvie Jul 8, 2024
e503a12
more TODO notes
somesylvie Jul 9, 2024
05a067d
Azure func terraform WIP
jherrflexion Jul 9, 2024
c9b76c4
Re-configure polling function app function
jherrflexion Jul 9, 2024
fc540e5
Attempting to fix Terraform errors
jherrflexion Jul 9, 2024
59445d0
Attempting fix for Terraform errors
jherrflexion Jul 9, 2024
8ff0219
WIP functions Terraform
jherrflexion Jul 9, 2024
010ff29
Add template for function app function deployment
saquino0827 Jul 10, 2024
d76a64b
created github workflow for node js function app
pluckyswan Jul 10, 2024
d65a8eb
updated function workflow call
pluckyswan Jul 10, 2024
a211db8
updated call to function workflow
pluckyswan Jul 10, 2024
874f6a9
Update github functions workflow with internal function publish profi…
saquino0827 Jul 11, 2024
2dd8760
Merge branch 'main' into scheduling
saquino0827 Jul 11, 2024
b047f88
re-remove the unneeded TF
somesylvie Jul 11, 2024
a21dca9
copy changes out of yesterday's `internal` branch
somesylvie Jul 11, 2024
3b227f6
put application insights in the right section
somesylvie Jul 11, 2024
22b1a7d
change a setting to cause terraform changes
somesylvie Jul 11, 2024
d4b1aeb
Added GetPublishProfile step
jherrflexion Jul 12, 2024
e44e743
Renamed function step
jherrflexion Jul 12, 2024
13bd37f
Fixed env variable name
jherrflexion Jul 12, 2024
4698f27
Removed deprecated set-output and masked the publish profile
jherrflexion Jul 12, 2024
094579a
Adding directory log for troubleshooting
jherrflexion Jul 15, 2024
1f6f75e
Testing new path
jherrflexion Jul 15, 2024
1449953
Testing function.json
jherrflexion Jul 15, 2024
2732515
Fixed file type
jherrflexion Jul 15, 2024
f70bc06
Fixed name
jherrflexion Jul 15, 2024
b50feb1
Renamed file to js
jherrflexion Jul 15, 2024
ba1b89d
update package path var for consistency; remove unneeded fuction.json
somesylvie Jul 15, 2024
5873e28
Merge branch 'scheduling' of https://github.com/CDCgov/reportstream-s…
somesylvie Jul 15, 2024
c394326
install azure functions core tools
somesylvie Jul 15, 2024
a6bbb85
updating pathing to match examples
somesylvie Jul 15, 2024
5fdbf4b
comment out code that won't work yet; add a new setting to function app
somesylvie Jul 15, 2024
2b6ed66
take out app_settings because the tf docs are wrong
somesylvie Jul 15, 2024
d1ae163
comment out env vars
somesylvie Jul 15, 2024
74545c3
set env vars and use them; remove add'l logging
somesylvie Jul 15, 2024
71146fc
change connection string and add Helpful Comments
somesylvie Jul 15, 2024
60bbf37
temporarily remove connection string for testing
somesylvie Jul 15, 2024
e327543
put connection string back
somesylvie Jul 15, 2024
24a8be0
try a health check?
somesylvie Jul 15, 2024
69f2a99
take out borked health check, add node_modules to funcignore
somesylvie Jul 15, 2024
b15117f
let's try another setting to build faster
somesylvie Jul 15, 2024
f018414
first try at a health check
somesylvie Jul 15, 2024
51a88e4
just look for function name
somesylvie Jul 15, 2024
d49c44a
let's break this again
somesylvie Jul 15, 2024
29e3093
turn off actual enqueueing for now, add some comments for later, remo…
somesylvie Jul 15, 2024
b864f28
README, ADR, and some cleanup
somesylvie Jul 15, 2024
752b314
do some cleanup
somesylvie Jul 15, 2024
cc73b65
terraform format
somesylvie Jul 15, 2024
498dac7
Merge branch 'main' into scheduling
somesylvie Jul 16, 2024
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
90 changes: 90 additions & 0 deletions .github/workflows/functions-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# TODO - currently this is only called from the `internal` deploy job. It should be part of all envs
name: Deploy Node.js project to Azure Function App

on:
workflow_call:
inputs:
ENVIRONMENT:
required: true
type: string
REGISTRY:
required: true
type: string
REPO:
required: true
type: string
APP:
required: true
type: string
secrets:
AZURE_CLIENT_ID:
required: true
AZURE_TENANT_ID:
required: true
AZURE_SUBSCRIPTION_ID:
required: true
AZURE_FUNCTIONAPP_PUBLISH_PROFILE:
required: true

permissions:
contents: read

env:
# AZURE_FUNCTIONAPP_NAME has to match the azurerm_linux_function_app's name in functions.tf
AZURE_FUNCTIONAPP_NAME: 'polling-function-${{ inputs.ENVIRONMENT }}'
AZURE_FUNCTIONAPP_PACKAGE_PATH: 'azure_functions'
NODE_VERSION: '20.x'

jobs:
build-and-deploy:
jherrflexion marked this conversation as resolved.
Show resolved Hide resolved
runs-on: ubuntu-latest
environment:
${{ inputs.ENVIRONMENT }}
permissions:
id-token: write
contents: read

steps:
- name: 'Checkout GitHub Action'
uses: actions/checkout@v4

- name: 'Setup Node ${{ env.NODE_VERSION }} Environment'
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}

- name: 'Resolve Project Dependencies Using Npm'
shell: bash
run: |
pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}'
npm install
npm run build --if-present
npm run test --if-present
popd
- name: 'Login via Azure CLI'
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

- name: 'Get Publish Profile'
run: |
PUBLISH_PROFILE=$(az webapp deployment list-publishing-profiles -g "csels-rsti-${{ inputs.ENVIRONMENT }}-moderate-rg" -n "polling-function-${{ inputs.ENVIRONMENT }}" --xml)
echo "::add-mask::$PUBLISH_PROFILE"
echo "PUBLISH_PROFILE=$PUBLISH_PROFILE" >> $GITHUB_OUTPUT
id: getPublishProfile

- name: 'Run Azure Functions Action'
uses: Azure/functions-action@v1
id: azure-function-deploy
with:
app-name: ${{ env.AZURE_FUNCTIONAPP_NAME }}
package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
publish-profile: ${{ steps.getPublishProfile.outputs.PUBLISH_PROFILE }}

# TODO: Add a step to report failure on Azure Function App Func creation
# Currently, if there's a bug in the function code or it tries to use an environment variable that doesn't exist
# or has an invalid value, the Github Action Step will complete successfully but the function code will NOT be
# deployed, and any previous version of the function will be removed
19 changes: 19 additions & 0 deletions .github/workflows/internal-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Deploy to Internal Environment

on:
workflow_call:
secrets:
AZURE_FUNCTIONAPP_PUBLISH_PROFILE_INTERNAL:
required: true
push:
branches:
- internal
Expand Down Expand Up @@ -32,3 +36,18 @@ jobs:
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

function-deploy:
name: Function Deploy
needs: terraform-deploy
uses: ./.github/workflows/functions-deploy.yml
with:
ENVIRONMENT: internal
REPO: report-stream-sftp-ingest
APP: ${{ needs.terraform-deploy.outputs.APP }}
REGISTRY: ${{ needs.terraform-deploy.outputs.REGISTRY }}
secrets:
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
AZURE_FUNCTIONAPP_PUBLISH_PROFILE: ${{ secrets.AZURE_FUNCTIONAPP_PUBLISH_PROFILE_INTERNAL }}
103 changes: 103 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,113 @@ reportstream-sftp-ingestion

# IDE files
.idea/
.vscode/

# Ignore terraform state (as it is persisted via Azure Storage)
terraform.tfstate*
.terraform*

# Local blob storage data
/localdata


# Items added by creating the Azure function:
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# next.js build output
.next

# nuxt.js build output
.nuxt

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TypeScript output
dist
out

# Azure Functions artifacts
bin
obj
appsettings.json
local.settings.json

# Azurite artifacts
__blobstorage__
__queuestorage__
__azurite_db*__.json
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ In the cloud, EventGrid monitors the blob storage container and sends file creat
In the local Azurite tool, there are no events to connect the blob storage container to the queue.
To mimic the deployed behavior so our app can read queue messages and access the file specified in the message:
1. Upload a file to your local Azurite sftp container
2. In Azure Storage Explorer, find the `blob-message-queue` that the service currently reads from
2. In Azure Storage Explorer, find the `message-import-queue` that the service currently reads from
3. Add a file create event message to that queue. You can start with this base message and edit the `subject` to
match your newly-created file
```json
Expand Down Expand Up @@ -174,6 +174,7 @@ occur when a release is published.

## Related documents

* [Azure Functions and Typescript](/azure_functions/src/README.md)
* [Open Practices](/docs/open_practices.md)
* [Rules of Behavior](/docs/rules_of_behavior.md)
* [Thanks and Acknowledgements](/docs/thanks.md)
Expand Down
18 changes: 18 additions & 0 deletions adr/009-typescript-and-azure-functions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 9. Typescript and Azure Functions

Date: 2024-07-15

## Decision

We're using Azure Functions for scheduled tasks. Azure Functions support a CRON
expression trigger, which most other Azure resources do not. Azure Webjobs are
supposed to work with CRON triggers, but don't seem to work well with Linux servers since they are in preview.

We're using Typescript for Azure Functions.
Go is not well-supported (it requires special handlers). Of the well-supported
language options, Typescript is lighter-weight than Java or C# and more
familiar to the team than Python.

## Status

Accepted.
Binary file added azure_functions/.DS_Store
Binary file not shown.
11 changes: 11 additions & 0 deletions azure_functions/.funcignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
*.js.map
*.ts
.git*
.vscode
__azurite_db*__.json
__blobstorage__
__queuestorage__
local.settings.json
test
tsconfig.json
node_modules/
15 changes: 15 additions & 0 deletions azure_functions/host.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[4.*, 5.0.0)"
}
}
Loading