Skip to content

Commit 60e935e

Browse files
authored
Merge pull request #31 from Azure-Samples/gk/azurite-bindings-fixes
Simplifies Devcontainer configuration
2 parents 7d09cd0 + f092b63 commit 60e935e

File tree

7 files changed

+38
-106
lines changed

7 files changed

+38
-106
lines changed

.devcontainer/Dockerfile

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,27 @@
11
# Snippy Functions – Dev Container image
2-
FROM mcr.microsoft.com/vscode/devcontainers/universal:latest
2+
FROM mcr.microsoft.com/devcontainers/python:3.11
33

4-
# ──────────────────────────────────────────────────────────────
5-
# 1 – First‑run welcome notice
6-
COPY first-run-notice.txt /tmp/staging/
7-
RUN sudo mv -f /tmp/staging/first-run-notice.txt \
8-
/usr/local/etc/vscode-dev-containers/ \
9-
&& sudo rm -rf /tmp/staging
4+
# Install system dependencies
5+
RUN apt-get update \
6+
&& apt-get install -y curl gnupg2 build-essential \
7+
&& rm -rf /var/lib/apt/lists/*
108

11-
# ──────────────────────────────────────────────────────────────
12-
# 2 – PowerShell 7.x
13-
RUN sudo apt-get update \
14-
&& sudo apt-get install -y wget apt-transport-https software-properties-common \
15-
&& wget -q https://packages.microsoft.com/config/ubuntu/$(. /etc/os-release && echo $VERSION_ID)/packages-microsoft-prod.deb \
16-
&& sudo dpkg -i packages-microsoft-prod.deb \
17-
&& sudo apt-get update \
18-
&& sudo apt-get install -y powershell \
19-
&& sudo apt-get clean \
20-
&& rm -rf /var/lib/apt/lists/*
9+
# Install Azure Functions Core Tools v4
10+
RUN curl -sL https://deb.nodesource.com/setup_18.x | bash - \
11+
&& apt-get install -y nodejs \
12+
&& npm install -g azure-functions-core-tools@4 --unsafe-perm \
13+
&& apt-get clean \
14+
&& rm -rf /var/lib/apt/lists/*
2115

22-
# ──────────────────────────────────────────────────────────────
23-
# 3 – Azure Functions Core Tools v4
24-
# Using npm ensures the latest build and works on any distro.
25-
RUN npm install -g azure-functions-core-tools@4 --unsafe-perm
26-
27-
# ──────────────────────────────────────────────────────────────
28-
# 4 – Azure Developer CLI
16+
# Install Azure Developer CLI (azd)
2917
RUN curl -fsSL https://aka.ms/install-azd.sh | bash
3018

31-
# ──────────────────────────────────────────────────────────────
32-
# 5 – Mechanical‑Markdown (quick‑start doc validation)
33-
RUN pip install --no-cache-dir mechanical-markdown
19+
RUN azd version
20+
21+
# Install uv (Python package manager)
22+
RUN pip install --no-cache-dir uv
23+
24+
# Optionally copy welcome notice
25+
COPY first-run-notice.txt /usr/local/etc/first-run-notice.txt
26+
27+
WORKDIR /workspaces/app

.devcontainer/devcontainer.json

Lines changed: 2 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,6 @@
11
{
2-
"name": "Snippy Functions Codespace",
2+
"name": "Azure Functions DevContainer",
33
"dockerFile": "Dockerfile",
4-
5-
// ── Features ────────────────────────────────────────────────────────────
6-
"features": {
7-
"ghcr.io/devcontainers/features/azure-cli:1": {},
8-
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {},
9-
"ghcr.io/devcontainers/features/node:1": { "version": "lts" }
10-
},
11-
12-
// ── Port forwards ───────────────────────────────────────────────────────
13-
"forwardPorts": [7071, 10000, 10001, 10002],
14-
15-
// ── Lifecycle commands ──────────────────────────────────────────────────
164
"postCreateCommand": "./.devcontainer/setup.sh",
17-
"postStartCommand": "bash .devcontainer/start.sh",
18-
19-
// ── VS Code customisation ───────────────────────────────────────────────
20-
"customizations": {
21-
"vscode": {
22-
"extensions": [
23-
"ms-azuretools.vscode-azurefunctions",
24-
"ms-azuretools.vscode-docker",
25-
"GitHub.copilot"
26-
]
27-
}
28-
},
29-
30-
// ── Misc ────────────────────────────────────────────────────────────────
31-
"mounts": [
32-
"source=codespaces-linux-var-lib-docker,target=/var/lib/docker,type=volume"
33-
],
34-
"overrideCommand": false,
35-
"remoteUser": "codespace",
36-
"runArgs": [
37-
"--cap-add=SYS_PTRACE",
38-
"--security-opt", "seccomp=unconfined",
39-
"--init",
40-
"--privileged"
41-
]
5+
"postStartCommand": "bash .devcontainer/start.sh"
426
}

.devcontainer/setup.sh

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,8 @@ set -e
33

44
echo "▶ Installing Python deps with uv"
55
pip install -q 'uv>=0.1.29'
6-
cd /workspaces/$(basename "$GITHUB_REPOSITORY")/src
6+
REPO_ROOT="/workspaces/snippy"
7+
SRC_DIR="$REPO_ROOT/src"
8+
cd $SRC_DIR
79
uv venv .venv
810
uv pip install -r requirements.txt
9-
10-
echo "▶ Creating local.settings.json from Codespaces secrets"
11-
jq -n '{
12-
IsEncrypted:false,
13-
Values:{
14-
AzureWebJobsStorage : env.AzureWebJobsStorage,
15-
AzureWebJobsFeatureFlags : "EnableWorkerIndexing",
16-
FUNCTIONS_WORKER_RUNTIME : "python",
17-
COSMOS_CONN : env.COSMOS_CONN,
18-
COSMOS_DATABASE_NAME : "dev-snippet-db",
19-
COSMOS_CONTAINER_NAME : "code-snippets",
20-
BLOB_CONTAINER_NAME : "snippet-backups",
21-
EMBEDDING_MODEL_DEPLOYMENT_NAME : "text-embedding-3-small",
22-
AGENTS_MODEL_DEPLOYMENT_NAME : "gpt-4o",
23-
PROJECT_CONNECTION_STRING : env.PROJECT_CONNECTION_STRING,
24-
PYTHON_ENABLE_WORKER_EXTENSIONS : "True",
25-
AZURE_OPENAI_ENDPOINT : env.AZURE_OPENAI_ENDPOINT,
26-
AZURE_OPENAI_KEY : env.AZURE_OPENAI_KEY,
27-
COSMOS_VECTOR_TOP_K : "30"
28-
}
29-
}' > local.settings.json

.devcontainer/start.sh

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,3 @@
11
#!/usr/bin/env bash
2-
set -euo pipefail
3-
4-
# ── Paths ────────────────────────────────────────────────────────────────
5-
REPO_ROOT="/workspaces/$(basename "$GITHUB_REPOSITORY")"
6-
SRC_DIR="$REPO_ROOT/src"
7-
8-
cd "$SRC_DIR"
9-
10-
# ── Python virtual environment ────────────────────────────────────────────
11-
if [[ -f .venv/bin/activate ]]; then
12-
source .venv/bin/activate
13-
fi
14-
15-
# ── Azure Functions runtime ───────────────────────────────────────────────
16-
echo "▶ func start (port 7071)"
17-
func start --python --no-build --port 7071
2+
# This script intentionally does nothing for now.
3+
exit 0

infra/main.bicep

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ var tags = { 'azd-env-name': environmentName }
3939
var functionAppName = !empty(apiServiceName) ? apiServiceName : '${abbrs.webSitesFunctions}api-${resourceToken}'
4040
var deploymentStorageContainerName = 'app-package-${take(functionAppName, 32)}-${take(toLower(uniqueString(functionAppName, resourceToken)), 7)}'
4141

42+
var storageAccountActualName = !empty(storageAccountName) ? storageAccountName : '${abbrs.storageStorageAccounts}${resourceToken}'
43+
4244
// Organize resources in a resource group
4345
resource rg 'Microsoft.Resources/resourceGroups@2021-04-01' = {
4446
name: !empty(resourceGroupName) ? resourceGroupName : '${abbrs.resourcesResourceGroups}${environmentName}'
@@ -62,7 +64,7 @@ module storage 'br/public:avm/res/storage/storage-account:0.8.3' = {
6264
name: 'storage'
6365
scope: rg
6466
params: {
65-
name: !empty(storageAccountName) ? storageAccountName : '${abbrs.storageStorageAccounts}${resourceToken}'
67+
name: storageAccountActualName
6668
location: location
6769
tags: tags
6870
skuName: 'Standard_LRS'
@@ -263,3 +265,6 @@ output AZURE_OPENAI_KEY string = openai.outputs.primaryKey
263265
@description('Name of the deployed Azure Function App.')
264266
output AZURE_FUNCTION_NAME string = api.outputs.SERVICE_API_NAME // Function App Name
265267

268+
@description('Connection string for the Azure Storage Account. Output name matches the AzureWebJobsStorage key in local settings.')
269+
@secure()
270+
output AZUREWEBJOBSSTORAGE string = 'DefaultEndpointsProtocol=https;AccountName=${storageAccountActualName};AccountKey=${listKeys(resourceId('Microsoft.Storage/storageAccounts', storageAccountActualName), '2022-09-01').keys[0].value};EndpointSuffix=core.windows.net'

scripts/generate-settings.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ $COSMOS_ENDPOINT = ($azdValues | Select-String 'COSMOS_ENDPOINT="(.*?)"').Matche
77
$PROJECT_CONNECTION_STRING = ($azdValues | Select-String 'PROJECT_CONNECTION_STRING="(.*?)"').Matches.Groups[1].Value
88
$AZURE_OPENAI_ENDPOINT = ($azdValues | Select-String 'AZURE_OPENAI_ENDPOINT="(.*?)"').Matches.Groups[1].Value
99
$AZURE_OPENAI_KEY = ($azdValues | Select-String 'AZURE_OPENAI_KEY="(.*?)"').Matches.Groups[1].Value
10+
$AZUREWEBJOBSSTORAGE = ($azdValues | Select-String 'AZUREWEBJOBSSTORAGE="(.*?)"').Matches.Groups[1].Value
1011

1112
# Create the JSON content
1213
$jsonContent = @"
1314
{
1415
"IsEncrypted": false,
1516
"Values": {
16-
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
17+
"AzureWebJobsStorage": "$AZUREWEBJOBSSTORAGE",
1718
"FUNCTIONS_WORKER_RUNTIME": "python",
1819
"PYTHON_ENABLE_WORKER_EXTENSIONS": "True",
1920
"COSMOS_DATABASE_NAME": "dev-snippet-db",

scripts/generate-settings.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ COSMOS_ENDPOINT=$(azd env get-values | grep COSMOS_ENDPOINT | cut -d'"' -f2)
66
PROJECT_CONNECTION_STRING=$(azd env get-values | grep PROJECT_CONNECTION_STRING | cut -d'"' -f2)
77
AZURE_OPENAI_ENDPOINT=$(azd env get-values | grep AZURE_OPENAI_ENDPOINT | cut -d'"' -f2)
88
AZURE_OPENAI_KEY=$(azd env get-values | grep AZURE_OPENAI_KEY | cut -d'"' -f2)
9+
AZUREWEBJOBSSTORAGE=$(azd env get-values | grep AZUREWEBJOBSSTORAGE | cut -d'"' -f2)
910

1011
# Create or update local.settings.json
1112
echo "Generating local.settings.json in src directory..."
1213
cat > src/local.settings.json << EOF
1314
{
1415
"IsEncrypted": false,
1516
"Values": {
16-
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
17+
"AzureWebJobsStorage": "$AZUREWEBJOBSSTORAGE",
1718
"FUNCTIONS_WORKER_RUNTIME": "python",
1819
"PYTHON_ENABLE_WORKER_EXTENSIONS": "True",
1920
"COSMOS_DATABASE_NAME": "dev-snippet-db",

0 commit comments

Comments
 (0)