Skip to content

Commit 4088ad9

Browse files
authored
Merge pull request #662 from PokeAPI/compose
2 parents c3e602d + 5754222 commit 4088ad9

File tree

162 files changed

+720
-662
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

162 files changed

+720
-662
lines changed

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ docker_config = --settings=config.docker-compose
44
HASURA_GRAPHQL_ADMIN_SECRET=pokemon
55

66
.PHONY: help
7-
.SILENT:
7+
.SILENT:
88

99
help:
1010
@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
6767
docker-down: # (Docker) Stop and removes containers and networks
6868
docker-compose down
6969

70+
docker-prod:
71+
docker-compose -f docker-compose.yml -f Resources/compose/docker-compose-prod-graphql.yml up -d
72+
7073
docker-setup: docker-up docker-migrate docker-build-db # (Docker) Start services, prepare the latest DB schema, populate the DB
7174

7275
format: # Format the source code
@@ -114,4 +117,4 @@ k8s-build-db: # (k8s) Build the database
114117
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'
115118

116119
k8s-delete: # (k8s) Delete pokeapi namespace
117-
kubectl delete namespace pokeapi
120+
kubectl delete namespace pokeapi

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ When you start PokéAPI with the above docker-compose setup, an [Hasura Engine](
9696

9797
```sh
9898
# hasura cli needs to be installed and available in your $PATH: https://hasura.io/docs/latest/graphql/core/hasura-cli/install-hasura-cli.html
99-
# hasura cli's version has to be v2.0.0-alpha.5
99+
# hasura cli's version has to be v2.0.8
100100
make hasura-apply
101101
```
102102

Resources/compose/docker-compose-prod-graphql.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ services:
44
environment:
55
POSTGRES_PASSWORD: "${POSTGRES_PASSWORD}"
66
POSTGRES_USER: "${POSTGRES_USER}"
7-
7+
88
app:
99
env_file: .env
1010

@@ -13,19 +13,24 @@ services:
1313
- graphiql:/public-console:ro
1414

1515
graphql-engine:
16+
cpus: 0.7
17+
memswap_limit: 3g
18+
mem_limit: 700m
1619
environment:
1720
HASURA_GRAPHQL_DATABASE_URL: "postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB:-pokeapi}"
1821
HASURA_GRAPHQL_ADMIN_SECRET: "${HASURA_GRAPHQL_ADMIN_SECRET}"
22+
HASURA_GRAPHQL_SCHEMA_SYNC_POLL_INTERVAL: 0
23+
HASURA_GRAPHQL_EVENTS_HTTP_POOL_SIZE: 10
1924

2025
graphiql:
2126
image: pokeapi/graphiql:1.0.1
2227
command: sh -c 'cp -a /app/static/. /transfer/ && tail -f /etc/passwd'
2328
volumes:
2429
- graphiql:/transfer
25-
depends_on:
30+
depends_on:
2631
- graphql-engine
2732

28-
volumes:
33+
volumes:
2934
graphiql:
3035

31-
# docker-compose -f docker-compose.yml -f Resources/compose/docker-compose-graphql.yml up
36+
# docker-compose -f docker-compose.yml -f Resources/compose/docker-compose-prod-graphql.yml up -d

Resources/k8s/kustomize/base/jobs/load-graphql.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ spec:
3030
- apt-get update &&
3131
apt-get install -y git curl &&
3232
curl -L https://github.com/hasura/graphql-engine/raw/stable/cli/get.sh | bash &&
33-
hasura update-cli --version v2.0.0-alpha.5 &&
33+
hasura update-cli --version v2.0.8 &&
3434
git clone https://github.com/PokeAPI/pokeapi.git &&
3535
cd pokeapi &&
3636
git checkout staging &&

Resources/nginx/nginx.conf

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
worker_processes 2;
1+
worker_processes 1;
22

33
events {
4-
worker_connections 4096;
4+
worker_connections 1024;
55
multi_accept on; # accept each connection as soon as you can
66
accept_mutex off;
77
use epoll;
@@ -24,21 +24,18 @@ http {
2424
tcp_nodelay on;
2525

2626
keepalive_timeout 5;
27-
27+
2828
gzip on;
2929
gzip_disable "msi6";
3030
gzip_vary on;
3131
gzip_proxied any;
32-
gzip_comp_level 6;
32+
gzip_comp_level 4;
3333
gzip_buffers 16 8k;
3434
gzip_http_version 1.1;
3535
gzip_min_length 256;
3636
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;
3737

38-
upstream pokeapi_upstream {
39-
# 'app' is the Django container name in Docker
40-
server app:80 fail_timeout=0;
41-
}
38+
resolver 127.0.0.11 valid=30s;
4239

4340
upstream graphql_upstream {
4441
server graphql-engine:8080 fail_timeout=0;
@@ -57,6 +54,7 @@ http {
5754

5855
limit_req_zone $limit_key zone=graphqlDefaultLimit:50m rate=1r/m;
5956
limit_conn_zone $binary_remote_addr zone=addr:20m;
57+
proxy_cache_path /tmp/cache levels=1:2 keys_zone=small:40m inactive=10d max_size=2g use_temp_path=off;
6058

6159
server {
6260
listen 80 deferred;
@@ -91,11 +89,18 @@ http {
9189
}
9290

9391
location /graphql/v1beta {
92+
# proxy_cache small;
93+
# proxy_cache_valid 200 10d;
94+
# proxy_cache_valid any 0;
95+
# proxy_cache_methods POST;
96+
# proxy_cache_key "$request_method$request_uri$request_body";
9497
limit_req zone=graphqlDefaultLimit burst=100 nodelay;
9598
limit_req_status 429;
96-
expires 1m; # client-side caching, one minute for each API resource
99+
expires 30m; # client-side caching, one minute for each API resource
97100
add_header Cache-Control "public";
98101
add_header Pragma public;
102+
# add_header X-Proxy-Cache $upstream_cache_status;
103+
# add_header X-Cache-Date $upstream_http_date;
99104
proxy_http_version 1.1;
100105
proxy_set_header Upgrade $http_upgrade;
101106
proxy_set_header Connection "upgrade";
@@ -105,7 +110,7 @@ http {
105110
proxy_redirect off;
106111
proxy_pass http://graphql_upstream/v1/graphql;
107112
}
108-
113+
109114
location /api/ {
110115
expires 1m; # client-side caching, one minute for each API resource
111116
add_header Cache-Control "public";
@@ -114,15 +119,12 @@ http {
114119
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
115120
proxy_set_header Host $http_host;
116121
proxy_redirect off;
117-
proxy_pass http://pokeapi_upstream;
122+
set $upstream app;
123+
proxy_pass http://$upstream:80;
118124
}
119125

120126
location / {
121-
proxy_set_header X-Real-IP $remote_addr;
122-
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
123-
proxy_set_header Host $http_host;
124-
proxy_redirect off;
125-
proxy_pass http://pokeapi_upstream;
127+
return 404;
126128
}
127129
}
128130
}

docker-compose-dev.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: '2.4'
2+
3+
services:
4+
app:
5+
build:
6+
context: .
7+
dockerfile: ./Resources/docker/app/Dockerfile
8+
9+
# # docker-compose -f docker-compose.yml -f Resources/compose/docker-compose-dev.yml up -d

docker-compose.yml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ services:
1717
restart: always
1818

1919
app:
20-
build:
21-
context: .
22-
dockerfile: ./Resources/docker/app/Dockerfile
20+
image: pokeapi/pokeapi:master
2321
user: ${RUN_AS:-pokeapi}
2422
environment:
2523
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-pokemon}
@@ -45,13 +43,9 @@ services:
4543
volumes:
4644
- ./Resources/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
4745
- ./Resources/nginx/ssl:/ssl:ro
48-
volumes_from:
49-
- app:ro
50-
links:
51-
- app
52-
46+
- graphql_cache:/tmp/cache
5347
graphql-engine:
54-
image: hasura/graphql-engine:v2.0.0-alpha.5
48+
image: hasura/graphql-engine:v2.0.8
5549
ports:
5650
- "8080:8080"
5751
depends_on:
@@ -61,6 +55,7 @@ services:
6155
HASURA_GRAPHQL_DATABASE_URL: postgres://${POSTGRES_USER:-ash}:${POSTGRES_PASSWORD:-pokemon}@db:5432/${POSTGRES_DB:-pokeapi}
6256
HASURA_GRAPHQL_ENABLE_CONSOLE: "true"
6357
HASURA_GRAPHQL_DEV_MODE: "false"
58+
HASURA_GRAPHQL_LOG_LEVEL: "warn"
6459
HASURA_GRAPHQL_ENABLED_LOG_TYPES: startup, http-log, webhook-log, websocket-log, query-log
6560
HASURA_GRAPHQL_ADMIN_SECRET: ${HASURA_GRAPHQL_ADMIN_SECRET:-pokemon}
6661
HASURA_GRAPHQL_UNAUTHORIZED_ROLE: anon
@@ -70,3 +65,4 @@ services:
7065
volumes:
7166
pg_data:
7267
redis_data:
68+
graphql_cache:

graphql/metadata/actions.graphql

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +0,0 @@
1-
2-

graphql/metadata/databases/databases.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
connection_info:
55
database_url:
66
from_env: HASURA_GRAPHQL_DATABASE_URL
7+
isolation_level: read-committed
78
pool_settings:
8-
idle_timeout: 180
9-
max_connections: 50
9+
idle_timeout: 20
10+
max_connections: 10
1011
retries: 1
12+
pool_timeout: 60
13+
connection_lifetime: 60
14+
use_prepared_statements: false
1115
tables: "!include default/tables/tables.yaml"
12-
functions: "!include default/functions/functions.yaml"

0 commit comments

Comments
 (0)