Skip to content

Commit 58046d7

Browse files
authored
Merge pull request #79 from Metaswitch/issue/78/flexconsumption
Switch to FlexConsumption plan for Function App
2 parents 4a58314 + 2708dfc commit 58046d7

File tree

16 files changed

+94
-144
lines changed

16 files changed

+94
-144
lines changed

.flake8

Lines changed: 0 additions & 34 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Copyright (c) Alianza, Inc. All rights reserved.
12
name: Lint
23

34
on: [push]

CHANGELOG.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,18 @@ Status: Available for use
1717

1818
### Fixed
1919

20+
## [1.0.0] - 2025-10-02
21+
22+
### Breaking Changes
23+
- Switch to using FlexConsumption as Consumption apps are being deprecated.
24+
2025
## [0.1.0] - 2024-05-16
2126

2227
### Added
2328
- Initial release
2429

2530
### Changed
2631

27-
[unreleased]: https://github.com/microsoft/apt-package-function/compare/0.1.0...HEAD
28-
[0.1.0]: https://github.com/microsoft/apt-package-function/tree/0.1.0
32+
[unreleased]: https://github.com/Metaswitch/apt-package-function/compare/1.0.0...HEAD
33+
[1.0.0]: https://github.com/Metaswitch/apt-package-function/compare/0.1.0...1.0.0
34+
[0.1.0]: https://github.com/Metaswitch/apt-package-function/tree/0.1.0

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Functionality to create a Debian package repository in Azure Blob Storage with
44
an Azure Function App to keep it up to date. For use with
5-
[apt-transport-blob](https://github.com/microsoft/apt-transport-blob).
5+
[apt-transport-blob](https://github.com/Metaswitch/apt-transport-blob).
66

77
# Getting Started
88

function_app.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) Microsoft Corporation.
1+
# Copyright (c) Alianza, Inc. All rights reserved.
22
# Licensed under the MIT License.
33
"""A function app to manage a Debian repository in Azure Blob Storage."""
44

@@ -9,7 +9,7 @@
99
import os
1010
import tempfile
1111
from pathlib import Path
12-
from typing import Generator
12+
from typing import Generator, Optional
1313

1414
import azure.functions as func
1515
import pydpkg
@@ -32,12 +32,14 @@
3232
@contextlib.contextmanager
3333
def temporary_filename() -> Generator[str, None, None]:
3434
"""Create a temporary file and return the filename."""
35+
temporary_name: Optional[str] = None
3536
try:
3637
with tempfile.NamedTemporaryFile(delete=False) as f:
3738
temporary_name = f.name
3839
yield temporary_name
3940
finally:
40-
os.unlink(temporary_name)
41+
if temporary_name:
42+
os.unlink(temporary_name)
4143

4244

4345
class PackageBlob:

pyproject.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
# Copyright (c) Alianza, Inc. All rights reserved.
2+
# Highly Confidential Material
13
[project]
24
name = "apt-package-function"
35
description = "Functionality to create a Debian package repository in Azure Blob Storage"
46
license = "MIT"
5-
version = "0.1.0"
7+
version = "1.0.0"
68
readme = "README.md"
79
authors = [{name = "Max Dymond", email = "[email protected]"}]
810
requires-python = '>=3.9.2,<4.0.0'

rg.bicep

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ resource packageContainer 'Microsoft.Storage/storageAccounts/blobServices/contai
6363
properties: {
6464
}
6565
}
66-
resource pythonContainer 'Microsoft.Storage/storageAccounts/blobServices/containers@2025-01-01' = if (!use_shared_keys) {
66+
resource pythonContainer 'Microsoft.Storage/storageAccounts/blobServices/containers@2025-01-01' = {
6767
parent: defBlobServices
6868
name: python_container_name
6969
properties: {
@@ -122,14 +122,14 @@ az storage blob upload --auth-mode login -f Packages -c "${AZURE_BLOB_CONTAINER}
122122
}
123123
}
124124

125-
// Create the function app directly, if shared key support is enabled
126-
module funcapp 'rg_funcapp.bicep' = if (use_shared_keys) {
125+
// Create the function app directly
126+
module funcapp 'rg_funcapp.bicep' = {
127127
name: 'funcapp${suffix}'
128128
params: {
129129
location: location
130130
storage_account_name: storageAccount.name
131131
appName: appName
132-
use_shared_keys: true
132+
use_shared_keys: use_shared_keys
133133
suffix: suffix
134134
}
135135
}
@@ -139,4 +139,4 @@ output apt_sources string = 'deb [trusted=yes] blob://${storageAccount.name}.blo
139139
output function_app_name string = appName
140140
output storage_account string = storageAccount.name
141141
output package_container string = packageContainer.name
142-
output python_container string = use_shared_keys ? '' : pythonContainer.name
142+
output python_container string = pythonContainer.name

rg_funcapp.bicep

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ var package_container_name = 'packages'
2727
// Create a container for the Python code
2828
var python_container_name = 'python'
2929

30+
var storage_connection_string = 'DefaultEndpointsProtocol=https;AccountName=${storageAccount.name};EndpointSuffix=${environment().suffixes.storage};AccountKey=${storageAccount.listKeys().keys[0].value}'
31+
3032
// The version of Python to run with
3133
var python_version = '3.11'
3234

@@ -50,7 +52,7 @@ resource packageContainer 'Microsoft.Storage/storageAccounts/blobServices/contai
5052
parent: defBlobServices
5153
name: package_container_name
5254
}
53-
resource pythonContainer 'Microsoft.Storage/storageAccounts/blobServices/containers@2025-01-01' existing = if (!use_shared_keys) {
55+
resource pythonContainer 'Microsoft.Storage/storageAccounts/blobServices/containers@2025-01-01' existing = {
5456
parent: defBlobServices
5557
name: python_container_name
5658
}
@@ -65,12 +67,14 @@ resource storageBlobDataContributorRoleAssignment 'Microsoft.Authorization/roleA
6567
}
6668

6769
// Create a hosting plan for the function app
70+
// Using Flex Consumption plan for serverless hosting with enhanced features
71+
// Reference: https://learn.microsoft.com/en-us/azure/azure-functions/flex-consumption-plan
6872
resource hostingPlan 'Microsoft.Web/serverfarms@2024-11-01' = {
6973
name: hostingPlanName
7074
location: location
7175
sku: {
72-
name: 'Y1'
73-
tier: 'Dynamic'
76+
name: 'FC1'
77+
tier: 'FlexConsumption'
7478
}
7579
properties: {
7680
reserved: true
@@ -90,18 +94,10 @@ resource applicationInsights 'Microsoft.Insights/components@2020-02-02' = {
9094

9195
// Construct the app settings
9296
var common_settings = [
93-
{
94-
name: 'FUNCTIONS_EXTENSION_VERSION'
95-
value: '~4'
96-
}
9797
{
9898
name: 'APPINSIGHTS_INSTRUMENTATIONKEY'
9999
value: applicationInsights.properties.InstrumentationKey
100100
}
101-
{
102-
name: 'FUNCTIONS_WORKER_RUNTIME'
103-
value: 'python'
104-
}
105101
// Pass the blob container name to the function app - this is the
106102
// container which is monitored for new packages.
107103
{
@@ -114,32 +110,56 @@ var common_settings = [
114110
var app_settings = use_shared_keys ? concat(common_settings, [
115111
{
116112
name: 'AzureWebJobsStorage'
117-
value: 'DefaultEndpointsProtocol=https;AccountName=${storageAccount.name};EndpointSuffix=${environment().suffixes.storage};AccountKey=${storageAccount.listKeys().keys[0].value}'
113+
value: storage_connection_string
118114
}
119115
{
120-
name: 'WEBSITE_CONTENTAZUREFILECONNECTIONSTRING'
121-
value: 'DefaultEndpointsProtocol=https;AccountName=${storageAccount.name};EndpointSuffix=${environment().suffixes.storage};AccountKey=${storageAccount.listKeys().keys[0].value}'
122-
}
123-
{
124-
name: 'WEBSITE_CONTENTSHARE'
125-
value: toLower(functionAppName)
116+
name: 'DEPLOYMENT_STORAGE_CONNECTION_STRING'
117+
value: storage_connection_string
126118
}
127119
]) : concat(common_settings, [
128120
{
129121
name: 'AzureWebJobsStorage__accountName'
130122
value: storageAccount.name
131123
}
132-
{
133-
name: 'WEBSITE_RUN_FROM_PACKAGE'
134-
value: 'https://${storageAccount.name}.blob.${environment().suffixes.storage}/${pythonContainer.name}/function_app.zip'
135-
}
136-
// Pass the container URL to the function app for the `from_container_url` call.
137124
{
138125
name: 'BLOB_CONTAINER_URL'
139126
value: 'https://${storageAccount.name}.blob.${environment().suffixes.storage}/${packageContainer.name}/'
140127
}
141128
])
142129

130+
var function_runtime = {
131+
name: 'python'
132+
version: python_version
133+
}
134+
135+
var deployment_storage_value = 'https://${storageAccount.name}.blob.${environment().suffixes.storage}/${pythonContainer.name}'
136+
137+
var deployment_authentication = use_shared_keys ? {
138+
type: 'StorageAccountConnectionString'
139+
storageAccountConnectionStringName: 'DEPLOYMENT_STORAGE_CONNECTION_STRING'
140+
} : {
141+
type: 'SystemAssignedIdentity'
142+
}
143+
144+
var flex_deployment_configuration = {
145+
storage: {
146+
type: 'blobContainer'
147+
value: deployment_storage_value
148+
authentication: deployment_authentication
149+
}
150+
}
151+
152+
var flex_scale_and_concurrency = {
153+
maximumInstanceCount: 100
154+
instanceMemoryMB: 2048
155+
}
156+
157+
var function_app_config = {
158+
runtime: function_runtime
159+
scaleAndConcurrency: flex_scale_and_concurrency
160+
deployment: flex_deployment_configuration
161+
}
162+
143163
// Create the function app.
144164
resource functionApp 'Microsoft.Web/sites@2024-11-01' = {
145165
name: functionAppName
@@ -152,13 +172,12 @@ resource functionApp 'Microsoft.Web/sites@2024-11-01' = {
152172
properties: {
153173
serverFarmId: hostingPlan.id
154174
siteConfig: {
155-
linuxFxVersion: 'Python|${python_version}'
156-
pythonVersion: python_version
157175
appSettings: app_settings
158176
ftpsState: 'FtpsOnly'
159177
minTlsVersion: '1.2'
160178
}
161179
httpsOnly: true
180+
functionAppConfig: function_app_config
162181
}
163182
}
164183

ruff.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Copyright (c) Alianza, Inc. All rights reserved.
12
exclude = [
23
".venv",
34
"__pycache__",
@@ -56,4 +57,4 @@ indent-style = "space"
5657
skip-magic-trailing-comma = false
5758

5859
# Like Black, automatically detect the appropriate line ending.
59-
line-ending = "auto"
60+
line-ending = "auto"

src/apt_package_function/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) Microsoft Corporation.
1+
# Copyright (c) Alianza, Inc. All rights reserved.
22
# Licensed under the MIT License.
33
"""Tooling for creating apt repositories in Azure."""
44

0 commit comments

Comments
 (0)