Skip to content

Commit e548803

Browse files
committed
Switch to FlexConsumption plan for Function App
Microsoft are deprecating the Consumption plan for Linux Function Apps, so we needed to switch over to FlexConsumption. Fixes #78
1 parent 4a58314 commit e548803

File tree

16 files changed

+83
-134
lines changed

16 files changed

+83
-134
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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

rg_funcapp.bicep

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,14 @@ resource storageBlobDataContributorRoleAssignment 'Microsoft.Authorization/roleA
6565
}
6666

6767
// Create a hosting plan for the function app
68+
// Using Flex Consumption plan for serverless hosting with enhanced features
69+
// Reference: https://learn.microsoft.com/en-us/azure/azure-functions/flex-consumption-plan
6870
resource hostingPlan 'Microsoft.Web/serverfarms@2024-11-01' = {
6971
name: hostingPlanName
7072
location: location
7173
sku: {
72-
name: 'Y1'
73-
tier: 'Dynamic'
74+
name: 'FC1'
75+
tier: 'FlexConsumption'
7476
}
7577
properties: {
7678
reserved: true
@@ -90,18 +92,10 @@ resource applicationInsights 'Microsoft.Insights/components@2020-02-02' = {
9092

9193
// Construct the app settings
9294
var common_settings = [
93-
{
94-
name: 'FUNCTIONS_EXTENSION_VERSION'
95-
value: '~4'
96-
}
9795
{
9896
name: 'APPINSIGHTS_INSTRUMENTATIONKEY'
9997
value: applicationInsights.properties.InstrumentationKey
10098
}
101-
{
102-
name: 'FUNCTIONS_WORKER_RUNTIME'
103-
value: 'python'
104-
}
10599
// Pass the blob container name to the function app - this is the
106100
// container which is monitored for new packages.
107101
{
@@ -129,17 +123,42 @@ var app_settings = use_shared_keys ? concat(common_settings, [
129123
name: 'AzureWebJobsStorage__accountName'
130124
value: storageAccount.name
131125
}
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.
137126
{
138127
name: 'BLOB_CONTAINER_URL'
139128
value: 'https://${storageAccount.name}.blob.${environment().suffixes.storage}/${packageContainer.name}/'
140129
}
141130
])
142131

132+
var function_runtime = {
133+
name: 'python'
134+
version: python_version
135+
}
136+
137+
var flex_deployment_configuration = {
138+
storage: {
139+
type: 'blobContainer'
140+
value: 'https://${storageAccount.name}.blob.${environment().suffixes.storage}/${pythonContainer.name}'
141+
authentication: {
142+
type: 'SystemAssignedIdentity'
143+
}
144+
}
145+
}
146+
147+
var flex_scale_and_concurrency = {
148+
maximumInstanceCount: 100
149+
instanceMemoryMB: 2048
150+
}
151+
152+
var function_app_config = use_shared_keys ? {
153+
runtime: function_runtime
154+
scaleAndConcurrency: flex_scale_and_concurrency
155+
} : union({
156+
runtime: function_runtime
157+
scaleAndConcurrency: flex_scale_and_concurrency
158+
}, {
159+
deployment: flex_deployment_configuration
160+
})
161+
143162
// Create the function app.
144163
resource functionApp 'Microsoft.Web/sites@2024-11-01' = {
145164
name: functionAppName
@@ -152,13 +171,12 @@ resource functionApp 'Microsoft.Web/sites@2024-11-01' = {
152171
properties: {
153172
serverFarmId: hostingPlan.id
154173
siteConfig: {
155-
linuxFxVersion: 'Python|${python_version}'
156-
pythonVersion: python_version
157174
appSettings: app_settings
158175
ftpsState: 'FtpsOnly'
159176
minTlsVersion: '1.2'
160177
}
161178
httpsOnly: true
179+
functionAppConfig: function_app_config
162180
}
163181
}
164182

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)