forked from PacktPublishing/Django-5-By-Example
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added docker compose to all chapters
- Loading branch information
Showing
48 changed files
with
2,423 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
FROM python:3.12.3-slim | ||
|
||
RUN apt-get update -qq \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Set environment variables | ||
ENV PIP_DISABLE_PIP_VERSION_CHECK 1 | ||
ENV PYTHONDONTWRITEBYTECODE 1 | ||
ENV PYTHONUNBUFFERED 1 | ||
|
||
WORKDIR /code | ||
|
||
COPY requirements.txt . | ||
RUN python -m pip install -r requirements.txt | ||
|
||
COPY . . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
#!/bin/bash | ||
|
||
COLUMNS="`tput cols`" | ||
LINES="`tput lines`" | ||
BOLD=$(tput bold) | ||
NORMAL=$(tput sgr0) | ||
|
||
COMPOSE_FILES="-f docker-compose.yml" | ||
|
||
DOCKER_COMPOSE="docker compose ${COMPOSE_FILES}" | ||
|
||
# Game-specific commands: | ||
_requires() { | ||
service="$1" | ||
$DOCKER_COMPOSE ps -q $service &> /dev/null | ||
if [[ "$?" == 1 ]]; then | ||
echo "'$service' service is not running. Please run \`start\` first." | ||
exit 1 | ||
fi | ||
} | ||
|
||
build() { | ||
$DOCKER_COMPOSE build --force-rm "${@:3}" | ||
} | ||
|
||
compose() { | ||
$DOCKER_COMPOSE "$@" | ||
} | ||
|
||
start() { | ||
$DOCKER_COMPOSE up "$@" | ||
} | ||
|
||
stop() { | ||
$DOCKER_COMPOSE down "$@" | ||
} | ||
|
||
shell() { | ||
_requires web_run | ||
exec -w /code/mysite web_run /bin/bash | ||
} | ||
|
||
migrate() { | ||
_requires web_run | ||
exec -w /code/mysite web_run ./manage.py migrate "$@" | ||
} | ||
|
||
makemigrations() { | ||
_requires web_run | ||
exec -w /code/mysite web_run python manage.py makemigrations "$@" | ||
} | ||
|
||
check() { | ||
_requires web_run | ||
exec -w /code/mysite web_run ./manage.py check | ||
} | ||
|
||
exec() { | ||
$DOCKER_COMPOSE exec -e COLUMNS -e LINES "$@" | ||
} | ||
|
||
_usage() { | ||
cat <<USAGE | ||
Convenience wrapper around docker compose. | ||
Usage: | ||
${BOLD}build${NORMAL} [<arg>] | ||
Builds all the images (or the ones specified). | ||
${BOLD}exec${NORMAL} [<arg>] | ||
Execute a command in a container | ||
${BOLD}compose${NORMAL} | ||
Minimal wrapper around docker-compose, just ensures the correct config files are loaded. | ||
${BOLD}migrate${NORMAL} [<arg>] | ||
Apply any unapplied django migrations | ||
${BOLD}makemigrations${NORMAL} [<arg>] | ||
Create a new Django migration, using the given args | ||
${BOLD}check${NORMAL} | ||
Validate django settings | ||
${BOLD}shell${NORMAL} | ||
Opens a bash terminal in web_run | ||
${BOLD}start${NORMAL} [<arg>] | ||
Start the django server (and dependent services) | ||
You can pass `-d` for running detached. | ||
${BOLD}stop${NORMAL} [<arg>] | ||
Stop the django server (and dependent services) | ||
USAGE | ||
} | ||
|
||
if [ "$1" == "" ]; then | ||
_usage | ||
fi | ||
|
||
$* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
services: | ||
web: | ||
build: . | ||
volumes: | ||
- .:/code | ||
web_migrate: | ||
extends: | ||
service: web | ||
command: python /code/mysite/manage.py migrate | ||
web_run: | ||
extends: | ||
service: web | ||
command: python /code/mysite/manage.py runserver 0.0.0.0:8000 | ||
ports: | ||
- "8000:8000" | ||
depends_on: | ||
- web_migrate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
FROM python:3.12.3-slim | ||
|
||
RUN apt-get update -qq \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Set environment variables | ||
ENV PIP_DISABLE_PIP_VERSION_CHECK 1 | ||
ENV PYTHONDONTWRITEBYTECODE 1 | ||
ENV PYTHONUNBUFFERED 1 | ||
|
||
WORKDIR /code | ||
|
||
COPY requirements.txt . | ||
RUN python -m pip install -r requirements.txt | ||
|
||
COPY . . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
#!/bin/bash | ||
|
||
COLUMNS="`tput cols`" | ||
LINES="`tput lines`" | ||
BOLD=$(tput bold) | ||
NORMAL=$(tput sgr0) | ||
|
||
COMPOSE_FILES="-f docker-compose.yml" | ||
|
||
DOCKER_COMPOSE="docker compose ${COMPOSE_FILES}" | ||
|
||
# Game-specific commands: | ||
_requires() { | ||
service="$1" | ||
$DOCKER_COMPOSE ps -q $service &> /dev/null | ||
if [[ "$?" == 1 ]]; then | ||
echo "'$service' service is not running. Please run \`start\` first." | ||
exit 1 | ||
fi | ||
} | ||
|
||
build() { | ||
$DOCKER_COMPOSE build --force-rm "${@:3}" | ||
} | ||
|
||
compose() { | ||
$DOCKER_COMPOSE "$@" | ||
} | ||
|
||
start() { | ||
$DOCKER_COMPOSE up "$@" | ||
} | ||
|
||
stop() { | ||
$DOCKER_COMPOSE down "$@" | ||
} | ||
|
||
shell() { | ||
_requires web_run | ||
exec -w /code/mysite web_run /bin/bash | ||
} | ||
|
||
migrate() { | ||
_requires web_run | ||
exec -w /code/mysite web_run ./manage.py migrate "$@" | ||
} | ||
|
||
makemigrations() { | ||
_requires web_run | ||
exec -w /code/mysite web_run python manage.py makemigrations "$@" | ||
} | ||
|
||
check() { | ||
_requires web_run | ||
exec -w /code/mysite web_run ./manage.py check | ||
} | ||
|
||
exec() { | ||
$DOCKER_COMPOSE exec -e COLUMNS -e LINES "$@" | ||
} | ||
|
||
_usage() { | ||
cat <<USAGE | ||
Convenience wrapper around docker compose. | ||
Usage: | ||
${BOLD}build${NORMAL} [<arg>] | ||
Builds all the images (or the ones specified). | ||
${BOLD}exec${NORMAL} [<arg>] | ||
Execute a command in a container | ||
${BOLD}compose${NORMAL} | ||
Minimal wrapper around docker-compose, just ensures the correct config files are loaded. | ||
${BOLD}migrate${NORMAL} [<arg>] | ||
Apply any unapplied django migrations | ||
${BOLD}makemigrations${NORMAL} [<arg>] | ||
Create a new Django migration, using the given args | ||
${BOLD}check${NORMAL} | ||
Validate django settings | ||
${BOLD}shell${NORMAL} | ||
Opens a bash terminal in web_run | ||
${BOLD}start${NORMAL} [<arg>] | ||
Start the django server (and dependent services) | ||
You can pass `-d` for running detached. | ||
${BOLD}stop${NORMAL} [<arg>] | ||
Stop the django server (and dependent services) | ||
USAGE | ||
} | ||
|
||
if [ "$1" == "" ]; then | ||
_usage | ||
fi | ||
|
||
$* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
services: | ||
web: | ||
build: . | ||
env_file: | ||
- .env | ||
volumes: | ||
- .:/code | ||
web_migrate: | ||
extends: | ||
service: web | ||
command: python /code/mysite/manage.py migrate | ||
web_run: | ||
extends: | ||
service: web | ||
command: python /code/mysite/manage.py runserver 0.0.0.0:8000 | ||
ports: | ||
- "8000:8000" | ||
depends_on: | ||
- web_migrate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
FROM python:3.12.3-slim | ||
|
||
RUN apt-get update -qq \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
# Set environment variables | ||
ENV PIP_DISABLE_PIP_VERSION_CHECK 1 | ||
ENV PYTHONDONTWRITEBYTECODE 1 | ||
ENV PYTHONUNBUFFERED 1 | ||
|
||
WORKDIR /code | ||
|
||
COPY requirements.txt . | ||
RUN python -m pip install -r requirements.txt | ||
RUN python -m pip install psycopg[binary] | ||
|
||
COPY . . |
Oops, something went wrong.