Skip to content

Commit 87329ab

Browse files
committed
fix django
1 parent b9e9118 commit 87329ab

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

Dockerfile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ WORKDIR /app
66
COPY --chown=app:app ./requirements.txt /app/
77
RUN pip install -r /app/requirements.txt; \
88
mkdir -p /app/static; \
9-
chown -R app:app /app/static
9+
chown -R app:app /app/static; \
10+
apt update; \
11+
apt install -y --no-install-recommends postgresql-client
1012
COPY --chown=app:app . /app/
1113
ENV DEBUG=True
1214
USER app
1315
EXPOSE 8000
14-
CMD [ "./manage.py", "runserver", "0.0.0.0:8000" ]
16+
CMD [ "bash", "entrypoint.sh" ]

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ This is a hello world app that is written in [Python](https://www.python.org/),
1010

1111
```bash
1212
$ git clone repo
13-
$ docker-compose up -d db
14-
$ docker-compose run app python manage.py migrate
1513
$ docker-compose up --build
1614
```
1715

docker-compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ services:
2525
environment:
2626
- POSTGRES_USER=app
2727
- POSTGRES_PASSWORD=app
28-
ports:
29-
- 5432:5432
28+
# ports:
29+
# - 5432:5432
3030
volumes:
3131
- db-data:/var/lib/postgresql/data
3232

entrypoint.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
3+
# Check if database is ready
4+
while ! pg_isready -q -h ${POSTGRES_HOST:-postgres} -p ${POSTGRES_PORT:-5432} -U ${POSTGRES_USER:-postgres}; do
5+
echo "Waiting for database connection..."
6+
sleep 1
7+
done
8+
9+
if [ -z "${SKIP_MIGRATION}" ]; then
10+
python manage.py migrate --noinput
11+
fi
12+
13+
if [ -z "${SKIP_COLLECTSTATIC}" ]; then
14+
python manage.py collectstatic --noinput
15+
fi
16+
17+
if [ -z "${USE_WSGI}" ]; then
18+
exec python manage.py runserver 0.0.0.0:${PORT:-8000}
19+
else
20+
exec gunicorn --bind 0.0.0.0:${PORT:-8000} hello_world.wsgi:application
21+
fi

0 commit comments

Comments
 (0)