diff --git a/Makefile b/Makefile index 97afba38..926b0cbe 100755 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ docker_config = --settings=config.docker-compose HASURA_GRAPHQL_ADMIN_SECRET=pokemon .PHONY: help -.SILENT: +.SILENT: help: @grep -E '^[a-zA-Z_-]+:.*?# .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?# "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' @@ -67,6 +67,9 @@ docker-stop: # (Docker) Stop containers docker-down: # (Docker) Stop and removes containers and networks docker-compose down +docker-prod: + docker-compose -f docker-compose.yml -f Resources/compose/docker-compose-prod-graphql.yml up -d + docker-setup: docker-up docker-migrate docker-build-db # (Docker) Start services, prepare the latest DB schema, populate the DB format: # Format the source code @@ -114,4 +117,4 @@ k8s-build-db: # (k8s) Build the database kubectl exec --namespace pokeapi deployment/pokeapi -- sh -c 'echo "from data.v2.build import build_all; build_all()" | python manage.py shell --settings=config.docker-compose' k8s-delete: # (k8s) Delete pokeapi namespace - kubectl delete namespace pokeapi \ No newline at end of file + kubectl delete namespace pokeapi diff --git a/Resources/compose/docker-compose-prod-graphql.yml b/Resources/compose/docker-compose-prod-graphql.yml index 4744ecc1..590893f5 100644 --- a/Resources/compose/docker-compose-prod-graphql.yml +++ b/Resources/compose/docker-compose-prod-graphql.yml @@ -13,6 +13,9 @@ services: - graphiql:/public-console:ro graphql-engine: + cpus: 0.7 + memswap_limit: 3g + mem_limit: 450m environment: HASURA_GRAPHQL_DATABASE_URL: "postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB:-pokeapi}" HASURA_GRAPHQL_ADMIN_SECRET: "${HASURA_GRAPHQL_ADMIN_SECRET}" diff --git a/Resources/nginx/nginx.conf b/Resources/nginx/nginx.conf index ff2e4a7f..ac334c61 100644 --- a/Resources/nginx/nginx.conf +++ b/Resources/nginx/nginx.conf @@ -24,7 +24,7 @@ http { tcp_nodelay on; keepalive_timeout 5; - + gzip on; gzip_disable "msi6"; gzip_vary on; @@ -35,10 +35,11 @@ http { gzip_min_length 256; gzip_types application/atom+xml application/geo+json application/javascript application/x-javascript application/json application/ld+json application/manifest+json application/rdf+xml application/rss+xml application/xhtml+xml application/xml font/eot font/otf font/ttf image/svg+xml text/css text/javascript text/plain text/xml; - #upstream pokeapi_upstream { - # 'app' is the Django container name in Docker - # server app:80 fail_timeout=0; - #} + resolver 127.0.0.11 valid=30s; + + upstream pokeapi_upstream { + server app:80 fail_timeout=0; + } upstream graphql_upstream { server graphql-engine:8080 fail_timeout=0; @@ -68,7 +69,7 @@ http { client_body_timeout 5s; client_header_timeout 5s; - limit_conn addr 15; + limit_conn addr 10; # Admin console location /graphql/admin/ { @@ -114,7 +115,17 @@ http { proxy_redirect off; proxy_pass http://graphql_upstream/v1/graphql; } - + + location /api/ { + expires 1m; # client-side caching, one minute for each API resource + add_header Cache-Control "public"; + add_header Pragma public; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $http_host; + proxy_redirect off; + proxy_pass http://pokeapi_upstream; + } location / { return 404; diff --git a/docker-compose.yml b/docker-compose.yml index e5b69c13..5d7aa872 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -46,9 +46,6 @@ services: graphql-engine: image: hasura/graphql-engine:v2.0.0-alpha.5 - cpus: 0.7 - memswap_limit: 3g - mem_limit: 450m ports: - "8080:8080" depends_on: