From 07f0eeff440b44560bb77aa9d9803f35e6c67eff Mon Sep 17 00:00:00 2001 From: JensDiemer Date: Sun, 22 Nov 2020 12:51:14 +0100 Subject: [PATCH] More generic deployment: rename "inventory" to "django" --- deployment/.env | 2 ++ deployment/.gitignore | 1 + deployment/Makefile | 26 +++++++++++++------------- deployment/README.creole | 10 +++++----- deployment/caddy/Caddyfile | 2 +- deployment/common.env | 1 - deployment/django/entrypoint.sh | 2 +- deployment/docker-compose.dev.yml | 2 +- deployment/docker-compose.yml | 6 ++++-- 9 files changed, 28 insertions(+), 24 deletions(-) create mode 100644 deployment/.env diff --git a/deployment/.env b/deployment/.env new file mode 100644 index 0000000..f4bc570 --- /dev/null +++ b/deployment/.env @@ -0,0 +1,2 @@ +PROJECT_NAME=pyinventory +PYTHON_PACKAGE_NAME=inventory diff --git a/deployment/.gitignore b/deployment/.gitignore index d2c6ad8..e11dd65 100644 --- a/deployment/.gitignore +++ b/deployment/.gitignore @@ -1,5 +1,6 @@ .* !.dockerignore +!.env !.gitignore poetry.lock diff --git a/deployment/Makefile b/deployment/Makefile index 10aba57..fd41f5b 100644 --- a/deployment/Makefile +++ b/deployment/Makefile @@ -4,7 +4,7 @@ all: help help: @echo -e '_________________________________________________________________' - @echo -e 'PyInventory - *deployment* Makefile\n' + @echo -e '*Deployment* Makefile\n' @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z0-9 -_]+:.*?## / {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST) check-poetry: @@ -68,12 +68,12 @@ init_postgres: ## Create postgres database ############################################################################## createsuperuser: ## Create super user - ./compose.sh exec inventory ./manage.sh createsuperuser + ./compose.sh exec django ./manage.sh createsuperuser ############################################################################## -shell_inventory: ## Go into bash shell in inventory container - ./compose.sh exec inventory /bin/bash +shell_django: ## Go into bash shell in django container + ./compose.sh exec django /bin/bash shell_postgres: ## Go into bash shell in postgres container ./compose.sh exec postgres /bin/bash @@ -94,8 +94,8 @@ logs: ## Display docker logs from all containers logs_postgres: ## Display docker logs from postgres container ./compose.sh logs --tail=500 --follow postgres -logs_inventory: ## Display docker logs from inventory container - ./compose.sh logs --tail=500 --follow inventory +logs_django: ## Display docker logs from django container + ./compose.sh logs --tail=500 --follow django logs_caddy: ## Display docker logs from caddy container ./compose.sh logs --tail=500 --follow caddy @@ -103,18 +103,18 @@ logs_caddy: ## Display docker logs from caddy container ############################################################################## dbbackup: ## Backup database - ./compose.sh exec inventory ./manage.sh dbbackup + ./compose.sh exec django ./manage.sh dbbackup dbrestore: ## Restore a database backup - ./compose.sh exec inventory ./manage.sh dbrestore + ./compose.sh exec django ./manage.sh dbrestore ############################################################################## restart: down up ## Restart all containers -upgrade_inventory: ## Upgrade "inventory" container and restart it +upgrade_django: ## Upgrade "django" container and restart it $(MAKE) build - ./compose.sh stop inventory + ./compose.sh stop django $(MAKE) up restart_caddy: ## Restart caddy container @@ -127,9 +127,9 @@ reload_caddy: ## Reload Caddy server ./compose.sh exec caddy caddy reload --config /etc/caddy/Caddyfile --adapter caddyfile $(MAKE) logs_caddy -reload_inventory: ## Reload server in "inventory" container - ./compose.sh exec inventory ./docker/kill_python.sh - ./compose.sh logs --tail=500 --follow inventory +reload_django: ## Reload server in "django" container + ./compose.sh exec django ./docker/kill_python.sh + ./compose.sh logs --tail=500 --follow django ############################################################################## diff --git a/deployment/README.creole b/deployment/README.creole index a566e94..7c292f2 100644 --- a/deployment/README.creole +++ b/deployment/README.creole @@ -102,7 +102,7 @@ install some base packages, e.g.: # Theses Makefile targets exists: ~/PyInventory/deployment$ make _________________________________________________________________ -PyInventory - *deployment* Makefile +*Deployment* Makefile install-poetry install or update poetry install install requirements to setup project @@ -113,21 +113,21 @@ prune Cleanup docker build Update docker container build init_postgres Create postgres database createsuperuser Create super user -shell_inventory Go into bash shell in inventory container +shell_django Go into bash shell in django container shell_postgres Go into bash shell in postgres container shell_caddy Go into bash shell in caddy container caddy_environ Prints the caddy environment logs Display docker logs from all containers logs_postgres Display docker logs from postgres container -logs_inventory Display docker logs from inventory container +logs_django Display docker logs from django container logs_caddy Display docker logs from caddy container dbbackup Backup database dbrestore Restore a database backup restart Restart all containers -upgrade_inventory Upgrade "inventory" container and restart it +upgrade_django Upgrade "django" container and restart it restart_caddy Restart caddy container reload_caddy Reload Caddy server -reload_inventory Reload server in "inventory" container +reload_django Reload server in "django" container }}} Install, e.g.: diff --git a/deployment/caddy/Caddyfile b/deployment/caddy/Caddyfile index 5335925..90ac1ca 100644 --- a/deployment/caddy/Caddyfile +++ b/deployment/caddy/Caddyfile @@ -23,6 +23,6 @@ Disallow: /" file_server /static/* { root /srv/ } - reverse_proxy inventory:8000 + reverse_proxy django:8000 } } diff --git a/deployment/common.env b/deployment/common.env index b2ba956..3c0d179 100644 --- a/deployment/common.env +++ b/deployment/common.env @@ -1,4 +1,3 @@ -DB_NAME=pyinventory DB_USER=postgres DB_PASS=postgres DB_HOST=postgres diff --git a/deployment/django/entrypoint.sh b/deployment/django/entrypoint.sh index 1622126..ef47bc8 100755 --- a/deployment/django/entrypoint.sh +++ b/deployment/django/entrypoint.sh @@ -26,7 +26,7 @@ if [ -d "/dist/" ] ; then else ( set -x - pip3 install -U "pyinventory>=0.5.0" + pip3 install -U "${PYTHON_PACKAGE_NAME}" ) fi ( diff --git a/deployment/docker-compose.dev.yml b/deployment/docker-compose.dev.yml index 29c70b3..28d427d 100644 --- a/deployment/docker-compose.dev.yml +++ b/deployment/docker-compose.dev.yml @@ -6,7 +6,7 @@ services: - HOSTNAME=localhost - LETSENCRYPT_EMAIL=internal - inventory: + django: environment: - DJANGO_SETTINGS_MODULE=docker_settings - HOSTNAME=localhost diff --git a/deployment/docker-compose.yml b/deployment/docker-compose.yml index ccf408a..bd0666a 100644 --- a/deployment/docker-compose.yml +++ b/deployment/docker-compose.yml @@ -16,18 +16,19 @@ services: - HOSTNAME=${HOSTNAME:-localhost} - LETSENCRYPT_EMAIL=${LETSENCRYPT_EMAIL:-internal} - inventory: + django: build: context: . dockerfile: Dockerfile restart: unless-stopped - hostname: inventory + hostname: django ports: - "8000" env_file: ./common.env environment: - DJANGO_SETTINGS_MODULE=docker_settings - HOSTNAME=${HOSTNAME:-localhost} + - DB_NAME=${PROJECT_NAME} links: - postgres:postgres depends_on: @@ -50,6 +51,7 @@ services: - "5432" env_file: ./common.env environment: + - DB_NAME=${PROJECT_NAME} - POSTGRES_HOST_AUTH_METHOD=trust volumes: - ./postgres/init-user-db.sh:/docker-entrypoint-initdb.d/init-user-db.sh:ro