From 0708cbe486bebd06f67c666d60ff48ce3648bc17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Mel=C3=A9?= Date: Sun, 5 May 2024 09:45:07 +0100 Subject: [PATCH] added docker compose to all chapters --- Chapter01/Dockerfile | 16 +++++ Chapter01/do.sh | 113 +++++++++++++++++++++++++++++++++++ Chapter01/docker-compose.yml | 17 ++++++ Chapter02/Dockerfile | 16 +++++ Chapter02/do.sh | 113 +++++++++++++++++++++++++++++++++++ Chapter02/docker-compose.yml | 19 ++++++ Chapter03/Dockerfile | 17 ++++++ Chapter03/do.sh | 113 +++++++++++++++++++++++++++++++++++ Chapter03/docker-compose.yml | 37 ++++++++++++ Chapter04/Dockerfile | 17 ++++++ Chapter04/do.sh | 113 +++++++++++++++++++++++++++++++++++ Chapter04/docker-compose.yml | 17 ++++++ Chapter05/Dockerfile | 17 ++++++ Chapter05/do.sh | 113 +++++++++++++++++++++++++++++++++++ Chapter05/docker-compose.yml | 17 ++++++ Chapter06/Dockerfile | 17 ++++++ Chapter06/do.sh | 113 +++++++++++++++++++++++++++++++++++ Chapter06/docker-compose.yml | 17 ++++++ Chapter07/Dockerfile | 17 ++++++ Chapter07/do.sh | 113 +++++++++++++++++++++++++++++++++++ Chapter07/docker-compose.yml | 24 ++++++++ Chapter08/Dockerfile | 17 ++++++ Chapter08/do.sh | 113 +++++++++++++++++++++++++++++++++++ Chapter08/docker-compose.yml | 17 ++++++ Chapter09/Dockerfile | 21 +++++++ Chapter09/do.sh | 113 +++++++++++++++++++++++++++++++++++ Chapter09/docker-compose.yml | 21 +++++++ Chapter10/Dockerfile | 21 +++++++ Chapter10/do.sh | 113 +++++++++++++++++++++++++++++++++++ Chapter10/docker-compose.yml | 21 +++++++ Chapter11/Dockerfile | 21 +++++++ Chapter11/do.sh | 113 +++++++++++++++++++++++++++++++++++ Chapter11/docker-compose.yml | 26 ++++++++ Chapter12/Dockerfile | 17 ++++++ Chapter12/do.sh | 113 +++++++++++++++++++++++++++++++++++ Chapter12/docker-compose.yml | 17 ++++++ Chapter13/Dockerfile | 17 ++++++ Chapter13/do.sh | 113 +++++++++++++++++++++++++++++++++++ Chapter13/docker-compose.yml | 17 ++++++ Chapter14/Dockerfile | 17 ++++++ Chapter14/do.sh | 113 +++++++++++++++++++++++++++++++++++ Chapter14/docker-compose.yml | 22 +++++++ Chapter15/Dockerfile | 17 ++++++ Chapter15/do.sh | 113 +++++++++++++++++++++++++++++++++++ Chapter15/docker-compose.yml | 22 +++++++ Chapter16/Dockerfile | 17 ++++++ Chapter16/do.sh | 113 +++++++++++++++++++++++++++++++++++ Chapter16/docker-compose.yml | 22 +++++++ 48 files changed, 2423 insertions(+) create mode 100644 Chapter01/Dockerfile create mode 100755 Chapter01/do.sh create mode 100644 Chapter01/docker-compose.yml create mode 100644 Chapter02/Dockerfile create mode 100755 Chapter02/do.sh create mode 100644 Chapter02/docker-compose.yml create mode 100644 Chapter03/Dockerfile create mode 100755 Chapter03/do.sh create mode 100644 Chapter03/docker-compose.yml create mode 100644 Chapter04/Dockerfile create mode 100755 Chapter04/do.sh create mode 100644 Chapter04/docker-compose.yml create mode 100644 Chapter05/Dockerfile create mode 100755 Chapter05/do.sh create mode 100644 Chapter05/docker-compose.yml create mode 100644 Chapter06/Dockerfile create mode 100755 Chapter06/do.sh create mode 100644 Chapter06/docker-compose.yml create mode 100644 Chapter07/Dockerfile create mode 100755 Chapter07/do.sh create mode 100644 Chapter07/docker-compose.yml create mode 100644 Chapter08/Dockerfile create mode 100755 Chapter08/do.sh create mode 100644 Chapter08/docker-compose.yml create mode 100644 Chapter09/Dockerfile create mode 100755 Chapter09/do.sh create mode 100644 Chapter09/docker-compose.yml create mode 100644 Chapter10/Dockerfile create mode 100755 Chapter10/do.sh create mode 100644 Chapter10/docker-compose.yml create mode 100644 Chapter11/Dockerfile create mode 100755 Chapter11/do.sh create mode 100644 Chapter11/docker-compose.yml create mode 100644 Chapter12/Dockerfile create mode 100755 Chapter12/do.sh create mode 100644 Chapter12/docker-compose.yml create mode 100644 Chapter13/Dockerfile create mode 100755 Chapter13/do.sh create mode 100644 Chapter13/docker-compose.yml create mode 100644 Chapter14/Dockerfile create mode 100755 Chapter14/do.sh create mode 100644 Chapter14/docker-compose.yml create mode 100644 Chapter15/Dockerfile create mode 100755 Chapter15/do.sh create mode 100644 Chapter15/docker-compose.yml create mode 100644 Chapter16/Dockerfile create mode 100755 Chapter16/do.sh create mode 100644 Chapter16/docker-compose.yml diff --git a/Chapter01/Dockerfile b/Chapter01/Dockerfile new file mode 100644 index 0000000..1e340c9 --- /dev/null +++ b/Chapter01/Dockerfile @@ -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 . . \ No newline at end of file diff --git a/Chapter01/do.sh b/Chapter01/do.sh new file mode 100755 index 0000000..5426b84 --- /dev/null +++ b/Chapter01/do.sh @@ -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 <] + + Builds all the images (or the ones specified). + + + ${BOLD}exec${NORMAL} [] + + 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} [] + + Apply any unapplied django migrations + + ${BOLD}makemigrations${NORMAL} [] + + 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} [] + + Start the django server (and dependent services) + You can pass `-d` for running detached. + + ${BOLD}stop${NORMAL} [] + + Stop the django server (and dependent services) + +USAGE +} + +if [ "$1" == "" ]; then + _usage +fi + +$* diff --git a/Chapter01/docker-compose.yml b/Chapter01/docker-compose.yml new file mode 100644 index 0000000..ac2f472 --- /dev/null +++ b/Chapter01/docker-compose.yml @@ -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 \ No newline at end of file diff --git a/Chapter02/Dockerfile b/Chapter02/Dockerfile new file mode 100644 index 0000000..1e340c9 --- /dev/null +++ b/Chapter02/Dockerfile @@ -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 . . \ No newline at end of file diff --git a/Chapter02/do.sh b/Chapter02/do.sh new file mode 100755 index 0000000..5426b84 --- /dev/null +++ b/Chapter02/do.sh @@ -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 <] + + Builds all the images (or the ones specified). + + + ${BOLD}exec${NORMAL} [] + + 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} [] + + Apply any unapplied django migrations + + ${BOLD}makemigrations${NORMAL} [] + + 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} [] + + Start the django server (and dependent services) + You can pass `-d` for running detached. + + ${BOLD}stop${NORMAL} [] + + Stop the django server (and dependent services) + +USAGE +} + +if [ "$1" == "" ]; then + _usage +fi + +$* diff --git a/Chapter02/docker-compose.yml b/Chapter02/docker-compose.yml new file mode 100644 index 0000000..3674dd1 --- /dev/null +++ b/Chapter02/docker-compose.yml @@ -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 \ No newline at end of file diff --git a/Chapter03/Dockerfile b/Chapter03/Dockerfile new file mode 100644 index 0000000..9856e59 --- /dev/null +++ b/Chapter03/Dockerfile @@ -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 . . \ No newline at end of file diff --git a/Chapter03/do.sh b/Chapter03/do.sh new file mode 100755 index 0000000..5426b84 --- /dev/null +++ b/Chapter03/do.sh @@ -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 <] + + Builds all the images (or the ones specified). + + + ${BOLD}exec${NORMAL} [] + + 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} [] + + Apply any unapplied django migrations + + ${BOLD}makemigrations${NORMAL} [] + + 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} [] + + Start the django server (and dependent services) + You can pass `-d` for running detached. + + ${BOLD}stop${NORMAL} [] + + Stop the django server (and dependent services) + +USAGE +} + +if [ "$1" == "" ]; then + _usage +fi + +$* diff --git a/Chapter03/docker-compose.yml b/Chapter03/docker-compose.yml new file mode 100644 index 0000000..06f4f79 --- /dev/null +++ b/Chapter03/docker-compose.yml @@ -0,0 +1,37 @@ +services: + web: + build: . + environment: + EMAIL_HOST_USER: 'your_account@gmail.com' + EMAIL_HOST_PASSWORD: 'xxxxxxxxxxxx' + DEFAULT_FROM_EMAIL: 'My Blog ' + DB_HOST: 'db' + DB_USER: 'postgres' + DB_PASSWORD: 'postgres' + DB_NAME: 'postgres' + volumes: + - .:/code + web_migrate: + extends: + service: web + command: python /code/mysite/manage.py migrate + depends_on: + - db + web_run: + extends: + service: web + command: python /code/mysite/manage.py runserver 0.0.0.0:8000 + ports: + - "8000:8000" + depends_on: + - db + - web_migrate + db: + image: postgres:16.2 + restart: always + volumes: + - ./data/db:/var/lib/postgresql/data + environment: + - POSTGRES_DB=postgres + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres \ No newline at end of file diff --git a/Chapter04/Dockerfile b/Chapter04/Dockerfile new file mode 100644 index 0000000..9856e59 --- /dev/null +++ b/Chapter04/Dockerfile @@ -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 . . \ No newline at end of file diff --git a/Chapter04/do.sh b/Chapter04/do.sh new file mode 100755 index 0000000..be7d85e --- /dev/null +++ b/Chapter04/do.sh @@ -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/bookmarks web_run /bin/bash +} + +migrate() { + _requires web_run + exec -w /code/bookmarks web_run ./manage.py migrate "$@" +} + +makemigrations() { + _requires web_run + exec -w /code/bookmarks web_run python manage.py makemigrations "$@" +} + +check() { + _requires web_run + exec -w /code/bookmarks web_run ./manage.py check +} + +exec() { + $DOCKER_COMPOSE exec -e COLUMNS -e LINES "$@" +} + +_usage() { + cat <] + + Builds all the images (or the ones specified). + + + ${BOLD}exec${NORMAL} [] + + 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} [] + + Apply any unapplied django migrations + + ${BOLD}makemigrations${NORMAL} [] + + 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} [] + + Start the django server (and dependent services) + You can pass `-d` for running detached. + + ${BOLD}stop${NORMAL} [] + + Stop the django server (and dependent services) + +USAGE +} + +if [ "$1" == "" ]; then + _usage +fi + +$* diff --git a/Chapter04/docker-compose.yml b/Chapter04/docker-compose.yml new file mode 100644 index 0000000..f805eeb --- /dev/null +++ b/Chapter04/docker-compose.yml @@ -0,0 +1,17 @@ +services: + web: + build: . + volumes: + - .:/code + web_migrate: + extends: + service: web + command: python /code/bookmarks/manage.py migrate + web_run: + extends: + service: web + command: python /code/bookmarks/manage.py runserver 0.0.0.0:8000 + ports: + - "8000:8000" + depends_on: + - web_migrate diff --git a/Chapter05/Dockerfile b/Chapter05/Dockerfile new file mode 100644 index 0000000..9856e59 --- /dev/null +++ b/Chapter05/Dockerfile @@ -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 . . \ No newline at end of file diff --git a/Chapter05/do.sh b/Chapter05/do.sh new file mode 100755 index 0000000..be7d85e --- /dev/null +++ b/Chapter05/do.sh @@ -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/bookmarks web_run /bin/bash +} + +migrate() { + _requires web_run + exec -w /code/bookmarks web_run ./manage.py migrate "$@" +} + +makemigrations() { + _requires web_run + exec -w /code/bookmarks web_run python manage.py makemigrations "$@" +} + +check() { + _requires web_run + exec -w /code/bookmarks web_run ./manage.py check +} + +exec() { + $DOCKER_COMPOSE exec -e COLUMNS -e LINES "$@" +} + +_usage() { + cat <] + + Builds all the images (or the ones specified). + + + ${BOLD}exec${NORMAL} [] + + 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} [] + + Apply any unapplied django migrations + + ${BOLD}makemigrations${NORMAL} [] + + 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} [] + + Start the django server (and dependent services) + You can pass `-d` for running detached. + + ${BOLD}stop${NORMAL} [] + + Stop the django server (and dependent services) + +USAGE +} + +if [ "$1" == "" ]; then + _usage +fi + +$* diff --git a/Chapter05/docker-compose.yml b/Chapter05/docker-compose.yml new file mode 100644 index 0000000..73023aa --- /dev/null +++ b/Chapter05/docker-compose.yml @@ -0,0 +1,17 @@ +services: + web: + build: . + volumes: + - .:/code + web_migrate: + extends: + service: web + command: python /code/bookmarks/manage.py migrate + web_run: + extends: + service: web + command: python /code/bookmarks/manage.py runserver 0.0.0.0:8000 + ports: + - "8000:8000" + depends_on: + - web_migrate \ No newline at end of file diff --git a/Chapter06/Dockerfile b/Chapter06/Dockerfile new file mode 100644 index 0000000..9856e59 --- /dev/null +++ b/Chapter06/Dockerfile @@ -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 . . \ No newline at end of file diff --git a/Chapter06/do.sh b/Chapter06/do.sh new file mode 100755 index 0000000..be7d85e --- /dev/null +++ b/Chapter06/do.sh @@ -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/bookmarks web_run /bin/bash +} + +migrate() { + _requires web_run + exec -w /code/bookmarks web_run ./manage.py migrate "$@" +} + +makemigrations() { + _requires web_run + exec -w /code/bookmarks web_run python manage.py makemigrations "$@" +} + +check() { + _requires web_run + exec -w /code/bookmarks web_run ./manage.py check +} + +exec() { + $DOCKER_COMPOSE exec -e COLUMNS -e LINES "$@" +} + +_usage() { + cat <] + + Builds all the images (or the ones specified). + + + ${BOLD}exec${NORMAL} [] + + 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} [] + + Apply any unapplied django migrations + + ${BOLD}makemigrations${NORMAL} [] + + 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} [] + + Start the django server (and dependent services) + You can pass `-d` for running detached. + + ${BOLD}stop${NORMAL} [] + + Stop the django server (and dependent services) + +USAGE +} + +if [ "$1" == "" ]; then + _usage +fi + +$* diff --git a/Chapter06/docker-compose.yml b/Chapter06/docker-compose.yml new file mode 100644 index 0000000..f805eeb --- /dev/null +++ b/Chapter06/docker-compose.yml @@ -0,0 +1,17 @@ +services: + web: + build: . + volumes: + - .:/code + web_migrate: + extends: + service: web + command: python /code/bookmarks/manage.py migrate + web_run: + extends: + service: web + command: python /code/bookmarks/manage.py runserver 0.0.0.0:8000 + ports: + - "8000:8000" + depends_on: + - web_migrate diff --git a/Chapter07/Dockerfile b/Chapter07/Dockerfile new file mode 100644 index 0000000..9856e59 --- /dev/null +++ b/Chapter07/Dockerfile @@ -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 . . \ No newline at end of file diff --git a/Chapter07/do.sh b/Chapter07/do.sh new file mode 100755 index 0000000..be7d85e --- /dev/null +++ b/Chapter07/do.sh @@ -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/bookmarks web_run /bin/bash +} + +migrate() { + _requires web_run + exec -w /code/bookmarks web_run ./manage.py migrate "$@" +} + +makemigrations() { + _requires web_run + exec -w /code/bookmarks web_run python manage.py makemigrations "$@" +} + +check() { + _requires web_run + exec -w /code/bookmarks web_run ./manage.py check +} + +exec() { + $DOCKER_COMPOSE exec -e COLUMNS -e LINES "$@" +} + +_usage() { + cat <] + + Builds all the images (or the ones specified). + + + ${BOLD}exec${NORMAL} [] + + 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} [] + + Apply any unapplied django migrations + + ${BOLD}makemigrations${NORMAL} [] + + 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} [] + + Start the django server (and dependent services) + You can pass `-d` for running detached. + + ${BOLD}stop${NORMAL} [] + + Stop the django server (and dependent services) + +USAGE +} + +if [ "$1" == "" ]; then + _usage +fi + +$* diff --git a/Chapter07/docker-compose.yml b/Chapter07/docker-compose.yml new file mode 100644 index 0000000..76933ea --- /dev/null +++ b/Chapter07/docker-compose.yml @@ -0,0 +1,24 @@ +services: + web: + build: . + env_file: + - .env + volumes: + - .:/code + web_migrate: + extends: + service: web + command: python /code/bookmarks/manage.py migrate + web_run: + extends: + service: web + command: python /code/bookmarks/manage.py runserver 0.0.0.0:8000 + ports: + - "8000:8000" + depends_on: + - web_migrate + cache: + image: redis:7.2.4 + restart: always + volumes: + - ./data/cache:/data diff --git a/Chapter08/Dockerfile b/Chapter08/Dockerfile new file mode 100644 index 0000000..9856e59 --- /dev/null +++ b/Chapter08/Dockerfile @@ -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 . . \ No newline at end of file diff --git a/Chapter08/do.sh b/Chapter08/do.sh new file mode 100755 index 0000000..1e2c3a5 --- /dev/null +++ b/Chapter08/do.sh @@ -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/myshop web_run /bin/bash +} + +migrate() { + _requires web_run + exec -w /code/myshop web_run ./manage.py migrate "$@" +} + +makemigrations() { + _requires web_run + exec -w /code/myshop web_run python manage.py makemigrations "$@" +} + +check() { + _requires web_run + exec -w /code/myshop web_run ./manage.py check +} + +exec() { + $DOCKER_COMPOSE exec -e COLUMNS -e LINES "$@" +} + +_usage() { + cat <] + + Builds all the images (or the ones specified). + + + ${BOLD}exec${NORMAL} [] + + 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} [] + + Apply any unapplied django migrations + + ${BOLD}makemigrations${NORMAL} [] + + 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} [] + + Start the django server (and dependent services) + You can pass `-d` for running detached. + + ${BOLD}stop${NORMAL} [] + + Stop the django server (and dependent services) + +USAGE +} + +if [ "$1" == "" ]; then + _usage +fi + +$* diff --git a/Chapter08/docker-compose.yml b/Chapter08/docker-compose.yml new file mode 100644 index 0000000..2e7faa7 --- /dev/null +++ b/Chapter08/docker-compose.yml @@ -0,0 +1,17 @@ +services: + web: + build: . + volumes: + - .:/code + web_migrate: + extends: + service: web + command: python /code/myshop/manage.py migrate + web_run: + extends: + service: web + command: python /code/myshop/manage.py runserver 0.0.0.0:8000 + ports: + - "8000:8000" + depends_on: + - web_migrate diff --git a/Chapter09/Dockerfile b/Chapter09/Dockerfile new file mode 100644 index 0000000..46b5b47 --- /dev/null +++ b/Chapter09/Dockerfile @@ -0,0 +1,21 @@ +FROM python:3.12.3-slim + +RUN apt-get update -qq \ + && apt-get install -y build-essential python3-dev \ + python3-pip python3-setuptools python3-wheel python3-cffi \ + libcairo2 libpango-1.0-0 libpangocairo-1.0-0 \ + libgdk-pixbuf2.0-0 libffi-dev shared-mime-info \ + && 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 . . \ No newline at end of file diff --git a/Chapter09/do.sh b/Chapter09/do.sh new file mode 100755 index 0000000..1e2c3a5 --- /dev/null +++ b/Chapter09/do.sh @@ -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/myshop web_run /bin/bash +} + +migrate() { + _requires web_run + exec -w /code/myshop web_run ./manage.py migrate "$@" +} + +makemigrations() { + _requires web_run + exec -w /code/myshop web_run python manage.py makemigrations "$@" +} + +check() { + _requires web_run + exec -w /code/myshop web_run ./manage.py check +} + +exec() { + $DOCKER_COMPOSE exec -e COLUMNS -e LINES "$@" +} + +_usage() { + cat <] + + Builds all the images (or the ones specified). + + + ${BOLD}exec${NORMAL} [] + + 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} [] + + Apply any unapplied django migrations + + ${BOLD}makemigrations${NORMAL} [] + + 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} [] + + Start the django server (and dependent services) + You can pass `-d` for running detached. + + ${BOLD}stop${NORMAL} [] + + Stop the django server (and dependent services) + +USAGE +} + +if [ "$1" == "" ]; then + _usage +fi + +$* diff --git a/Chapter09/docker-compose.yml b/Chapter09/docker-compose.yml new file mode 100644 index 0000000..3ec890e --- /dev/null +++ b/Chapter09/docker-compose.yml @@ -0,0 +1,21 @@ +services: + web: + build: . + environment: + - STRIPE_PUBLISHABLE_KEY=key + - STRIPE_SECRET_KEY=secret + - STRIPE_WEBHOOK_SECRET=secret-hook + volumes: + - .:/code + web_migrate: + extends: + service: web + command: python /code/myshop/manage.py migrate + web_run: + extends: + service: web + command: python /code/myshop/manage.py runserver 0.0.0.0:8000 + ports: + - "8000:8000" + depends_on: + - web_migrate diff --git a/Chapter10/Dockerfile b/Chapter10/Dockerfile new file mode 100644 index 0000000..46b5b47 --- /dev/null +++ b/Chapter10/Dockerfile @@ -0,0 +1,21 @@ +FROM python:3.12.3-slim + +RUN apt-get update -qq \ + && apt-get install -y build-essential python3-dev \ + python3-pip python3-setuptools python3-wheel python3-cffi \ + libcairo2 libpango-1.0-0 libpangocairo-1.0-0 \ + libgdk-pixbuf2.0-0 libffi-dev shared-mime-info \ + && 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 . . \ No newline at end of file diff --git a/Chapter10/do.sh b/Chapter10/do.sh new file mode 100755 index 0000000..1e2c3a5 --- /dev/null +++ b/Chapter10/do.sh @@ -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/myshop web_run /bin/bash +} + +migrate() { + _requires web_run + exec -w /code/myshop web_run ./manage.py migrate "$@" +} + +makemigrations() { + _requires web_run + exec -w /code/myshop web_run python manage.py makemigrations "$@" +} + +check() { + _requires web_run + exec -w /code/myshop web_run ./manage.py check +} + +exec() { + $DOCKER_COMPOSE exec -e COLUMNS -e LINES "$@" +} + +_usage() { + cat <] + + Builds all the images (or the ones specified). + + + ${BOLD}exec${NORMAL} [] + + 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} [] + + Apply any unapplied django migrations + + ${BOLD}makemigrations${NORMAL} [] + + 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} [] + + Start the django server (and dependent services) + You can pass `-d` for running detached. + + ${BOLD}stop${NORMAL} [] + + Stop the django server (and dependent services) + +USAGE +} + +if [ "$1" == "" ]; then + _usage +fi + +$* diff --git a/Chapter10/docker-compose.yml b/Chapter10/docker-compose.yml new file mode 100644 index 0000000..3ec890e --- /dev/null +++ b/Chapter10/docker-compose.yml @@ -0,0 +1,21 @@ +services: + web: + build: . + environment: + - STRIPE_PUBLISHABLE_KEY=key + - STRIPE_SECRET_KEY=secret + - STRIPE_WEBHOOK_SECRET=secret-hook + volumes: + - .:/code + web_migrate: + extends: + service: web + command: python /code/myshop/manage.py migrate + web_run: + extends: + service: web + command: python /code/myshop/manage.py runserver 0.0.0.0:8000 + ports: + - "8000:8000" + depends_on: + - web_migrate diff --git a/Chapter11/Dockerfile b/Chapter11/Dockerfile new file mode 100644 index 0000000..46b5b47 --- /dev/null +++ b/Chapter11/Dockerfile @@ -0,0 +1,21 @@ +FROM python:3.12.3-slim + +RUN apt-get update -qq \ + && apt-get install -y build-essential python3-dev \ + python3-pip python3-setuptools python3-wheel python3-cffi \ + libcairo2 libpango-1.0-0 libpangocairo-1.0-0 \ + libgdk-pixbuf2.0-0 libffi-dev shared-mime-info \ + && 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 . . \ No newline at end of file diff --git a/Chapter11/do.sh b/Chapter11/do.sh new file mode 100755 index 0000000..1e2c3a5 --- /dev/null +++ b/Chapter11/do.sh @@ -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/myshop web_run /bin/bash +} + +migrate() { + _requires web_run + exec -w /code/myshop web_run ./manage.py migrate "$@" +} + +makemigrations() { + _requires web_run + exec -w /code/myshop web_run python manage.py makemigrations "$@" +} + +check() { + _requires web_run + exec -w /code/myshop web_run ./manage.py check +} + +exec() { + $DOCKER_COMPOSE exec -e COLUMNS -e LINES "$@" +} + +_usage() { + cat <] + + Builds all the images (or the ones specified). + + + ${BOLD}exec${NORMAL} [] + + 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} [] + + Apply any unapplied django migrations + + ${BOLD}makemigrations${NORMAL} [] + + 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} [] + + Start the django server (and dependent services) + You can pass `-d` for running detached. + + ${BOLD}stop${NORMAL} [] + + Stop the django server (and dependent services) + +USAGE +} + +if [ "$1" == "" ]; then + _usage +fi + +$* diff --git a/Chapter11/docker-compose.yml b/Chapter11/docker-compose.yml new file mode 100644 index 0000000..e9f44ad --- /dev/null +++ b/Chapter11/docker-compose.yml @@ -0,0 +1,26 @@ +services: + web: + build: . + environment: + - STRIPE_PUBLISHABLE_KEY=key + - STRIPE_SECRET_KEY=secret + - STRIPE_WEBHOOK_SECRET=secret-hook + volumes: + - .:/code + web_migrate: + extends: + service: web + command: python /code/myshop/manage.py migrate + web_run: + extends: + service: web + command: python /code/myshop/manage.py runserver 0.0.0.0:8000 + ports: + - "8000:8000" + depends_on: + - web_migrate + cache: + image: redis:7.2.4 + restart: always + volumes: + - ./data/cache:/data diff --git a/Chapter12/Dockerfile b/Chapter12/Dockerfile new file mode 100644 index 0000000..9856e59 --- /dev/null +++ b/Chapter12/Dockerfile @@ -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 . . \ No newline at end of file diff --git a/Chapter12/do.sh b/Chapter12/do.sh new file mode 100755 index 0000000..f4d0340 --- /dev/null +++ b/Chapter12/do.sh @@ -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/educa web_run /bin/bash +} + +migrate() { + _requires web_run + exec -w /code/educa web_run ./manage.py migrate "$@" +} + +makemigrations() { + _requires web_run + exec -w /code/educa web_run python manage.py makemigrations "$@" +} + +check() { + _requires web_run + exec -w /code/educa web_run ./manage.py check +} + +exec() { + $DOCKER_COMPOSE exec -e COLUMNS -e LINES "$@" +} + +_usage() { + cat <] + + Builds all the images (or the ones specified). + + + ${BOLD}exec${NORMAL} [] + + 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} [] + + Apply any unapplied django migrations + + ${BOLD}makemigrations${NORMAL} [] + + 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} [] + + Start the django server (and dependent services) + You can pass `-d` for running detached. + + ${BOLD}stop${NORMAL} [] + + Stop the django server (and dependent services) + +USAGE +} + +if [ "$1" == "" ]; then + _usage +fi + +$* diff --git a/Chapter12/docker-compose.yml b/Chapter12/docker-compose.yml new file mode 100644 index 0000000..608ac23 --- /dev/null +++ b/Chapter12/docker-compose.yml @@ -0,0 +1,17 @@ +services: + web: + build: . + volumes: + - .:/code + web_migrate: + extends: + service: web + command: python /code/educa/manage.py migrate + web_run: + extends: + service: web + command: python /code/educa/manage.py runserver 0.0.0.0:8000 + ports: + - "8000:8000" + depends_on: + - web_migrate diff --git a/Chapter13/Dockerfile b/Chapter13/Dockerfile new file mode 100644 index 0000000..9856e59 --- /dev/null +++ b/Chapter13/Dockerfile @@ -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 . . \ No newline at end of file diff --git a/Chapter13/do.sh b/Chapter13/do.sh new file mode 100755 index 0000000..f4d0340 --- /dev/null +++ b/Chapter13/do.sh @@ -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/educa web_run /bin/bash +} + +migrate() { + _requires web_run + exec -w /code/educa web_run ./manage.py migrate "$@" +} + +makemigrations() { + _requires web_run + exec -w /code/educa web_run python manage.py makemigrations "$@" +} + +check() { + _requires web_run + exec -w /code/educa web_run ./manage.py check +} + +exec() { + $DOCKER_COMPOSE exec -e COLUMNS -e LINES "$@" +} + +_usage() { + cat <] + + Builds all the images (or the ones specified). + + + ${BOLD}exec${NORMAL} [] + + 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} [] + + Apply any unapplied django migrations + + ${BOLD}makemigrations${NORMAL} [] + + 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} [] + + Start the django server (and dependent services) + You can pass `-d` for running detached. + + ${BOLD}stop${NORMAL} [] + + Stop the django server (and dependent services) + +USAGE +} + +if [ "$1" == "" ]; then + _usage +fi + +$* diff --git a/Chapter13/docker-compose.yml b/Chapter13/docker-compose.yml new file mode 100644 index 0000000..608ac23 --- /dev/null +++ b/Chapter13/docker-compose.yml @@ -0,0 +1,17 @@ +services: + web: + build: . + volumes: + - .:/code + web_migrate: + extends: + service: web + command: python /code/educa/manage.py migrate + web_run: + extends: + service: web + command: python /code/educa/manage.py runserver 0.0.0.0:8000 + ports: + - "8000:8000" + depends_on: + - web_migrate diff --git a/Chapter14/Dockerfile b/Chapter14/Dockerfile new file mode 100644 index 0000000..9856e59 --- /dev/null +++ b/Chapter14/Dockerfile @@ -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 . . \ No newline at end of file diff --git a/Chapter14/do.sh b/Chapter14/do.sh new file mode 100755 index 0000000..f4d0340 --- /dev/null +++ b/Chapter14/do.sh @@ -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/educa web_run /bin/bash +} + +migrate() { + _requires web_run + exec -w /code/educa web_run ./manage.py migrate "$@" +} + +makemigrations() { + _requires web_run + exec -w /code/educa web_run python manage.py makemigrations "$@" +} + +check() { + _requires web_run + exec -w /code/educa web_run ./manage.py check +} + +exec() { + $DOCKER_COMPOSE exec -e COLUMNS -e LINES "$@" +} + +_usage() { + cat <] + + Builds all the images (or the ones specified). + + + ${BOLD}exec${NORMAL} [] + + 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} [] + + Apply any unapplied django migrations + + ${BOLD}makemigrations${NORMAL} [] + + 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} [] + + Start the django server (and dependent services) + You can pass `-d` for running detached. + + ${BOLD}stop${NORMAL} [] + + Stop the django server (and dependent services) + +USAGE +} + +if [ "$1" == "" ]; then + _usage +fi + +$* diff --git a/Chapter14/docker-compose.yml b/Chapter14/docker-compose.yml new file mode 100644 index 0000000..8cc95bd --- /dev/null +++ b/Chapter14/docker-compose.yml @@ -0,0 +1,22 @@ +services: + web: + build: . + volumes: + - .:/code + web_migrate: + extends: + service: web + command: python /code/educa/manage.py migrate + web_run: + extends: + service: web + command: python /code/educa/manage.py runserver 0.0.0.0:8000 + ports: + - "8000:8000" + depends_on: + - web_migrate + cache: + image: redis:7.2.4 + restart: always + volumes: + - ./data/cache:/data diff --git a/Chapter15/Dockerfile b/Chapter15/Dockerfile new file mode 100644 index 0000000..9856e59 --- /dev/null +++ b/Chapter15/Dockerfile @@ -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 . . \ No newline at end of file diff --git a/Chapter15/do.sh b/Chapter15/do.sh new file mode 100755 index 0000000..f4d0340 --- /dev/null +++ b/Chapter15/do.sh @@ -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/educa web_run /bin/bash +} + +migrate() { + _requires web_run + exec -w /code/educa web_run ./manage.py migrate "$@" +} + +makemigrations() { + _requires web_run + exec -w /code/educa web_run python manage.py makemigrations "$@" +} + +check() { + _requires web_run + exec -w /code/educa web_run ./manage.py check +} + +exec() { + $DOCKER_COMPOSE exec -e COLUMNS -e LINES "$@" +} + +_usage() { + cat <] + + Builds all the images (or the ones specified). + + + ${BOLD}exec${NORMAL} [] + + 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} [] + + Apply any unapplied django migrations + + ${BOLD}makemigrations${NORMAL} [] + + 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} [] + + Start the django server (and dependent services) + You can pass `-d` for running detached. + + ${BOLD}stop${NORMAL} [] + + Stop the django server (and dependent services) + +USAGE +} + +if [ "$1" == "" ]; then + _usage +fi + +$* diff --git a/Chapter15/docker-compose.yml b/Chapter15/docker-compose.yml new file mode 100644 index 0000000..8cc95bd --- /dev/null +++ b/Chapter15/docker-compose.yml @@ -0,0 +1,22 @@ +services: + web: + build: . + volumes: + - .:/code + web_migrate: + extends: + service: web + command: python /code/educa/manage.py migrate + web_run: + extends: + service: web + command: python /code/educa/manage.py runserver 0.0.0.0:8000 + ports: + - "8000:8000" + depends_on: + - web_migrate + cache: + image: redis:7.2.4 + restart: always + volumes: + - ./data/cache:/data diff --git a/Chapter16/Dockerfile b/Chapter16/Dockerfile new file mode 100644 index 0000000..9856e59 --- /dev/null +++ b/Chapter16/Dockerfile @@ -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 . . \ No newline at end of file diff --git a/Chapter16/do.sh b/Chapter16/do.sh new file mode 100755 index 0000000..f4d0340 --- /dev/null +++ b/Chapter16/do.sh @@ -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/educa web_run /bin/bash +} + +migrate() { + _requires web_run + exec -w /code/educa web_run ./manage.py migrate "$@" +} + +makemigrations() { + _requires web_run + exec -w /code/educa web_run python manage.py makemigrations "$@" +} + +check() { + _requires web_run + exec -w /code/educa web_run ./manage.py check +} + +exec() { + $DOCKER_COMPOSE exec -e COLUMNS -e LINES "$@" +} + +_usage() { + cat <] + + Builds all the images (or the ones specified). + + + ${BOLD}exec${NORMAL} [] + + 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} [] + + Apply any unapplied django migrations + + ${BOLD}makemigrations${NORMAL} [] + + 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} [] + + Start the django server (and dependent services) + You can pass `-d` for running detached. + + ${BOLD}stop${NORMAL} [] + + Stop the django server (and dependent services) + +USAGE +} + +if [ "$1" == "" ]; then + _usage +fi + +$* diff --git a/Chapter16/docker-compose.yml b/Chapter16/docker-compose.yml new file mode 100644 index 0000000..8cc95bd --- /dev/null +++ b/Chapter16/docker-compose.yml @@ -0,0 +1,22 @@ +services: + web: + build: . + volumes: + - .:/code + web_migrate: + extends: + service: web + command: python /code/educa/manage.py migrate + web_run: + extends: + service: web + command: python /code/educa/manage.py runserver 0.0.0.0:8000 + ports: + - "8000:8000" + depends_on: + - web_migrate + cache: + image: redis:7.2.4 + restart: always + volumes: + - ./data/cache:/data