Skip to content

Commit 5399177

Browse files
committed
convert to service connector and kv secrets
1 parent 47cbc0b commit 5399177

File tree

10 files changed

+359
-196
lines changed

10 files changed

+359
-196
lines changed

.devcontainer/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM mcr.microsoft.com/vscode/devcontainers/python:0-3.10
1+
FROM mcr.microsoft.com/vscode/devcontainers/python:3.12
22

33
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
44
&& apt-get -y install --no-install-recommends postgresql-client \

.devcontainer/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ This `.devcontainer` directory contains the configuration for a [dev container](
55
The dev container configuration lets you open the repository in a [GitHub codespace](https://docs.github.com/codespaces/overview) or a dev container in Visual Studio Code. For your convenience, the dev container is configured with the following:
66

77
- Python
8+
- Running `pip install -r requirements.txt` from the project at container start.
89
- PostgreSQL
910
- [Azure Developer CLI](https://learn.microsoft.com/azure/developer/azure-developer-cli/overview) (so you can run `azd` commands directly).

.devcontainer/devcontainer.json

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "python-app-service-postgresql-redis-infra",
33
"dockerComposeFile": "docker-compose.yml",
44
"service": "app",
5-
"workspaceFolder": "/workspace",
5+
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
66
"features": {
77
"ghcr.io/azure/azure-dev/azd:latest": {}
88
},
@@ -29,7 +29,6 @@
2929
"password": "app_password"
3030
}
3131
],
32-
"python.pythonPath": "/usr/local/bin/python",
3332
"python.languageServer": "Pylance",
3433
"python.linting.enabled": true,
3534
"python.linting.mypyEnabled": true,
@@ -51,12 +50,10 @@
5150
}
5251
}
5352
},
54-
// Use 'forwardPorts' to make a list of ports inside the container available locally. 5000 is for Flask, 8000 is for Django, and 5432 is for PostgreSQL.
55-
"forwardPorts": [
56-
8000, 5000, 5432
57-
],
53+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
54+
// "forwardPorts": [],
5855
// Use 'postCreateCommand' to run commands after the container is created.
59-
// "postCreateCommand": "",
56+
"postCreateCommand": "pip install -r requirements.txt",
6057
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
6158
"remoteUser": "vscode"
6259
}
File renamed without changes.

.env.sample

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

azure.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ hooks:
1313
postprovision:
1414
posix:
1515
shell: sh
16-
run: echo $'\n\nApp Service app has the following settings:\n' && echo "$WEB_APP_SETTINGS" | jq -r '.[]' | sed 's/\(.*\)/\t- \1/' && echo -e $"\nSee the settings in the portal:\033[1;36m $WEB_APP_CONFIG"
16+
run: printf '\nApp Service app has the following connection settings:\n' && printf "$CONNECTION_SETTINGS" | jq -r '.[]' | sed 's/\(.*\)/\t- \1/' && printf "\nSee the settings in the portal:\033[1;36m $WEB_APP_CONFIG\n"
1717
interactive: true
1818
continueOnError: true
1919
windows:
2020
shell: pwsh
21-
run: Write-Host "`n`nApp Service app has the following settings:`n" $WEB_APP_SETTINGS | ConvertFrom-Json | ForEach-Object { Write-Host "\t- $_" }
21+
run: Write-Host "`n`nApp Service app has the following connection settings:`n" $CONNECTION_SETTINGS | ConvertFrom-Json | ForEach-Object { Write-Host "\t- $_" }
2222
interactive: true
2323
continueOnError: true
2424
postdeploy:
2525
posix:
2626
shell: sh
27-
run: echo -e $"\n\nOpen SSH session to App Service container at:\033[1;36m $WEB_APP_SSH\033[0m" && echo -e $"Stream App Service logs at:\033[1;36m $WEB_APP_LOG_STREAM"
27+
run: printf "Open SSH session to App Service container at:\033[1;36m $WEB_APP_SSH\033[0m\nStream App Service logs at:\033[1;36m $WEB_APP_LOG_STREAM\n"
2828
interactive: true
2929
continueOnError: true
3030
windows:

azureproject/production.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
import os
22

3-
# Configure Postgres database based on connection string of the libpq Keyword/Value form
4-
# https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING
5-
conn_str = os.environ['AZURE_POSTGRESQL_CONNECTIONSTRING']
6-
conn_str_params = {pair.split('=')[0]: pair.split('=')[1] for pair in conn_str.split(' ')}
7-
83
DATABASE_URI = 'postgresql+psycopg2://{dbuser}:{dbpass}@{dbhost}/{dbname}'.format(
9-
dbuser=conn_str_params['user'],
10-
dbpass=conn_str_params['password'],
11-
dbhost=conn_str_params['host'],
12-
dbname=conn_str_params['dbname']
4+
dbuser=os.getenv('AZURE_POSTGRESQL_USER'),
5+
dbpass=os.getenv('AZURE_POSTGRESQL_PASSWORD'),
6+
dbhost=os.getenv('AZURE_POSTGRESQL_HOST'),
7+
dbname=os.getenv('AZURE_POSTGRESQL_NAME')
138
)

infra/main.bicep

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ param databasePassword string
1717
@description('Django SECRET_KEY for securing signed data')
1818
param secretKey string
1919

20+
param principalId string = ''
21+
2022
var resourceToken = toLower(uniqueString(subscription().id, name, location))
2123
var tags = { 'azd-env-name': name }
2224

@@ -35,14 +37,15 @@ module resources 'resources.bicep' = {
3537
resourceToken: resourceToken
3638
tags: tags
3739
databasePassword: databasePassword
40+
principalId: principalId
3841
secretKey: secretKey
3942
}
4043
}
4144

4245
output AZURE_LOCATION string = location
4346
output APPLICATIONINSIGHTS_CONNECTION_STRING string = resources.outputs.APPLICATIONINSIGHTS_CONNECTION_STRING
4447
output WEB_URI string = resources.outputs.WEB_URI
45-
output WEB_APP_SETTINGS array = resources.outputs.WEB_APP_SETTINGS
48+
output CONNECTION_SETTINGS array = resources.outputs.CONNECTION_SETTINGS
4649
output WEB_APP_LOG_STREAM string = resources.outputs.WEB_APP_LOG_STREAM
4750
output WEB_APP_SSH string = resources.outputs.WEB_APP_SSH
48-
output WEB_APP_CONFIG string = resources.outputs.WEB_APP_CONFIG
51+
output WEB_APP_CONFIG string = resources.outputs.WEB_APP_CONFIG

infra/main.parameters.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
"databasePassword": {
1212
"value": "$(secretOrRandomPassword)"
1313
},
14+
"principalId": {
15+
"value": "${AZURE_PRINCIPAL_ID}"
16+
},
1417
"secretKey": {
1518
"value": "$(secretOrRandomPassword)"
1619
}

0 commit comments

Comments
 (0)