Skip to content

Commit 8189b72

Browse files
committed
more testing with postgres
1 parent 140cce8 commit 8189b72

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

samples/django-channels-redis/app/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ RUN adduser --disabled-password --gecos '' django
3131
USER django
3232

3333
# Start server
34-
CMD ["sh", "-c", "python manage.py migrate && gunicorn django_defang.wsgi:application --bind 0.0.0.0:8000"]
34+
CMD ["sh", "-c", "python manage.py migrate && daphne -b 0.0.0.0 -p 8000 django_defang.asgi:application"]

samples/django-channels-redis/app/django_defang/settings.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,19 @@
1515
import dj_database_url
1616
import urllib.parse
1717

18+
19+
# print redis and postgres urls
20+
print('@@@@@@@ DEBUG @@@@@@@')
21+
print(f'redis: {os.getenv("REDIS_URL", None)}')
22+
print(f'postgres: {os.getenv("POSTGRES_URL", None)}')
23+
print(f'postgres_password: {os.getenv("POSTGRES_PASSWORD", None)}')
24+
postgres_url = os.getenv("POSTGRES_URL", None)
25+
postgres_password = os.getenv("POSTGRES_PASSWORD", None)
26+
fixed_postgres_url = postgres_url.replace("password", postgres_password) if postgres_url and postgres_password else postgres_url
27+
print(f'fixed_postgres_url: {fixed_postgres_url}')
28+
print('@@@@@@@ DEBUG @@@@@@@')
29+
30+
1831
# Build paths inside the project like this: BASE_DIR / 'subdir'.
1932
BASE_DIR = Path(__file__).resolve().parent.parent
2033

@@ -82,10 +95,11 @@
8295
# Database
8396
# https://docs.djangoproject.com/en/5.1/ref/settings/#databases
8497

98+
8599
DATABASES = {
86100
# default is a postrgres database load from environment variable POSTGRES_URL
87101
"default": dj_database_url.config(
88-
default=os.environ.get('POSTGRES_URL')
102+
default=fixed_postgres_url
89103
)
90104
}
91105

@@ -160,4 +174,4 @@
160174
"hosts": [(redis_host, redis_port)],
161175
},
162176
},
163-
}
177+
}

samples/django-channels-redis/compose.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ services:
1313
mode: ingress
1414
environment:
1515
REDIS_URL: redis://redis_service:6379
16-
POSTGRES_URL: postgres://postgres:password@postgres_service:5432
16+
POSTGRES_URL: postgres://postgres:password@postgres_service:5432/postgres
17+
POSTGRES_PASSWORD: testtest
1718
healthcheck:
1819
# wget or curl required for healthchecks on services with a published port
1920
# this gets parsed by Defang and provided to the load balancers as well
@@ -31,4 +32,6 @@ services:
3132
x-defang-postgres: true
3233
ports:
3334
- mode: host
34-
target: 5432
35+
target: 5432
36+
environment:
37+
POSTGRES_PASSWORD: testtest

0 commit comments

Comments
 (0)