Skip to content

Commit 1b8931e

Browse files
committed
init: fastapi-postgres-aca
0 parents  commit 1b8931e

18 files changed

Lines changed: 1088 additions & 0 deletions

.github/workflows/azure-dev.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Run when commits are pushed to main
2+
on:
3+
workflow_dispatch:
4+
push:
5+
# Run when commits are pushed to mainline branch (main or master)
6+
# Set this to the mainline branch you are using
7+
branches:
8+
- main
9+
10+
# Set up permissions for deploying with secretless Azure federated credentials
11+
# https://learn.microsoft.com/en-us/azure/developer/github/connect-from-azure?tabs=azure-portal%2Clinux#set-up-azure-login-with-openid-connect-authentication
12+
permissions:
13+
id-token: write
14+
contents: read
15+
16+
17+
jobs:
18+
build:
19+
runs-on: ubuntu-latest
20+
env:
21+
AZURE_CLIENT_ID: ${{ vars.AZURE_CLIENT_ID }}
22+
AZURE_TENANT_ID: ${{ vars.AZURE_TENANT_ID }}
23+
AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }}
24+
AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }}
25+
AZURE_LOCATION: ${{ vars.AZURE_LOCATION }}
26+
SERVICE_FASTAPI_POSTGRES_ACA_RESOURCE_EXISTS: ${{ vars.SERVICE_FASTAPI_POSTGRES_ACA_RESOURCE_EXISTS }}
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v4
30+
- name: Install azd
31+
uses: Azure/setup-azd@v2
32+
- name: Log in with Azure (Federated Credentials)
33+
run: |
34+
azd auth login `
35+
--client-id "$Env:AZURE_CLIENT_ID" `
36+
--federated-credential-provider "github" `
37+
--tenant-id "$Env:AZURE_TENANT_ID"
38+
shell: pwsh
39+
40+
41+
- name: Provision Infrastructure
42+
run: azd provision --no-prompt
43+
env:
44+
AZURE_KEY_VAULT_NAME: ${{ secrets.AZURE_KEY_VAULT_NAME }}
45+
46+
- name: Deploy Application
47+
run: azd deploy --no-prompt
48+
env:
49+
AZURE_KEY_VAULT_NAME: ${{ secrets.AZURE_KEY_VAULT_NAME }}
50+

.gitignore

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Virtual environment
2+
.venv/
3+
venv/
4+
env/
5+
6+
# Python cache files
7+
__pycache__/
8+
*.pyc
9+
*.pyo
10+
11+
# Editor/IDE specific files
12+
.vscode/
13+
.idea/
14+
*.swp
15+
*.bak
16+
17+
# Environment variables
18+
.env
19+
.env.*
20+
*.log
21+
22+
# Database files
23+
*.sqlite3
24+
*.db
25+
26+
# FastAPI specific
27+
# If you are using a specific build directory for your frontend assets, add it here
28+
# For example:
29+
# frontend/dist/
30+
31+
# Other common files to ignore
32+
temp/
33+
tmp/
34+
.azure

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 anth.dev
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

azure.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/Azure/azure-dev/main/schemas/v1.0/azure.yaml.json
2+
3+
name: fastapi-postgres-aca
4+
metadata:
5+
template: azd-init@1.20.2
6+
services:
7+
fastapi-postgres-aca:
8+
project: .
9+
host: containerapp
10+
language: python
11+
docker:
12+
path: Dockerfile
13+
resources:
14+
fastapi-postgres-aca:
15+
type: host.containerapp
16+
uses:
17+
- pycon-members
18+
port: 8000
19+
pycon-members:
20+
type: db.postgres

infra/abbreviations.json

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
{
2+
"aiFoundryAccounts": "aif",
3+
"analysisServicesServers": "as",
4+
"apiManagementService": "apim-",
5+
"appConfigurationStores": "appcs-",
6+
"appManagedEnvironments": "cae-",
7+
"appContainerApps": "ca-",
8+
"authorizationPolicyDefinitions": "policy-",
9+
"automationAutomationAccounts": "aa-",
10+
"blueprintBlueprints": "bp-",
11+
"blueprintBlueprintsArtifacts": "bpa-",
12+
"cacheRedis": "redis-",
13+
"cdnProfiles": "cdnp-",
14+
"cdnProfilesEndpoints": "cdne-",
15+
"cognitiveServicesAccounts": "cog-",
16+
"cognitiveServicesFormRecognizer": "cog-fr-",
17+
"cognitiveServicesTextAnalytics": "cog-ta-",
18+
"computeAvailabilitySets": "avail-",
19+
"computeCloudServices": "cld-",
20+
"computeDiskEncryptionSets": "des",
21+
"computeDisks": "disk",
22+
"computeDisksOs": "osdisk",
23+
"computeGalleries": "gal",
24+
"computeSnapshots": "snap-",
25+
"computeVirtualMachines": "vm",
26+
"computeVirtualMachineScaleSets": "vmss-",
27+
"containerInstanceContainerGroups": "ci",
28+
"containerRegistryRegistries": "cr",
29+
"containerServiceManagedClusters": "aks-",
30+
"databricksWorkspaces": "dbw-",
31+
"dataFactoryFactories": "adf-",
32+
"dataLakeAnalyticsAccounts": "dla",
33+
"dataLakeStoreAccounts": "dls",
34+
"dataMigrationServices": "dms-",
35+
"dBforMySQLServers": "mysql-",
36+
"dBforPostgreSQLServers": "psql-",
37+
"devicesIotHubs": "iot-",
38+
"devicesProvisioningServices": "provs-",
39+
"devicesProvisioningServicesCertificates": "pcert-",
40+
"documentDBDatabaseAccounts": "cosmos-",
41+
"documentDBMongoDatabaseAccounts": "cosmon-",
42+
"eventGridDomains": "evgd-",
43+
"eventGridDomainsTopics": "evgt-",
44+
"eventGridEventSubscriptions": "evgs-",
45+
"eventHubNamespaces": "evhns-",
46+
"eventHubNamespacesEventHubs": "evh-",
47+
"hdInsightClustersHadoop": "hadoop-",
48+
"hdInsightClustersHbase": "hbase-",
49+
"hdInsightClustersKafka": "kafka-",
50+
"hdInsightClustersMl": "mls-",
51+
"hdInsightClustersSpark": "spark-",
52+
"hdInsightClustersStorm": "storm-",
53+
"hybridComputeMachines": "arcs-",
54+
"insightsActionGroups": "ag-",
55+
"insightsComponents": "appi-",
56+
"keyVaultVaults": "kv-",
57+
"kubernetesConnectedClusters": "arck",
58+
"kustoClusters": "dec",
59+
"kustoClustersDatabases": "dedb",
60+
"logicIntegrationAccounts": "ia-",
61+
"logicWorkflows": "logic-",
62+
"machineLearningServicesWorkspaces": "mlw-",
63+
"managedIdentityUserAssignedIdentities": "id-",
64+
"managementManagementGroups": "mg-",
65+
"migrateAssessmentProjects": "migr-",
66+
"networkApplicationGateways": "agw-",
67+
"networkApplicationSecurityGroups": "asg-",
68+
"networkAzureFirewalls": "afw-",
69+
"networkBastionHosts": "bas-",
70+
"networkConnections": "con-",
71+
"networkDnsZones": "dnsz-",
72+
"networkExpressRouteCircuits": "erc-",
73+
"networkFirewallPolicies": "afwp-",
74+
"networkFirewallPoliciesWebApplication": "waf",
75+
"networkFirewallPoliciesRuleGroups": "wafrg",
76+
"networkFrontDoors": "fd-",
77+
"networkFrontdoorWebApplicationFirewallPolicies": "fdfp-",
78+
"networkLoadBalancersExternal": "lbe-",
79+
"networkLoadBalancersInternal": "lbi-",
80+
"networkLoadBalancersInboundNatRules": "rule-",
81+
"networkLocalNetworkGateways": "lgw-",
82+
"networkNatGateways": "ng-",
83+
"networkNetworkInterfaces": "nic-",
84+
"networkNetworkSecurityGroups": "nsg-",
85+
"networkNetworkSecurityGroupsSecurityRules": "nsgsr-",
86+
"networkNetworkWatchers": "nw-",
87+
"networkPrivateDnsZones": "pdnsz-",
88+
"networkPrivateLinkServices": "pl-",
89+
"networkPublicIPAddresses": "pip-",
90+
"networkPublicIPPrefixes": "ippre-",
91+
"networkRouteFilters": "rf-",
92+
"networkRouteTables": "rt-",
93+
"networkRouteTablesRoutes": "udr-",
94+
"networkTrafficManagerProfiles": "traf-",
95+
"networkVirtualNetworkGateways": "vgw-",
96+
"networkVirtualNetworks": "vnet-",
97+
"networkVirtualNetworksSubnets": "snet-",
98+
"networkVirtualNetworksVirtualNetworkPeerings": "peer-",
99+
"networkVirtualWans": "vwan-",
100+
"networkVpnGateways": "vpng-",
101+
"networkVpnGatewaysVpnConnections": "vcn-",
102+
"networkVpnGatewaysVpnSites": "vst-",
103+
"notificationHubsNamespaces": "ntfns-",
104+
"notificationHubsNamespacesNotificationHubs": "ntf-",
105+
"operationalInsightsWorkspaces": "log-",
106+
"portalDashboards": "dash-",
107+
"powerBIDedicatedCapacities": "pbi-",
108+
"purviewAccounts": "pview-",
109+
"recoveryServicesVaults": "rsv-",
110+
"resourcesResourceGroups": "rg-",
111+
"searchSearchServices": "srch-",
112+
"serviceBusNamespaces": "sb-",
113+
"serviceBusNamespacesQueues": "sbq-",
114+
"serviceBusNamespacesTopics": "sbt-",
115+
"serviceEndPointPolicies": "se-",
116+
"serviceFabricClusters": "sf-",
117+
"signalRServiceSignalR": "sigr",
118+
"sqlManagedInstances": "sqlmi-",
119+
"sqlServers": "sql-",
120+
"sqlServersDataWarehouse": "sqldw-",
121+
"sqlServersDatabases": "sqldb-",
122+
"sqlServersDatabasesStretch": "sqlstrdb-",
123+
"storageStorageAccounts": "st",
124+
"storageStorageAccountsVm": "stvm",
125+
"storSimpleManagers": "ssimp",
126+
"streamAnalyticsCluster": "asa-",
127+
"synapseWorkspaces": "syn",
128+
"synapseWorkspacesAnalyticsWorkspaces": "synw",
129+
"synapseWorkspacesSqlPoolsDedicated": "syndp",
130+
"synapseWorkspacesSqlPoolsSpark": "synsp",
131+
"timeSeriesInsightsEnvironments": "tsi-",
132+
"webServerFarms": "plan-",
133+
"webSitesAppService": "app-",
134+
"webSitesAppServiceEnvironment": "ase-",
135+
"webSitesFunctions": "func-",
136+
"webStaticSites": "stapp-"
137+
}

infra/main.bicep

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
targetScope = 'subscription'
2+
3+
@minLength(1)
4+
@maxLength(64)
5+
@description('Name of the environment that can be used as part of naming resource convention')
6+
param environmentName string
7+
8+
@minLength(1)
9+
@description('Primary location for all resources')
10+
param location string
11+
12+
13+
@secure()
14+
param postgresDatabasePassword string
15+
param fastapiPostgresAcaExists bool
16+
17+
@description('Id of the user or app to assign application roles')
18+
param principalId string
19+
20+
@description('Principal type of user or app')
21+
param principalType string
22+
23+
// Tags that should be applied to all resources.
24+
//
25+
// Note that 'azd-service-name' tags should be applied separately to service host resources.
26+
// Example usage:
27+
// tags: union(tags, { 'azd-service-name': <service name in azure.yaml> })
28+
var tags = {
29+
'azd-env-name': environmentName
30+
}
31+
32+
// Organize resources in a resource group
33+
resource rg 'Microsoft.Resources/resourceGroups@2021-04-01' = {
34+
name: 'rg-${environmentName}'
35+
location: location
36+
tags: tags
37+
}
38+
39+
module resources 'resources.bicep' = {
40+
scope: rg
41+
name: 'resources'
42+
params: {
43+
location: location
44+
tags: tags
45+
principalId: principalId
46+
principalType: principalType
47+
postgresDatabasePassword: postgresDatabasePassword
48+
fastapiPostgresAcaExists: fastapiPostgresAcaExists
49+
}
50+
}
51+
output AZURE_CONTAINER_REGISTRY_ENDPOINT string = resources.outputs.AZURE_CONTAINER_REGISTRY_ENDPOINT
52+
output AZURE_RESOURCE_FASTAPI_POSTGRES_ACA_ID string = resources.outputs.AZURE_RESOURCE_FASTAPI_POSTGRES_ACA_ID
53+
output AZURE_KEY_VAULT_ENDPOINT string = resources.outputs.AZURE_KEY_VAULT_ENDPOINT
54+
output AZURE_KEY_VAULT_NAME string = resources.outputs.AZURE_KEY_VAULT_NAME
55+
output AZURE_RESOURCE_VAULT_ID string = resources.outputs.AZURE_RESOURCE_VAULT_ID
56+
output AZURE_RESOURCE_PYCON_MEMBERS_ID string = resources.outputs.AZURE_RESOURCE_PYCON_MEMBERS_ID

infra/main.parameters.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
3+
"contentVersion": "1.0.0.0",
4+
"parameters": {
5+
"environmentName": {
6+
"value": "${AZURE_ENV_NAME}"
7+
},
8+
"location": {
9+
"value": "${AZURE_LOCATION}"
10+
},
11+
"postgresDatabasePassword": {
12+
"value": "$(secretOrRandomPassword ${AZURE_KEY_VAULT_NAME} postgres-password)"
13+
},
14+
"fastapiPostgresAcaExists": {
15+
"value": "${SERVICE_FASTAPI_POSTGRES_ACA_RESOURCE_EXISTS=false}"
16+
},
17+
"principalId": {
18+
"value": "${AZURE_PRINCIPAL_ID}"
19+
},
20+
"principalType": {
21+
"value": "${AZURE_PRINCIPAL_TYPE}"
22+
}
23+
}
24+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
param exists bool
2+
param name string
3+
4+
resource existingApp 'Microsoft.App/containerApps@2023-05-02-preview' existing = if (exists) {
5+
name: name
6+
}
7+
8+
output containers array = exists ? existingApp!.properties.template.containers : []

0 commit comments

Comments
 (0)