Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cruft update #8

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .cruft.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"template": "https://github.com/kjaymiller/cookiecutter-relecloud/",
"commit": "a3794bddf382c4c6fa4add5bf935ca14bca40a71",
"commit": "04ac8410200b9d270bf7f07d1ae0d96837f5b5d9",
"checkout": null,
"context": {
"cookiecutter": {
Expand Down
4 changes: 4 additions & 0 deletions .devcontainer/Dockerfile_dev
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@ RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends postgresql-client \
&& apt-get clean -y && rm -rf /var/lib/apt/lists/*


COPY requirements-dev.txt requirements-dev.txt
COPY src/requirements.txt src/requirements.txt
RUN python -m pip install --upgrade pip
RUN python -m pip install -r requirements-dev.txt
28 changes: 11 additions & 17 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,34 @@
"ms-azuretools.vscode-bicep",
"charliermarsh.ruff",
"ms-python.python",
"ms-python.black-formatter",
"ms-azuretools.vscode-docker",
"mtxr.sqltools",
"mtxr.sqltools-driver-pg",
"bierner.github-markdown-preview"
],
"settings": {
"sqltools.connections": [
{
"name": "Local database",
"driver": "PostgreSQL",
"server": "db",
"port": 5432,
"database": "relecloud",
"username": "postgres",
"password": "postgres"
}
],
"python.defaultInterpreterPath": "/usr/local/bin/python",
"python.testing.pytestEnabled": true,
"python.testing.unittestEnabled": false,
"files.exclude": {
".coverage": true,
".pytest_cache": true,
"__pycache__": true
},
"[python]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.codeActionsOnSave": {
"source.organizeImports": true,
"source.fixAll": true
}
}
}
}
},
"features": {
"ghcr.io/azure/azure-dev/azd:latest": {},
// Required for azd to package the app to ACA
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
"ghcr.io/azure/azure-dev/azd:latest": {}
},
"postCreateCommand": "pip install -r requirements-dev.in && pip install -e src && python3 src/fastapi_app/seed_data.py"
"postCreateCommand": "playwright install chromium --with-deps && pip install -e src && python3 src/fastapi_app/seed_data.py"
}

4 changes: 2 additions & 2 deletions .devcontainer/docker-compose_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ services:

app:
build:
context: .
dockerfile: Dockerfile_dev
context: ..
dockerfile: ./.devcontainer/Dockerfile_dev
depends_on:
db:
condition: service_healthy
Expand Down
54 changes: 46 additions & 8 deletions .github/workflows/azure-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,18 @@ on:

# GitHub Actions workflow to deploy to Azure using azd
# To configure required secrets for connecting to Azure, simply run `azd pipeline config`

# Set up permissions for deploying with secretless Azure federated credentials
# https://learn.microsoft.com/en-us/azure/developer/github/connect-from-azure?tabs=azure-portal%2Clinux#set-up-azure-login-with-openid-connect-authentication
permissions:
id-token: write
contents: read

jobs:
build:
runs-on: ubuntu-latest
outputs:
uri: ${{ steps.output.outputs.uri }}
env:
AZURE_CLIENT_ID: ${{ vars.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ vars.AZURE_TENANT_ID }}
Expand All @@ -27,10 +29,10 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install azd
uses: Azure/[email protected]

- name: Log in with Azure (Federated Credentials)
if: ${{ env.AZURE_CLIENT_ID != '' }}
run: |
Expand All @@ -39,31 +41,67 @@ jobs:
--federated-credential-provider "github" `
--tenant-id "$Env:AZURE_TENANT_ID"
shell: pwsh

- name: Log in with Azure (Client Credentials)
if: ${{ env.AZURE_CREDENTIALS != '' }}
run: |
$info = $Env:AZURE_CREDENTIALS | ConvertFrom-Json -AsHashtable;
Write-Host "::add-mask::$($info.clientSecret)"

azd auth login `
--client-id "$($info.clientId)" `
--client-secret "$($info.clientSecret)" `
--tenant-id "$($info.tenantId)"
shell: pwsh
env:
AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}

- name: Provision Infrastructure
run: azd provision --no-prompt
env:
AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }}
AZURE_LOCATION: ${{ vars.AZURE_LOCATION }}
AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }}

- name: Deploy Application
run: azd deploy --no-prompt
env:
AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }}
AZURE_LOCATION: ${{ vars.AZURE_LOCATION }}
AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }}

- name: Output Deployment URI
id: output
run: |
azd env get-values > .env
source .env
echo "uri=$BACKEND_URI" >> "$GITHUB_OUTPUT"

smoketests:
runs-on: ubuntu-latest
needs: build
steps:

- name: Basic smoke test (curl)
env:
URI: ${{needs.build.outputs.uri}}
run: |
echo "Sleeping 1 minute due to https://github.com/Azure/azure-dev/issues/2669"
sleep 60
curl -sSf $URI
- name: Checkout
uses: actions/checkout@v3

- name: Setup python
uses: actions/setup-python@v4
with:
python-version: 3.12

- name: End-to-end smoke tests (playwright)
env:
URI: ${{needs.build.outputs.uri}}
run: |
python3 -m pip install --upgrade pip
python3 -m pip install -r requirements-dev.txt
python3 -m playwright install --with-deps
python3 -m pytest --exitfirst src/tests/smoke/smoketests.py --live-server-url $URI
2 changes: 1 addition & 1 deletion .github/workflows/cruft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
python-version: "3.10"

- name: Install Cruft
run: pip3 install -r requirements-dev.in
run: pip3 install -r requirements-dev.txt

- name: Check if update is available
continue-on-error: false
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-dev.in
pip install -r requirements-dev.txt
- name: Lint with ruff
run: ruff .
- name: Check formatting with black
run: black . --check --verbose
run: |
ruff check .
ruff format .
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fail-fast: false
matrix:
os: ["ubuntu-20.04"]
python_version: ["3.8", "3.9", "3.10", "3.11"]
python_version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
services:
db:
image: postgres:14
Expand All @@ -36,13 +36,13 @@ jobs:
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip
python3 -m pip install -r requirements-dev.in
python3 -m pip install -r requirements-dev.txt
playwright install --with-deps
python3 -m pip install -e src
- name: Seed data and run Pytest tests
run: |
python3 src/fastapi_app/seed_data.py
python3 -m pytest
python3 -m pytest
env:
POSTGRES_HOST: localhost
POSTGRES_USERNAME: postgres
Expand Down
3 changes: 3 additions & 0 deletions .markdownlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"MD013": false
}
13 changes: 0 additions & 13 deletions CHANGELOG.md

This file was deleted.

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ python3 -m uvicorn fastapi_app:app --reload --port=8000
2. Install the development requirements:

```sh
python3 -m pip install -r requirements-dev.in
playwright install --with-deps
python3 -m pip install -r requirements-dev.txt
python3 -m playwright install --with-deps
```

3. Run the tests:
Expand Down
33 changes: 17 additions & 16 deletions infra/core/host/appservice.bicep
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
metadata description = 'Creates an Azure App Service in an existing Azure App Service plan.'
param name string
param location string = resourceGroup().location
param tags object = {}
Expand All @@ -23,6 +24,7 @@ param kind string = 'app,linux'
param allowedOrigins array = []
param alwaysOn bool = true
param appCommandLine string = ''
@secure()
param appSettings object = {}
param clientAffinityEnabled bool = false
param enableOryxBuild bool = contains(kind, 'linux')
Expand Down Expand Up @@ -63,6 +65,18 @@ resource appService 'Microsoft.Web/sites@2022-03-01' = {

identity: { type: managedIdentity ? 'SystemAssigned' : 'None' }

resource configAppSettings 'config' = {
name: 'appsettings'
properties: union(appSettings,
{
SCM_DO_BUILD_DURING_DEPLOYMENT: string(scmDoBuildDuringDeployment)
ENABLE_ORYX_BUILD: string(enableOryxBuild)
},
runtimeName == 'python' ? { PYTHON_ENABLE_GUNICORN_MULTIWORKERS: 'true'} : {},
!empty(applicationInsightsName) ? { APPLICATIONINSIGHTS_CONNECTION_STRING: applicationInsights.properties.ConnectionString } : {},
!empty(keyVaultName) ? { AZURE_KEY_VAULT_ENDPOINT: keyVault.properties.vaultUri } : {})
}

resource configLogs 'config' = {
name: 'logs'
properties: {
Expand All @@ -71,39 +85,26 @@ resource appService 'Microsoft.Web/sites@2022-03-01' = {
failedRequestsTracing: { enabled: true }
httpLogs: { fileSystem: { enabled: true, retentionInDays: 1, retentionInMb: 35 } }
}
dependsOn: [
configAppSettings
]
}

resource basicPublishingCredentialsPoliciesFtp 'basicPublishingCredentialsPolicies' = {
name: 'ftp'
location: location
properties: {
allow: false
}
}

resource basicPublishingCredentialsPoliciesScm 'basicPublishingCredentialsPolicies' = {
name: 'scm'
location: location
properties: {
allow: false
}
}
}

module config 'appservice-appsettings.bicep' = if (!empty(appSettings)) {
name: '${name}-appSettings'
params: {
name: appService.name
appSettings: union(appSettings,
{
SCM_DO_BUILD_DURING_DEPLOYMENT: string(scmDoBuildDuringDeployment)
ENABLE_ORYX_BUILD: string(enableOryxBuild)
},
!empty(applicationInsightsName) ? { APPLICATIONINSIGHTS_CONNECTION_STRING: applicationInsights.properties.ConnectionString } : {},
!empty(keyVaultName) ? { AZURE_KEY_VAULT_ENDPOINT: keyVault.properties.vaultUri } : {})
}
}

resource keyVault 'Microsoft.KeyVault/vaults@2022-07-01' existing = if (!(empty(keyVaultName))) {
name: keyVaultName
}
Expand Down
4 changes: 3 additions & 1 deletion infra/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,6 @@ output SERVICE_WEB_URI string = web.outputs.SERVICE_WEB_URI
output SERVICE_WEB_IMAGE_NAME string = web.outputs.SERVICE_WEB_IMAGE_NAME
output AZURE_KEY_VAULT_ENDPOINT string = keyVault.outputs.endpoint
output AZURE_KEY_VAULT_NAME string = keyVault.outputs.name
output APPLICATIONINSIGHTS_NAME string = monitoring.outputs.applicationInsightsName
output APPLICATIONINSIGHTS_NAME string = monitoring.outputs.applicationInsightsName

output BACKEND_URI string = web.outputs.uri
6 changes: 6 additions & 0 deletions infra/web.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ module app 'core/host/container-app-upsert.bicep' = {
name: 'POSTGRES_PASSWORD'
secretRef: 'dbserver-password'
}
{
name: 'POSTGRES_SSL'
value: 'require'
}
{
name: 'RUNNING_IN_PRODUCTION'
value: 'true'
Expand Down Expand Up @@ -88,3 +92,5 @@ output SERVICE_WEB_IDENTITY_PRINCIPAL_ID string = webIdentity.properties.princip
output SERVICE_WEB_NAME string = app.outputs.name
output SERVICE_WEB_URI string = app.outputs.uri
output SERVICE_WEB_IMAGE_NAME string = app.outputs.imageName

output uri string = app.outputs.uri
9 changes: 2 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@
line-length = 120
select = ["E", "F", "I", "UP"]
ignore = ["D203"]
extend-exclude = ["src/flaskapp/migrations/"]

[tool.ruff.isort]
known-first-party = ["fastapi_app"]

[tool.black]
line-length = 120

[tool.pytest.ini_options]
addopts = "-ra --cov -vv"

[tool.coverage.report]
show_missing = true
addopts = "-ra -vv"
4 changes: 1 addition & 3 deletions requirements-dev.in → requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ cruft
pip-tools

# Testing Tools
coverage
pytest
pytest-cov
ephemeral-port-reserve
pytest-playwright

# Linters
ruff
black
Loading
Loading