Skip to content

Commit 237eba5

Browse files
Copilotpaulyuk
andcommitted
Modernize FastAPI Azure Functions template with v2 programming model and Flex Consumption
Co-authored-by: paulyuk <1968137+paulyuk@users.noreply.github.com>
1 parent e87d9cc commit 237eba5

25 files changed

Lines changed: 1106 additions & 1844 deletions

.devcontainer/Dockerfile

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,27 @@
1-
ARG VARIANT=bullseye
2-
FROM --platform=amd64 mcr.microsoft.com/devcontainers/python:0-${VARIANT}
1+
FROM mcr.microsoft.com/vscode/devcontainers/universal:latest
2+
3+
# Copy custom first notice message.
4+
COPY first-run-notice.txt /tmp/staging/
5+
RUN sudo mv -f /tmp/staging/first-run-notice.txt /usr/local/etc/vscode-dev-containers/ \
6+
&& sudo rm -rf /tmp/staging
7+
8+
# Install PowerShell 7.x
9+
RUN sudo apt-get update \
10+
&& sudo apt-get install -y wget apt-transport-https software-properties-common \
11+
&& wget -q https://packages.microsoft.com/config/ubuntu/$(. /etc/os-release && echo $VERSION_ID)/packages-microsoft-prod.deb \
12+
&& sudo dpkg -i packages-microsoft-prod.deb \
13+
&& sudo apt-get update \
14+
&& sudo apt-get install -y powershell
15+
16+
# Install Azure Functions Core Tools
317
RUN curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg \
4-
&& mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg \
5-
&& sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/debian/$(lsb_release -rs | cut -d'.' -f 1)/prod $(lsb_release -cs) main" > /etc/apt/sources.list.d/dotnetdev.list' \
6-
&& apt-get update && apt-get install -y azure-functions-core-tools-4
18+
&& sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg \
19+
&& sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-$(lsb_release -cs)-prod $(lsb_release -cs) main" > /etc/apt/sources.list.d/dotnetdev.list' \
20+
&& sudo apt-get update \
21+
&& sudo apt-get install -y azure-functions-core-tools-4
22+
23+
# Install Azure Developer CLI
24+
RUN curl -fsSL https://aka.ms/install-azd.sh | bash
25+
26+
# Install mechanical-markdown for quickstart validations
27+
RUN pip install mechanical-markdown

.devcontainer/devcontainer.json

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,35 @@
11
{
2-
"name": "FastAPI on Azure Functions",
3-
"build": {
4-
"dockerfile": "Dockerfile",
5-
"args": {
6-
"VARIANT": "3.10-bullseye"
7-
}
8-
},
9-
"forwardPorts": [8000, 7071],
2+
"name": "Functions Quickstarts Codespace",
3+
"dockerFile": "Dockerfile",
104
"features": {
11-
"ghcr.io/devcontainers/features/node:1": {
12-
"version": "16",
13-
"nodeGypDependencies": false
14-
},
15-
"ghcr.io/azure/azure-dev/azd:latest": {}
5+
"azure-cli": "latest"
166
},
177
"customizations": {
18-
"vscode": {
19-
"extensions": [
20-
"ms-azuretools.azure-dev",
21-
"ms-azuretools.vscode-bicep",
22-
"ms-vscode.vscode-node-azure-pack",
23-
"ms-python.python",
24-
"ms-azuretools.vscode-azurefunctions"
25-
]
26-
}
8+
"vscode": {
9+
"extensions": [
10+
"ms-azuretools.vscode-bicep",
11+
"ms-azuretools.vscode-docker",
12+
"ms-azuretools.vscode-azurefunctions",
13+
"GitHub.copilot",
14+
"humao.rest-client"
15+
]
16+
}
2717
},
28-
"postCreateCommand": "python3 -m venv .venv",
29-
"postAttachCommand": ". .venv/bin/activate",
30-
"remoteUser": "vscode",
31-
"hostRequirements": {
32-
"memory": "8gb"
33-
}
34-
}
18+
"mounts": [
19+
// Mount docker-in-docker library volume
20+
"source=codespaces-linux-var-lib-docker,target=/var/lib/docker,type=volume"
21+
],
22+
// Always run image-defined docker-init.sh to enable docker-in-docker
23+
"overrideCommand": false,
24+
"remoteUser": "codespace",
25+
"runArgs": [
26+
// Enable ptrace-based debugging for Go in container
27+
"--cap-add=SYS_PTRACE",
28+
"--security-opt",
29+
"seccomp=unconfined",
30+
31+
// Enable docker-in-docker configuration
32+
"--init",
33+
"--privileged"
34+
]
35+
}

