pulumi-django-azure 1.0.22__py3-none-any.whl → 1.0.24__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pulumi-django-azure might be problematic. Click here for more details.

@@ -844,6 +844,7 @@ class DjangoDeployment(pulumi.ComponentResource):
844
844
  dedicated_app_service_sku: azure.web.SkuDescriptionArgs | None = None,
845
845
  vault_administrators: list[str] | None = None,
846
846
  cache_db: int | None = None,
847
+ startup_timeout: int = 300,
847
848
  ) -> azure.web.WebApp:
848
849
  """
849
850
  Create a Django website with it's own database and storage containers.
@@ -864,6 +865,7 @@ class DjangoDeployment(pulumi.ComponentResource):
864
865
  :param dedicated_app_service_sku: The SKU for the dedicated App Service Plan (optional).
865
866
  :param vault_administrators: The principal IDs of the vault administrators (optional).
866
867
  :param cache_db: The index of the cache database to use (optional).
868
+ :param startup_timeout: The startup timeout for the App Service (default is 300 seconds).
867
869
  """
868
870
 
869
871
  # Create a database
@@ -962,6 +964,10 @@ class DjangoDeployment(pulumi.ComponentResource):
962
964
  # scm_type=azure.web.ScmType.EXTERNAL_GIT,
963
965
  linux_fx_version=f"PYTHON|{python_version}",
