Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
POSTGRES_USER=ayon
POSTGRES_PASSWORD=ayon
POSTGRES_DB=ayon

AYON_STACK_SERVER_TAG=latest
AYON_STACK_SERVER_PORT=5001

AYON_STACK_WORKER_TAG=latest
AYON_API_KEY=veryinsecurapikey
39 changes: 31 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ AYON_STACK_SETTINGS_FILE ?= settings/template.json
AYON_STACK_SERVER_NAME ?= ynput/ayon
AYON_STACK_SERVER_TAG ?= latest

POSTGRES_USER ?= ayon
POSTGRES_PASSWORD ?= ayon
POSTGRES_DB ?= ayon
#
# Variables
#
Expand All @@ -35,6 +38,8 @@ default:
@echo " demo Create demo projects based on settings in demo directory"
@echo " dump Use 'make dump projectname=<projectname>' to backup a project"
@echo " restore Use 'make restore projectname=<projectname>' to restore a project from previous dump"
@echo " dump-entire Use 'make dump-entire targetname=<targetname>' to backup the entire database, targetname is optional, no targetname uses 'backup_TIMESTAMP.sql', '_TIMESTAMP.sql' is always appended, targetname=test.sql == test_TIMESTAMP.sql"
@echo " restore-entire Use 'make restore-entire targetfilename=<targetfilename>' to restore the entire database"
@echo ""
@echo "Development:"
@echo " backend Download / update backend"
Expand All @@ -58,7 +63,7 @@ endif
@docker compose exec $(SERVER_CONTAINER) ./reload.sh

dbshell:
@docker compose exec postgres psql -U ayon ayon
@docker compose exec -e PGPASSWORD=$(POSTGRES_PASSWORD) postgres psql -U $(POSTGRES_USER) -d $(POSTGRES_DB)

reload:
@docker compose exec $(SERVER_CONTAINER) ./reload.sh
Expand Down Expand Up @@ -86,23 +91,21 @@ dump:

@# Dump project data from public.projects table

docker compose exec -t postgres pg_dump --table=public.projects --column-inserts ayon -U ayon | \
docker compose exec -e PGPASSWORD=$(POSTGRES_PASSWORD) -T postgres pg_dump --table=public.projects --column-inserts -d $(POSTGRES_DB) -U $(POSTGRES_USER) | \
grep "^INSERT INTO" | grep \'$(projectname)\' >> dump.$(projectname).sql

@# Get all product types used in the project
@# and insert them into the product_types table
@# (if they don't exist yet)

docker compose exec postgres psql -U ayon ayon -Atc "SELECT DISTINCT(product_type) from project_$(projectname).products;" | \
docker compose exec -e PGPASSWORD=$(POSTGRES_PASSWORD) postgres psql -U $(POSTGRES_USER) -d $(POSTGRES_DB) -Atc "SELECT DISTINCT(product_type) from project_$(projectname).products;" | \
while read -r product_type; do \
echo "INSERT INTO public.product_types (name) VALUES ('$${product_type}') ON CONFLICT DO NOTHING;"; \
done >> dump.$(projectname).sql

@# Dump project schema (tables, views, etc.)

docker compose exec postgres pg_dump --schema=project_$(projectname) ayon -U ayon >> dump.$(projectname).sql


docker compose exec -e PGPASSWORD=$(POSTGRES_PASSWORD) postgres pg_dump --schema=project_$(projectname) -d $(POSTGRES_DB) -U $(POSTGRES_USER) >> dump.$(projectname).sql

restore:
@if [ -z "$(projectname)" ]; then \
Expand All @@ -114,8 +117,28 @@ restore:
echo "Error: Dump file dump.$(projectname).sql not found"; \
exit 1; \
fi
docker compose exec -T postgres psql -U ayon ayon < dump.$(projectname).sql

docker compose exec -e PGPASSWORD=$(POSTGRES_PASSWORD) -T postgres psql -U $(POSTGRES_USER) -d $(POSTGRES_DB) < dump.$(projectname).sql

dump-entire:
$(eval TIMESTAMP := $(shell date +%y%m%d%H%M))
$(eval CLEAN_NAME := $(if $(targetname),$(patsubst %.sql,%,$(targetname)),backup))
$(eval TARGET := $(CLEAN_NAME)_$(TIMESTAMP).sql)
@echo "Dumping entire database to $(TARGET)..."
@docker compose exec -e PGPASSWORD=$(POSTGRES_PASSWORD) -T postgres pg_dump -U $(POSTGRES_USER) -d $(POSTGRES_DB) > $(TARGET)
@echo "Done."

restore-entire:
@if [ -z "$(targetfilename)" ]; then \
echo "Error: targetfilename is required. Usage: make restore-entire targetfilename=<file.sql>"; \
exit 1; \
fi
@if [ ! -f $(targetfilename) ]; then \
echo "Error: File $(targetfilename) not found"; \
exit 1; \
fi
@echo "Restoring entire database from $(targetfilename)..."
@docker compose exec -e PGPASSWORD=$(POSTGRES_PASSWORD) -T postgres psql -U $(POSTGRES_USER) -d $(POSTGRES_DB) < $(targetfilename)
@echo "Restore complete."
#
# The following targets are for development purposes only.
#
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.worker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ services:
- "/var/run/docker.sock:/var/run/docker.sock"

environment:
- "AYON_API_KEY=${AYON_API_KEY-veryinsecurapikey}"
- "AYON_SERVER_URL=${AYON_SERVER_URL-http://server:5000}"
- "AYON_API_KEY=${AYON_API_KEY:-veryinsecurapikey}"
- "AYON_SERVER_URL=${AYON_SERVER_URL:-http://server:5000}"
8 changes: 5 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ services:
expose: [5432]

volumes:
# comment out the following line on Windows
- "/etc/localtime:/etc/localtime:ro"

- "db:/var/lib/postgresql/data"

environment:
- "POSTGRES_USER=ayon"
- "POSTGRES_PASSWORD=ayon"
- "POSTGRES_DB=ayon"
- "POSTGRES_USER=${POSTGRES_USER:-ayon}"
- "POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-ayon}"
- "POSTGRES_DB=${POSTGRES_DB:-ayon}"

redis:
image: redis:alpine
Expand Down
Loading