Skip to content

Commit 03c5342

Browse files
author
Bob Tabor
committed
Initial commit
1 parent 3799871 commit 03c5342

87 files changed

Lines changed: 4873 additions & 446 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.cruft.json‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"template": "https://github.com/Azure-Samples/Azure-Python-Standardization-Template-Generator",
3+
"commit": "619a6b29afba8ca26c528526bc313294d5c414a4",
4+
"checkout": null,
5+
"context": {
6+
"cookiecutter": {
7+
"project_name": "azure",
8+
"python_version": "3.12",
9+
"project_backend": "fastapi",
10+
"db_resource": "postgres-flexible",
11+
"project_host": "appservice",
12+
"web_port": "8000",
13+
"__repo_name": "azure-fastapi-postgres-flexible-appservice",
14+
"__src_folder_name": "azure-fastapi-postgres-flexible-appservice",
15+
"__project_short_description": "Create a relecloud demo application with fastapi and postgres-flexible",
16+
"_copy_without_render": [
17+
".github/workflows/azure-dev.yml",
18+
".github/workflows/cruft.yml",
19+
".github/workflows/devcontainer-ci.yml",
20+
".github/workflows/format.yml"
21+
],
22+
"_extensions": [
23+
"extensions.GetUrlForBackend"
24+
],
25+
"_jinja2_env_vars": {
26+
"lstrip_blocks": true,
27+
"trim_blocks": true
28+
},
29+
"_template": "https://github.com/Azure-Samples/Azure-Python-Standardization-Template-Generator"
30+
}
31+
},
32+
"directory": null
33+
}