964
966
  app_settings=[
967
+ # Startup settings
968
+ azure.web.NameValuePairArgs(name="WEBSITES_CONTAINER_START_TIME_LIMIT", value=str(startup_timeout)),
969
+ # To support our settings helper
970
+ azure.web.NameValuePairArgs(name="IS_AZURE_ENVIRONMENT", value="true"),
965
971
  # Build settings
966
972
  azure.web.NameValuePairArgs(name="SCM_DO_BUILD_DURING_DEPLOYMENT", value="true"),
967
973
  azure.web.NameValuePairArgs(name="PRE_BUILD_COMMAND", value="cicd/pre_build.sh"),
@@ -1,43 +1,43 @@
1
- from django.conf import settings
2
- from django.core.cache import cache
3
- from django.db import connection
4
- from django.db.utils import OperationalError
5
- from django.http import HttpResponse
6
- from django_redis import get_redis_connection
7
-
8
- from .azure_helper import get_db_password, get_redis_credentials
9
-
10
-
11
- class HealthCheckMiddleware:
12
- def __init__(self, get_response):
13
- self.get_response = get_response
14
-
15
- def __call__(self, request):
16
- if request.path == settings.HEALTH_CHECK_PATH:
17
- # Update the database credentials if needed
18
- if settings.AZURE_DB_PASSWORD:
19
- settings.DATABASES["default"]["PASSWORD"] = get_db_password()
20
-
21
- # Update the Redis credentials if needed
22
- if settings.AZURE_REDIS_CREDENTIALS:
23
- redis_credentials = get_redis_credentials()
24
-
25
- # Re-authenticate the Redis connection
26
- redis_connection = get_redis_connection("default")
27
- redis_connection.execute_command("AUTH", redis_credentials.username, redis_credentials.password)
28
-
29
- settings.CACHES["default"]["OPTIONS"]["PASSWORD"] = redis_credentials.password
30
-
31
- try:
32
- # Test the database connection
33
- connection.ensure_connection()
34
-
35
- # Test the Redis connection
36
- cache.set("health_check", "test")
37
-
38
- return HttpResponse("OK")
39
-
40
- except OperationalError:
41
- return HttpResponse(status=503)
42
-
43
- return self.get_response(request)
1
+ from django.conf import settings
2
+ from django.core.cache import cache
3
+ from django.db import connection
4
+ from django.db.utils import OperationalError
5
+ from django.http import HttpResponse
6
+ from django_redis import get_redis_connection
7
+
8
+ from .azure_helper import get_db_password, get_redis_credentials
9
+
10
+
11
+ class HealthCheckMiddleware:
12
+ def __init__(self, get_response):
13
+ self.get_response = get_response
14
+
15
+ def __call__(self, request):
16
+ if request.path == settings.HEALTH_CHECK_PATH:
17
+ # Update the database credentials if needed
18
+ if settings.AZURE_DB_PASSWORD:
19
+ settings.DATABASES["default"]["PASSWORD"] = get_db_password()
20
+
21
+ # Update the Redis credentials if needed
22
+ if settings.AZURE_REDIS_CREDENTIALS:
23
+ redis_credentials = get_redis_credentials()
24
+
25
+ # Re-authenticate the Redis connection
26
+ redis_connection = get_redis_connection("default")
27
+ redis_connection.execute_command("AUTH", redis_credentials.username, redis_credentials.password)
28
+
29
+ settings.CACHES["default"]["OPTIONS"]["PASSWORD"] = redis_credentials.password
30
+
31
+ try:
32
+ # Test the database connection
33
+ connection.ensure_connection()
34
+
35
+ # Test the Redis connection
36
+ cache.set("health_check", "test")
37
+
38
+ return HttpResponse("OK")
39
+
40
+ except OperationalError:
41
+ return HttpResponse(status=503)
42
+
43
+ return self.get_response(request)
@@ -5,111 +5,128 @@ from .azure_helper import AZURE_CREDENTIAL, LOCAL_IP_ADDRESSES, get_db_password,
5
5
 
6
6
  env = environ.Env()
7
7
 
8
- SECRET_KEY = env("DJANGO_SECRET_KEY")
8
+ SECRET_KEY = env("DJANGO_SECRET_KEY", default=None)
9
+
10
+ IS_AZURE_ENVIRONMENT = env("IS_AZURE_ENVIRONMENT", default=False)
11
+
12
+ # Some generic stuff we only need if we're running in Azure.
13
+ # Most of the other stuff will check for the explicit variable we need.
14
+ if IS_AZURE_ENVIRONMENT:
15
+ # Detect HTTPS behind AppService
16
+ SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
17
+
18
+ # Azure context
19
+ AZURE_SUBSCRIPTION = get_subscription()
20
+ AZURE_TENANT_ID = AZURE_SUBSCRIPTION.tenant_id
21
+ AZURE_SUBSCRIPTION_ID = AZURE_SUBSCRIPTION.subscription_id
9
22
 
10
23
  # Health check path
11
24
  HEALTH_CHECK_PATH = env("HEALTH_CHECK_PATH", default="/health")
12
25
 
13
26
  ALLOWED_HOSTS: list = env.list("DJANGO_ALLOWED_HOSTS", default=[])
27
+
14
28
  # WEBSITE_HOSTNAME contains the Azure domain name
15
- ALLOWED_HOSTS.append(env("WEBSITE_HOSTNAME"))
29
+ if website_hostname := env("WEBSITE_HOSTNAME", default=None):
30
+ ALLOWED_HOSTS.append(website_hostname)
31
+
16
32
  # Add the local IP addresses of the machine for health checks
17
33
  ALLOWED_HOSTS.extend(LOCAL_IP_ADDRESSES)
18
34
 
19
- # Detect HTTPS behind AppService
20
- SECURE_PROXY_SSL_HEADER = ("HTTP_X_FORWARDED_PROTO", "https")
21
-
22
-
23
- # Azure context
24
- AZURE_SUBSCRIPTION = get_subscription()
25
- AZURE_TENANT_ID = AZURE_SUBSCRIPTION.tenant_id
26
- AZURE_SUBSCRIPTION_ID = AZURE_SUBSCRIPTION.subscription_id
27
-
28
35
  # Azure Key Vault
29
- AZURE_KEY_VAULT = env("AZURE_KEY_VAULT")
30
- AZURE_KEY_VAULT_URI = f"https://{AZURE_KEY_VAULT}.vault.azure.net"
31
- AZURE_KEY_VAULT_CLIENT = SecretClient(vault_url=AZURE_KEY_VAULT_URI, credential=AZURE_CREDENTIAL)
36
+ if azure_key_vault := env("AZURE_KEY_VAULT", default=None):
37
+ AZURE_KEY_VAULT_URI = f"https://{azure_key_vault}.vault.azure.net"
38
+ AZURE_KEY_VAULT_CLIENT = SecretClient(vault_url=AZURE_KEY_VAULT_URI, credential=AZURE_CREDENTIAL)
32
39
 
33
40
  # Allow CSRF cookies to be sent from our domains
34
41
  # CSRF_TRUSTED_ORIGINS = ["https://" + host for host in ALLOWED_HOSTS]
35
- AZURE_ACCOUNT_NAME = env("AZURE_STORAGE_ACCOUNT_NAME")
36
- AZURE_TOKEN_CREDENTIAL = AZURE_CREDENTIAL
42
+ if azure_storage_account_name := env("AZURE_STORAGE_ACCOUNT_NAME", default=None):
43
+ AZURE_ACCOUNT_NAME = azure_storage_account_name
44
+ AZURE_TOKEN_CREDENTIAL = AZURE_CREDENTIAL
37
45
 
38
46
 
39
47
  # CDN domain - shared for all storages
40
- AZURE_CUSTOM_DOMAIN = env("CDN_HOST")
48
+ if cdn_host := env("CDN_HOST", default=None):
49
+ AZURE_CUSTOM_DOMAIN = cdn_host
50
+
51
+ STATIC_URL = f"https://{AZURE_CUSTOM_DOMAIN}/static/"
52
+ MEDIA_URL = f"https://{AZURE_CUSTOM_DOMAIN}/media/"
41
53
 
42
- STORAGES = {
43
- "default": {
54
+ # Storage configuration
55
+ STORAGES = {}
56
+ if container_media := env("AZURE_STORAGE_CONTAINER_MEDIA", default=None):
57
+ STORAGES["default"] = {
44
58
  "BACKEND": "storages.backends.azure_storage.AzureStorage",
45
59
  "OPTIONS": {
46
- "azure_container": env("AZURE_STORAGE_CONTAINER_MEDIA"),
60
+ "azure_container": container_media,
47
61
  "overwrite_files": False,
48
62
  },
49
- },
50
- "staticfiles": {
63
+ }
64
+
65
+ if container_staticfiles := env("AZURE_STORAGE_CONTAINER_STATICFILES", default=None):
66
+ STORAGES["staticfiles"] = {
51
67
  "BACKEND": "storages.backends.azure_storage.AzureStorage",
52
68
  "OPTIONS": {
53
- "azure_container": env("AZURE_STORAGE_CONTAINER_STATICFILES"),
69
+ "azure_container": container_staticfiles,
54
70
  },
55
- },
56
- }
57
-
58
-
59
- # STATIC_ROOT = BASE_DIR / "staticfiles"
60
- STATIC_URL = f"https://{AZURE_CUSTOM_DOMAIN}/static/"
61
- MEDIA_URL = f"https://{AZURE_CUSTOM_DOMAIN}/media/"
71
+ }
62
72
 
63
73
  # This setting enables password rotation in the health check middleware
64
- AZURE_DB_PASSWORD = True
65
- DATABASES = {
66
- "default": {
67
- "ENGINE": "django.db.backends.postgresql",
68
- "NAME": env("DB_NAME"),
69
- "USER": env("DB_USER"),
70
- "HOST": env("DB_HOST"),
71
- "PASSWORD": get_db_password(),
72
- "PORT": "5432",
73
- "OPTIONS": {
74
- "sslmode": "require",
75
- },
76
- # Make connections persistent
77
- "CONN_MAX_AGE": None,
78
- # To enable health checks, add the following:
79
- # "CONN_HEALTH_CHECKS": True,
74
+ if IS_AZURE_ENVIRONMENT:
75
+ AZURE_DB_PASSWORD = True
76
+ DATABASES = {
77
+ "default": {
78
+ "ENGINE": "django.db.backends.postgresql",
79
+ "NAME": env("DB_NAME"),
80
+ "USER": env("DB_USER"),
81
+ "HOST": env("DB_HOST"),
82
+ "PASSWORD": get_db_password(),
83
+ "PORT": "5432",
84
+ "OPTIONS": {
85
+ "sslmode": "require",
86
+ },
87
+ # Make connections persistent
88
+ "CONN_MAX_AGE": None,
89
+ # To enable health checks, add the following:
90
+ # "CONN_HEALTH_CHECKS": True,
91
+ }
80
92
  }
81
- }
82
93
 
83
94
  # Email
84
95
  EMAIL_BACKEND = "django_azure_communication_email.EmailBackend"
85
- AZURE_COMMUNICATION_ENDPOINT = env("AZURE_COMMUNICATION_SERVICE_ENDPOINT")
86
- DEFAULT_FROM_EMAIL = env("DJANGO_DEFAULT_FROM_EMAIL")
96
+ AZURE_COMMUNICATION_ENDPOINT = env("AZURE_COMMUNICATION_SERVICE_ENDPOINT", default=None)
97
+ DEFAULT_FROM_EMAIL = env("DJANGO_DEFAULT_FROM_EMAIL", default=None)
87
98
 
88
99
 
89
100
  # Logging
90
- LOGGING = {
91
- "version": 1,
92
- "disable_existing_loggers": False,
93
- "handlers": {
94
- "file": {
95
- "level": "INFO",
96
- "class": "logging.handlers.RotatingFileHandler",
97
- "filename": "/home/LogFiles/django.log",
98
- "maxBytes": 1024 * 1024 * 100, # 100 mb
99
- "backupCount": 5,
101
+ if IS_AZURE_ENVIRONMENT:
102
+ LOGGING = {
103
+ "version": 1,
104
+ "disable_existing_loggers": False,
105
+ "handlers": {
106
+ "file": {
107
+ "level": "INFO",
108
+ "class": "logging.handlers.TimedRotatingFileHandler",
109
+ "filename": "/home/LogFiles/django.log",
110
+ "when": "h",
111
+ "interval": 1,
112
+ "backupCount": 24,
113
+ },
100
114
  },
101
- },
102
- "loggers": {
103
- "django": {
104
- "handlers": ["file"],
105
- "level": "INFO",
106
- "propagate": True,
115
+ "loggers": {
116
+ "django": {
117
+ "handlers": ["file"],
118
+ "level": "INFO",
119
+ "propagate": True,
120
+ },
107
121
  },
108
- },
109
- }
122
+ }
110
123
 
111
124
  # Redis, if enabled
112
- if env("REDIS_CACHE_HOST") and env("REDIS_CACHE_PORT") and env("REDIS_CACHE_DB"):
125
+ redis_cache_host = env("REDIS_CACHE_HOST", default=None)
126
+ redis_cache_port = env("REDIS_CACHE_PORT", default=None)
127
+ redis_cache_db = env("REDIS_CACHE_DB", default=None)
128
+
129
+ if redis_cache_host and redis_cache_port and redis_cache_db:
113
130
  # This will enable the health check to update the Redis credentials
114
131
  AZURE_REDIS_CREDENTIALS = True
115
132
 
@@ -117,9 +134,9 @@ if env("REDIS_CACHE_HOST") and env("REDIS_CACHE_PORT") and env("REDIS_CACHE_DB")
117
134
  DJANGO_REDIS_IGNORE_EXCEPTIONS = True
118
135
  DJANGO_REDIS_LOG_IGNORED_EXCEPTIONS = True
119
136
 
120
- REDIS_CACHE_HOST = env("REDIS_CACHE_HOST")
121
- REDIS_CACHE_PORT = env("REDIS_CACHE_PORT")
122
- REDIS_CACHE_DB = env("REDIS_CACHE_DB")
137
+ REDIS_CACHE_HOST = redis_cache_host
138
+ REDIS_CACHE_PORT = redis_cache_port
139
+ REDIS_CACHE_DB = redis_cache_db
123
140
  redis_credentials = get_redis_credentials()
124
141
  REDIS_USERNAME = redis_credentials.username
125
142
  REDIS_PASSWORD = redis_credentials.password
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: pulumi-django-azure
3
- Version: 1.0.22
3
+ Version: 1.0.24
4
4
  Summary: Simply deployment of Django on Azure with Pulumi
5
5
  Author-email: Maarten Ureel <maarten@youreal.eu>
6
6
  License: MIT License
@@ -46,6 +46,7 @@ Requires-Dist: pulumi>=3.156.0
46
46
  Requires-Dist: pulumi-azure-native>=2.89.1
47
47
  Requires-Dist: pulumi-random>=4.18.0
48
48
  Requires-Dist: redis[hiredis]<6.0.0,>=5.2.1
49
+ Dynamic: license-file
49
50
 
50
51
  # Pulumi Django Deployment
51
52
 
@@ -0,0 +1,12 @@
1
+ pulumi_django_azure/__init__.py,sha256=WoTHLNGnqc3dQoJtzrAJY8OVA7ReP6XFkDb9BXZGfJ8,117
2
+ pulumi_django_azure/azure_helper.py,sha256=HU0cb85jTeh70qjv11foWuqgE-SNQ21bhMKsy1lB7MM,1903
3
+ pulumi_django_azure/django_deployment.py,sha256=VL9MTEq5rDLGdJPDQWHHCGbeC3Taw7vnpq_DGoMA6Ec,49705
4
+ pulumi_django_azure/middleware.py,sha256=kOWtlY3kjmUgpTXjDhGIzNeJtBWjn8FRmGQRZqWsSG0,1589
5
+ pulumi_django_azure/settings.py,sha256=hC1to1sgKeA7Lw43PlCx4AJ1AOQLuXbAhDIprD3uKc8,5482
6
+ pulumi_django_azure/management/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ pulumi_django_azure/management/commands/purge_cdn.py,sha256=1lZI5liDIiOGyJRmo9gRn-BDLHaRuipaUmUAm06bRr0,2093
8
+ pulumi_django_azure-1.0.24.dist-info/licenses/LICENSE,sha256=NX2LN3U319Zaac8b7ZgfNOco_nTBbN531X_M_13niSg,1087
9
+ pulumi_django_azure-1.0.24.dist-info/METADATA,sha256=yM_sCef90KAfykNnXKh0xdQ4LG64uYRk6AGBrHoYbNc,12537
10
+ pulumi_django_azure-1.0.24.dist-info/WHEEL,sha256=1tXe9gY0PYatrMPMDd6jXqjfpz_B-Wqm32CPfRC58XU,91
11
+ pulumi_django_azure-1.0.24.dist-info/top_level.txt,sha256=MNPRJhq-_G8EMCHRkjdcb_xrqzOkmKogXUGV7Ysz3g0,20
12
+ pulumi_django_azure-1.0.24.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (76.0.0)
2
+ Generator: setuptools (77.0.3)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,12 +0,0 @@
1
- pulumi_django_azure/__init__.py,sha256=WoTHLNGnqc3dQoJtzrAJY8OVA7ReP6XFkDb9BXZGfJ8,117
2
- pulumi_django_azure/azure_helper.py,sha256=HU0cb85jTeh70qjv11foWuqgE-SNQ21bhMKsy1lB7MM,1903
3
- pulumi_django_azure/django_deployment.py,sha256=bSMczOl7nivLGVhfEXroDc_FyD0hXLne1TwhdhLMoNY,49260
4
- pulumi_django_azure/middleware.py,sha256=AtZJO3NJLaf6Zdkbv2_SV9UeCZpXShMfomxpMEE0ab0,1546
5
- pulumi_django_azure/settings.py,sha256=2Mu1k5bvx8LIgbGH8qI2RcKixyZW2njeHGUda39P4Xs,4496
6
- pulumi_django_azure/management/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
- pulumi_django_azure/management/commands/purge_cdn.py,sha256=1lZI5liDIiOGyJRmo9gRn-BDLHaRuipaUmUAm06bRr0,2093
8
- pulumi_django_azure-1.0.22.dist-info/LICENSE,sha256=NX2LN3U319Zaac8b7ZgfNOco_nTBbN531X_M_13niSg,1087
9
- pulumi_django_azure-1.0.22.dist-info/METADATA,sha256=uND6SLUYtIOnTqHsh7rf_p7QVVTQQqy-6y4pKLYXl2k,12514
10
- pulumi_django_azure-1.0.22.dist-info/WHEEL,sha256=52BFRY2Up02UkjOa29eZOS2VxUrpPORXg1pkohGGUS8,91
11
- pulumi_django_azure-1.0.22.dist-info/top_level.txt,sha256=MNPRJhq-_G8EMCHRkjdcb_xrqzOkmKogXUGV7Ysz3g0,20
12
- pulumi_django_azure-1.0.22.dist-info/RECORD,,