Skip to content

Commit 3a996dd

Browse files
committed
Dockerized environment to launch local dev server
1 parent 7e362e1 commit 3a996dd

File tree

8 files changed

+84
-2
lines changed

8 files changed

+84
-2
lines changed

Makefile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
up:
2+
docker-compose -f ./docker/docker-compose.yml up
3+
4+
build:
5+
docker-compose -f ./docker/docker-compose.yml build

README.md

+28-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,28 @@
1-
# multisite
2-
Example of multiple sites with one Django source
1+
Multisite Test
2+
==============
3+
4+
Example of multiple sites with one Django source.
5+
6+
This is just an example project to illustrate Django's multisite feature.
7+
8+
9+
## Run local server
10+
11+
We use `docker-compose` to launch development server. The command is wrapped
12+
inside `Makefile`, so you can just type:
13+
14+
```
15+
$ make up
16+
```
17+
18+
Then, open `http://127.0.0.1:8000` or `http://site1.local:8000` in the browser
19+
to access the server. This makes you can see the contents of default site 1.
20+
If you want to visit site 2, just try `http://site2.local:8000`. You can see
21+
different contents depending on the address you typed.
22+
23+
If you want to re-build the docker images later, you can use another make
24+
command.
25+
26+
```
27+
$ make build
28+
```

docker/Dockerfile

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM python:3.7-alpine3.10
2+
3+
ENV PYTHONUNBUFFERED 1
4+
5+
# Install Python requirements.
6+
COPY ./requirements.txt /requirements.txt
7+
RUN pip install -r /requirements.txt
8+
9+
COPY ./start /start
10+
RUN chmod +x /start
11+
12+
WORKDIR /app

docker/docker-compose.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version: "3"
2+
3+
services:
4+
django:
5+
build:
6+
context: .
7+
dockerfile: ./Dockerfile
8+
image: multisite_django
9+
container_name: multisite_django
10+
volumes:
11+
- ..:/app
12+
env_file:
13+
- ./envs
14+
ports:
15+
- "8000:8000"
16+
command: /start

docker/envs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Environment variables can be set here. They are applied in container.

docker/requirements.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
django~=2.2.3
2+
3+
# Development
4+
django-extensions~=2.1.6
5+
flake8~=3.7.5

docker/start

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh
2+
3+
set -o errexit
4+
set -o pipefail
5+
set -o nounset
6+
7+
cat <<EOF | python manage.py shell
8+
from django.contrib.auth import get_user_model
9+
User = get_user_model()
10+
if not User.objects.filter(username='admin').exists():
11+
User.objects.create_superuser('admin', '[email protected]', '0')
12+
print('Default "admin" user is created.')
13+
EOF
14+
python manage.py migrate
15+
python manage.py runserver 0.0.0.0:8000

run_in_container.sh

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/bin/bash
2+
docker exec -it multisite_django "$@"

0 commit comments

Comments
 (0)