‎.devcontainer/Dockerfile_dev‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM mcr.microsoft.com/devcontainers/python:3.12-bullseye
2+
3+
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
4+
&& apt-get -y install --no-install-recommends postgresql-client \
5+
&& apt-get clean -y && rm -rf /var/lib/apt/lists/*
6+
7+
8+
COPY requirements-dev.txt requirements-dev.txt
9+
COPY src/requirements.txt src/requirements.txt
10+
RUN python -m pip install --upgrade pip
11+
RUN python -m pip install -r requirements-dev.txt

‎.devcontainer/devcontainer.json‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
2+
// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-docker-compose
3+
{
4+
"name": "azure-fastapi-postgres-flexible-appservice",
5+
6+
// Update the 'dockerComposeFile' list if you have more compose files or use different names.
7+
// The .devcontainer/docker-compose.yml file contains any overrides you need/want to make.
8+
"dockerComposeFile": "docker-compose_dev.yml",
9+
// The 'service' property is the name of the service for the container that VS Code should
10+
// use. Update this value and .devcontainer/docker-compose.yml to the real service name.
11+
"service": "app",
12+
"shutdownAction": "stopCompose",
13+
"workspaceFolder": "/workspace",
14+
"forwardPorts": [8000, 5432],
15+
"portsAttributes": {
16+
"8000": {"label": "frontend web port", "onAutoForward": "notify"},
17+
"5432": {"label": "PostgreSQL Port", "onAutoForward": "silent"}
18+
},
19+
"customizations": {
20+
"vscode": {
21+
"extensions": [
22+
"ms-azuretools.vscode-bicep",
23+
"charliermarsh.ruff",
24+
"ms-python.python",
25+
"bierner.github-markdown-preview"
26+
],
27+
"settings": {
28+
"python.defaultInterpreterPath": "/usr/local/bin/python",
29+
"python.testing.pytestEnabled": true,
30+
"python.testing.unittestEnabled": false,
31+
"files.exclude": {
32+
".coverage": true,
33+
".pytest_cache": true,
34+
"__pycache__": true,
35+
".ruff_cache": true
36+
},
37+
"[python]": {
38+
"editor.formatOnSave": true,
39+
"editor.defaultFormatter": "charliermarsh.ruff",
40+
"editor.codeActionsOnSave": {
41+
"source.organizeImports": true,
42+
"source.fixAll": true
43+
}
44+
}
45+
}
46+
}
47+
},
48+
"features": {
49+
"ghcr.io/azure/azure-dev/azd:latest": {}
50+
},
51+
"postCreateCommand": "playwright install chromium --with-deps && pip install -e src && python3 src/fastapi_app/seed_data.py"
52+
}
53+
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
version: '3'
2+
services:
3+
db:
4+
image: postgres:14
5+
6+
environment:
7+
POSTGRES_USER: postgres
8+
POSTGRES_DB: relecloud
9+
POSTGRES_PASSWORD: postgres
10+
11+
restart: unless-stopped
12+
13+
volumes:
14+
- postgres-data:/var/lib/postgresql/data
15+
16+
healthcheck:
17+
test: ["CMD-SHELL", "pg_isready -U postgres -d relecloud"]
18+
interval: 5s
19+
timeout: 5s
20+
retries: 5
21+
22+
app:
23+
build:
24+
context: ..
25+
dockerfile: ./.devcontainer/Dockerfile_dev
26+
depends_on:
27+
db:
28+
condition: service_healthy
29+
network_mode: service:db
30+
environment:
31+
POSTGRES_USERNAME: postgres
32+
POSTGRES_DATABASE: relecloud
33+
POSTGRES_HOST: db
34+
POSTGRES_PASSWORD: postgres
35+
36+
command: sleep infinity
37+
38+
volumes:
39+
- ..:/workspace:cached
40+
41+
volumes:
42+
postgres-data:

‎.gitattributes‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* text=auto eol=lf
2+
*.{cmd,[cC][mM][dD]} text eol=crlf
3+
*.{bat,[bB][aA][tT]} text eol=crlf

‎.github/workflows/audit-bicep.yml‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Validate AZD template
2+
on:
3+
push:
4+
branches:
5+
- main
6+
- cruft/update
7+
paths:
8+
- "infra/**"
9+
pull_request:
10+
branches:
11+
- main
12+
- cruft/update
13+
paths:
14+
- "infra/**"
15+
workflow_dispatch:
16+
17+
jobs:
18+
build:
19+
runs-on: ubuntu-latest
20+
permissions:
21+
security-events: write
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v4
25+
26+
- name: Run PSRule analysis
27+
uses: microsoft/ps-rule@v2.9.0
28+
with:
29+
modules: PSRule.Rules.Azure
30+
baseline: Azure.Pillar.Security
31+
inputPath: infra/*.test.bicep
32+
outputFormat: Sarif
33+
outputPath: reports/ps-rule-results.sarif
34+
summary: true
35+
continue-on-error: true
36+
37+
env:
38+
PSRULE_CONFIGURATION_AZURE_BICEP_FILE_EXPANSION: 'true'
39+
PSRULE_CONFIGURATION_AZURE_BICEP_FILE_EXPANSION_TIMEOUT: '30'
40+
41+
- name: Upload alerts to Security tab
42+
uses: github/codeql-action/upload-sarif@v3
43+
if: github.repository_owner == 'Azure-Samples'
44+
with:
45+
sarif_file: reports/ps-rule-results.sarif

‎.github/workflows/azure-dev.yml‎

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: Deploy to Azure with azd
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
- cruft/update
9+
10+
# GitHub Actions workflow to deploy to Azure using azd
11+
# To configure required secrets for connecting to Azure, simply run `azd pipeline config`
12+
13+
# Set up permissions for deploying with secretless Azure federated credentials
14+
# https://learn.microsoft.com/en-us/azure/developer/github/connect-from-azure?tabs=azure-portal%2Clinux#set-up-azure-login-with-openid-connect-authentication
15+
permissions:
16+
id-token: write
17+
contents: read
18+
19+
jobs:
20+
build:
21+
runs-on: ubuntu-latest
22+
outputs:
23+
uri: ${{ steps.output.outputs.uri }}
24+
env:
25+
AZURE_CLIENT_ID: ${{ vars.AZURE_CLIENT_ID }}
26+
AZURE_TENANT_ID: ${{ vars.AZURE_TENANT_ID }}
27+
AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }}
28+
AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}
29+
steps:
30+
- name: Checkout
31+
uses: actions/checkout@v4
32+
33+
- name: Install azd
34+
uses: Azure/setup-azd@v1.0.0
35+
36+
- name: Log in with Azure (Federated Credentials)
37+
if: ${{ env.AZURE_CLIENT_ID != '' }}
38+
run: |
39+
azd auth login `
40+
--client-id "$Env:AZURE_CLIENT_ID" `
41+
--federated-credential-provider "github" `
42+
--tenant-id "$Env:AZURE_TENANT_ID"
43+
shell: pwsh
44+
45+
- name: Log in with Azure (Client Credentials)
46+
if: ${{ env.AZURE_CREDENTIALS != '' }}
47+
run: |
48+
$info = $Env:AZURE_CREDENTIALS | ConvertFrom-Json -AsHashtable;
49+
Write-Host "::add-mask::$($info.clientSecret)"
50+
51+
azd auth login `
52+
--client-id "$($info.clientId)" `
53+
--client-secret "$($info.clientSecret)" `
54+
--tenant-id "$($info.tenantId)"
55+
shell: pwsh
56+
env:
57+
AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}
58+
59+
- name: Provision Infrastructure
60+
run: azd provision --no-prompt
61+
env:
62+
AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }}
63+
AZURE_LOCATION: ${{ vars.AZURE_LOCATION }}
64+
AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }}
65+
66+
- name: Deploy Application
67+
run: azd deploy --no-prompt
68+
env:
69+
AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }}
70+
AZURE_LOCATION: ${{ vars.AZURE_LOCATION }}
71+
AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }}
72+
73+
- name: Output Deployment URI
74+
id: output
75+
run: |
76+
azd env get-values > .env
77+
source .env
78+
echo "uri=$BACKEND_URI" >> "$GITHUB_OUTPUT"
79+
80+
smoketests:
81+
runs-on: ubuntu-latest
82+
needs: build
83+
steps:
84+
85+
- name: Basic smoke test (curl)
86+
env:
87+
URI: ${{needs.build.outputs.uri}}
88+
run: |
89+
echo "Sleeping 1 minute due to https://github.com/Azure/azure-dev/issues/2669"
90+
sleep 60
91+
curl -sSf $URI
92+
- name: Checkout
93+
uses: actions/checkout@v3
94+
95+
- name: Setup python
96+
uses: actions/setup-python@v4
97+
with:
98+
python-version: 3.12
99+
100+
- name: End-to-end smoke tests (playwright)
101+
env:
102+
URI: ${{needs.build.outputs.uri}}
103+
run: |
104+
python3 -m pip install --upgrade pip
105+
python3 -m pip install -r requirements-dev.txt
106+
python3 -m playwright install chromium --with-deps
107+
python3 -m pytest --exitfirst src/tests/smoke/smoketests.py --live-server-url $URI

‎.github/workflows/cruft.yml‎

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Update repository with Cruft
2+
permissions:
3+
contents: write
4+
pull-requests: write
5+
on:
6+
workflow_dispatch:
7+
schedule:
8+
- cron: "0 2 * * 1" # Every Monday at 2am
9+
jobs:
10+
update:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: true
14+
matrix:
15+
include:
16+
- add-paths: .
17+
body: Use this to merge the changes to this repository.
18+
branch: cruft/update
19+
commit-message: "chore: accept new Cruft update"
20+
title: New updates detected with Cruft
21+
- add-paths: .cruft.json
22+
body: Use this to reject the changes in this repository.
23+
branch: cruft/reject${{ github.run_id }}
24+
commit-message: "chore: reject new Cruft update"
25+
title: Reject new updates detected with Cruft
26+
steps:
27+
- uses: actions/checkout@v3
28+
29+
- uses: actions/setup-python@v4
30+
with:
31+
python-version: "3.12"
32+
33+
- name: Install Cruft
34+
run: pip3 install -r requirements-dev.txt
35+
36+
- name: Check if update is available
37+
continue-on-error: false
38+
id: check
39+
run: |
40+
CHANGES=0
41+
if [ -f .cruft.json ]; then
42+
if ! cruft check; then
43+
CHANGES=1
44+
fi
45+
else
46+
echo "No .cruft.json file"
47+
fi
48+
49+
echo "has_changes=$CHANGES" >> "$GITHUB_OUTPUT"
50+
51+
- name: Run update if available
52+
if: steps.check.outputs.has_changes == '1'
53+
run: |
54+
git config --global user.email "you@example.com"
55+
git config --global user.name "GitHub"
56+
57+
cruft update --skip-apply-ask --refresh-private-variables
58+
git restore --staged .
59+
60+
- name: Create pull request
61+
if: steps.check.outputs.has_changes == '1'
62+
run: |
63+
echo "::set-output name=branch::${{ matrix.branch }}"
64+
echo "::set-output name=commit-message::${{ matrix.commit-message }}"
65+
git checkout -b "${{ matrix.branch }}"
66+
git add ${{ matrix.add-paths }}
67+
git commit -m "${{ matrix.commit-message }}"
68+
git push origin "${{ matrix.branch }}"

0 commit comments

Comments
 (0)