Skip to content

Commit 4666260

Browse files
use one-off jobs for migrations
1 parent f928fee commit 4666260

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"permissions": {
3+
"allow": [
4+
"Bash(docker compose:*)"
5+
],
6+
"deny": []
7+
}
8+
}

samples/django-channels-redis-postgres/app/Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Use a smaller base image
2-
FROM python:3.10-slim-buster
2+
FROM python:3.10-slim-bullseye
33

44
# Set environment variables
55
ENV PYTHONDONTWRITEBYTECODE=1
@@ -12,7 +12,8 @@ RUN apt-get update \
1212
&& apt-get install -y \
1313
gcc \
1414
python3-dev \
15-
libpq-dev
15+
libpq-dev \
16+
netcat-openbsd
1617

1718
# Install dependencies
1819
COPY requirements.txt /app/
@@ -32,4 +33,4 @@ RUN adduser --disabled-password --gecos '' django
3233
USER django
3334

3435
# Start server
35-
CMD ["sh", "-c", "python manage.py migrate && daphne -b 0.0.0.0 -p 8000 django_defang.asgi:application"]
36+
CMD ["sh", "-c", "daphne -b 0.0.0.0 -p 8000 django_defang.asgi:application"]

samples/django-channels-redis-postgres/compose.dev.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,16 @@ services:
1313
depends_on:
1414
- redis-service
1515
- postgres-service
16-
command: sh -c "python manage.py migrate && python manage.py runserver 0.0.0.0:8000"
16+
- migrate
17+
command: sh -c "python manage.py runserver 0.0.0.0:8000"
1718

19+
migrate:
20+
extends:
21+
file: compose.yaml
22+
service: migrate
23+
environment:
24+
- POSTGRES_URL=postgres://djangouser:djangopassword@postgres-service:5432/djangodatabase
25+
1826
redis-service:
1927
extends:
2028
file: compose.yaml

samples/django-channels-redis-postgres/compose.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ services:
2222
depends_on:
2323
- redis-service
2424
- postgres-service
25+
- migrate
2526

2627
redis-service:
2728
image: redis:6.2
@@ -31,6 +32,18 @@ services:
3132
- mode: host
3233
target: 6379
3334

35+
migrate:
36+
restart: "no"
37+
build:
38+
context: ./app
39+
dockerfile: Dockerfile
40+
command: python manage.py migrate
41+
depends_on:
42+
- postgres-service
43+
environment:
44+
- POSTGRES_URL=postgres://djangouser:${POSTGRES_PASSWORD}@postgres-service:5432/djangodatabase?
45+
- SECRET_KEY
46+
3447
postgres-service:
3548
image: postgres:16.4
3649
# uncomment the following line in BYOC

0 commit comments

Comments
 (0)