.devcontainer/first-run-notice.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
👋 Welcome to the Functions Codespace! You are on the Functions Quickstarts image.
2+
It includes everything needed to run through our tutorials and quickstart applications.
3+
4+
📚 Functions docs can be found at: https://learn.microsoft.com/en-us/azure/azure-functions/
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
name: Security Scans
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
schedule:
9+
- cron: '0 0 * * 0' # Weekly scan
10+
11+
permissions:
12+
actions: read
13+
contents: read
14+
security-events: write
15+
16+
jobs:
17+
codeql:
18+
name: CodeQL Analysis
19+
runs-on: ubuntu-latest
20+
21+
strategy:
22+
fail-fast: false
23+
matrix:
24+
language: [ 'python' ]
25+
26+
steps:
27+
- name: Checkout repository
28+
uses: actions/checkout@v4
29+
30+
- name: Initialize CodeQL
31+
uses: github/codeql-action/init@v2
32+
with:
33+
languages: ${{ matrix.language }}
34+
35+
- name: Autobuild
36+
uses: github/codeql-action/autobuild@v2
37+
38+
- name: Perform CodeQL Analysis
39+
uses: github/codeql-action/analyze@v2
40+
41+
dependency-review:
42+
name: Dependency Review
43+
runs-on: ubuntu-latest
44+
if: github.event_name == 'pull_request'
45+
46+
steps:
47+
- name: Checkout repository
48+
uses: actions/checkout@v4
49+
50+
- name: Dependency Review
51+
uses: actions/dependency-review-action@v3
52+
53+
secret-scan:
54+
name: Secret Scanning
55+
runs-on: ubuntu-latest
56+
57+
steps:
58+
- name: Checkout repository
59+
uses: actions/checkout@v4
60+
61+
- name: Run Trivy vulnerability scanner in repo mode
62+
uses: aquasecurity/trivy-action@master
63+
with:
64+
scan-type: 'fs'
65+
scan-ref: '.'
66+
format: 'sarif'
67+
output: 'trivy-results.sarif'
68+
69+
- name: Upload Trivy scan results to GitHub Security tab
70+
uses: github/codeql-action/upload-sarif@v2
71+
if: always()
72+
with:
73+
sarif_file: 'trivy-results.sarif'
74+
75+
python-security:
76+
name: Python Security Scan
77+
runs-on: ubuntu-latest
78+
79+
steps:
80+
- name: Checkout repository
81+
uses: actions/checkout@v4
82+
83+
- name: Set up Python
84+
uses: actions/setup-python@v4
85+
with:
86+
python-version: '3.12'
87+
88+
- name: Install dependencies
89+
run: |
90+
python -m pip install --upgrade pip
91+
pip install bandit[toml] safety
92+
93+
- name: Run Bandit security linter
94+
run: |
95+
bandit -r . -f json -o bandit-results.json || true
96+
97+
- name: Run Safety security scanner
98+
run: |
99+
safety check --json --output safety-results.json || true
100+
101+
- name: Upload security scan results
102+
uses: actions/upload-artifact@v3
103+
if: always()
104+
with:
105+
name: security-scan-results
106+
path: |
107+
bandit-results.json
108+
safety-results.json

0 commit comments

Comments
 (0)