Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use compose V2 #1027

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
63bf517
refactor: use compose V2
Naramsim Feb 1, 2024
02baf0b
feat: :sparkles: Add pokemon cries
FallenDeity Feb 2, 2024
4828b93
style: Run black formatter on source
FallenDeity Feb 2, 2024
e0a877b
Updating MoveDetailSerializer to change $effect_chance to actual number
SKCwillie Feb 2, 2024
ccd4479
fixing a debugging print line
SKCwillie Feb 2, 2024
77b9741
replacing move_effect_prose.csv with original
SKCwillie Feb 2, 2024
8f9fd71
removing unnecessary line
SKCwillie Feb 4, 2024
12db174
that line was needed after all
SKCwillie Feb 4, 2024
d65c740
Mark indeedee and oinkologne as having gender differences as per http…
dhaber Feb 4, 2024
0572e1b
Merge branch 'master' into gender-differences
dhaber Feb 4, 2024
1b35b7d
Merge pull request #1032 from dhaber/gender-differences
Naramsim Feb 5, 2024
4bf4e67
Merge branch 'master' into issue1024
Naramsim Feb 7, 2024
6f0b800
Merge branch 'master' into add-pokemon-cries
FallenDeity Feb 7, 2024
58b9590
Merge pull request #1030 from FallenDeity/add-pokemon-cries
Naramsim Feb 7, 2024
2c3c7b2
chore: tweak nginx conf
Naramsim Feb 9, 2024
16f5cd4
chore: add logging
Naramsim Feb 9, 2024
6f8b418
Merge pull request #1041 from PokeAPI/nginx
Naramsim Feb 9, 2024
9cdc44d
chore: add gql metadata for cries
Naramsim Feb 9, 2024
036ea6a
Merge branch 'master' of https://github.com/PokeAPI/pokeapi
Naramsim Feb 9, 2024
c843a67
fixing linter issue
SKCwillie Feb 10, 2024
5e37282
Merge branch 'master' into issue1024
SKCwillie Feb 10, 2024
e7974e7
fix: sets is_battle_only to false on totem pokémon
Gudine Feb 10, 2024
2a85ddf
fix: corrects is_battle_only value on certain pokémon forms
Gudine Feb 10, 2024
99f2131
making simonorono's suggest changes
SKCwillie Feb 11, 2024
fd985e4
Merge pull request #1042 from Gudine/battle_only_fix
Naramsim Feb 12, 2024
e4e2cd6
fix: track and set permissions on talbes
Naramsim Feb 13, 2024
567e6a1
Merge branch 'master' into issue1024
SKCwillie Feb 19, 2024
b5d617a
Merge pull request #1031 from SKCwillie/issue1024
Naramsim Feb 19, 2024
2e53180
Added PowerShell wrapper and sorted table alphabetically
Celerium Mar 2, 2024
69de124
Merge pull request #1049 from Celerium/master
Naramsim Mar 4, 2024
9196054
fixing eevee's has_gender_differences data
SKCwillie Mar 4, 2024
50ab698
Added french names and some typos fixes
invalid-email-address Mar 4, 2024
c3ce0b0
Merge pull request #1053 from polidano10/french_forms_names
Naramsim Mar 5, 2024
f0b5103
Merge pull request #1052 from SKCwillie/issue-1051
Naramsim Mar 5, 2024
f364369
refactor: use compose V2
Naramsim Feb 1, 2024
7c58f00
Merge branch 'compose' of https://github.com/PokeAPI/pokeapi into com…
Naramsim Mar 22, 2024
a492d4f
refactor: style
Naramsim Mar 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions .dockerignore
Expand Up @@ -18,10 +18,10 @@ graphql
.vscode
.github
.circleci
docker-compose.yml
docker-compose*
.dockerignore
/*.md
/*.js
.env
*pycache*
target
target
20 changes: 10 additions & 10 deletions Makefile
Expand Up @@ -42,38 +42,38 @@ shell: # Load a shell
python manage.py shell ${local_config}

docker-up: # (Docker) Create services/volumes/networks
docker-compose up -d
docker compose up -d

docker-migrate: # (Docker) Run any pending migrations
docker-compose exec -T app python manage.py migrate ${docker_config}
docker compose exec -T app python manage.py migrate ${docker_config}

docker-build-db: # (Docker) Build the database
docker-compose exec -T app sh -c 'echo "from data.v2.build import build_all; build_all()" | python manage.py shell ${docker_config}'
docker compose exec -T app sh -c 'echo "from data.v2.build import build_all; build_all()" | python manage.py shell ${docker_config}'

docker-make-migrations: # (Docker) Create migrations files if schema has changed
docker-compose exec -T app sh -c 'python manage.py makemigrations ${docker_config}'
docker compose exec -T app sh -c 'python manage.py makemigrations ${docker_config}'

docker-flush-db: # (Docker) Removes all the data present in the database but preserves tables and migrations
docker-compose exec -T app sh -c 'python manage.py flush --no-input ${docker_config}'
docker compose exec -T app sh -c 'python manage.py flush --no-input ${docker_config}'

docker-destroy-db: # (Docker) Removes the volume where the database is installed on, alongside to the container itself
docker rm -f pokeapi_db_1
docker volume rm pokeapi_pg_data

docker-shell: # (Docker) Launch an interative shell for the pokeapi container
docker-compose exec app sh -l
docker compose exec app sh -l

docker-stop: # (Docker) Stop containers
docker-compose stop
docker compose stop

docker-down: # (Docker) Stop and removes containers and networks
docker-compose down
docker compose down

docker-test: # (Docker) Run tests
docker-compose exec -T app python manage.py test ${local_config}
docker compose exec -T app python manage.py test ${local_config}

docker-prod:
docker-compose -f docker-compose.yml -f docker-compose.override.yml -f Resources/compose/docker-compose-prod-graphql.yml up -d
docker compose -f docker-compose.yml -f docker-compose.override.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

Expand Down
33 changes: 17 additions & 16 deletions README.md
Expand Up @@ -83,9 +83,9 @@ make docker-setup
If you don't have `make` on your machine you can use the following commands

```sh
docker-compose up -d
docker-compose exec -T app python manage.py migrate --settings=config.docker-compose
docker-compose exec -T app sh -c 'echo "from data.v2.build import build_all; build_all()" | python manage.py shell --settings=config.docker-compose'
docker compose up -d
docker compose exec -T app python manage.py migrate --settings=config.docker-compose
docker compose exec -T app sh -c 'echo "from data.v2.build import build_all; build_all()" | python manage.py shell --settings=config.docker-compose'
```

Browse [localhost/api/v2/](http://localhost/api/v2/) or [localhost/api/v2/pokemon/bulbasaur/](http://localhost/api/v2/pokemon/bulbasaur/) on port `80`.
Expand Down Expand Up @@ -153,19 +153,20 @@ This k8s setup creates all k8s resources inside the _Namespace_ `pokeapi`, run `
| Python 2/3 | [PokeAPI/pokepy](https://github.com/PokeAPI/pokepy) | _Auto caching_ |
| Python 3 | [PokeAPI/pokebase](https://github.com/PokeAPI/pokebase) | _Auto caching_, _Image caching_ |

| Wrapper | Repository | Features |
| --- | --- | --- |
| PHP | [lmerotta/phpokeapi](https://github.com/lmerotta/phpokeapi) | _Auto caching, lazy loading_ |
| Ruby | [rdavid1099/poke-api-v2](https://github.com/rdavid1099/poke-api-v2) | |
| .Net Standard | [mtrdp642/PokeApiNet](https://github.com/mtrdp642/PokeApiNet) | _Auto caching_ |
| Go | [mtslzr/pokeapi-go](https://github.com/mtslzr/pokeapi-go) | _Auto caching_ |
| Dart | [prathanbomb/pokedart](https://github.com/prathanbomb/pokedart) | |
| Rust | [lunik1/pokerust](https://gitlab.com/lunik1/pokerust) | _Auto caching_ |
| Spring Boot | [dlfigueira/spring-pokeapi](https://github.com/dlfigueira/spring-pokeapi) | _Auto caching_ |
| Swift | [kinkofer/PokemonAPI](https://github.com/kinkofer/PokemonAPI) | |
| Typescript server-side/client-side | [Gabb-c/Pokenode-ts](https://github.com/Gabb-c/pokenode-ts) | _Auto caching_ |
| Python | [beastmatser/aiopokeapi](https://github.com/beastmatser/aiopokeapi) | _Auto caching, asynchronous_
| Scala | [juliano/pokeapi-scala](https://github.com/juliano/pokeapi-scala) | _Auto caching_ |
|Wrapper |Repository |Features |
|----------------------------------|-------------------------------------------------------------------------------------------|---------------------------|
|.Net Standard |[mtrdp642/PokeApiNet](https://github.com/mtrdp642/PokeApiNet) |Auto caching |
|Dart |[prathanbomb/pokedart](https://github.com/prathanbomb/pokedart) | |
|Go |[mtslzr/pokeapi-go](https://github.com/mtslzr/pokeapi-go) |Auto caching |
|PHP |[lmerotta/phpokeapi](https://github.com/lmerotta/phpokeapi) |Auto caching, lazy loading |
|PowerShell |[Celerium/PokeAPI-PowerShellWrapper](https://github.com/Celerium/PokeAPI-PowerShellWrapper)| |
|Python |[beastmatser/aiopokeapi](https://github.com/beastmatser/aiopokeapi) |Auto caching, asynchronous |
|Ruby |[rdavid1099/poke-api-v2](https://github.com/rdavid1099/poke-api-v2) | |
|Rust |[lunik1/pokerust](https://gitlab.com/lunik1/pokerust) |Auto caching |
|Scala |[juliano/pokeapi-scala](https://github.com/juliano/pokeapi-scala) |Auto caching |
|Spring Boot |[dlfigueira/spring-pokeapi](https://github.com/dlfigueira/spring-pokeapi) |Auto caching |
|Swift |[kinkofer/PokemonAPI](https://github.com/kinkofer/PokemonAPI) | |
|Typescript server-side/client-side|[Gabb-c/Pokenode-ts](https://github.com/Gabb-c/pokenode-ts) |Auto caching |

## Donations

Expand Down
2 changes: 2 additions & 0 deletions Resources/compose/docker-compose-prod-graphql.yml
Expand Up @@ -13,6 +13,8 @@ services:
web:
volumes:
- graphiql:/public-console:ro
logging:
driver: gcplogs

graphql-engine:
cpus: 0.7
Expand Down
2 changes: 1 addition & 1 deletion Resources/docker/app/README.md
Expand Up @@ -35,7 +35,7 @@ The container connects to a Redis cache via the environment variable `REDIS_CONN

### Run the container

The container exposes port `80`. It needs a PostgreSQL and a Redis instance to connect to. Refer to the section [How to use this image](./how-to-use-this-image) for mapping the environment variables.
The container exposes port `80`. It needs a PostgreSQL and a Redis instance to connect to. Refer to the section [How to use this image](#how-to-use-this-image) for mapping the environment variables.

It's recommended to use the provided [docker-compose.yml](https://github.com/PokeAPI/pokeapi/blob/master/docker-compose.yml) to start a container from this image.

Expand Down
52 changes: 31 additions & 21 deletions Resources/nginx/nginx.conf
Expand Up @@ -2,26 +2,32 @@ worker_processes 1;

events {
worker_connections 1024;
multi_accept on; # accept each connection as soon as you can
multi_accept on;
accept_mutex off;
use epoll;
}

http {
include mime.types;
default_type application/octet-stream;
access_log off;
log_format pokeapilogformat
'$remote_addr '
'"$request" $status cs:$upstream_cache_status s:$bytes_sent '
'r:"$http_referer"';
error_log /dev/stdout warn;
include mime.types;
default_type application/octet-stream;

server_tokens off; # dont send unnecessary server info (like version)
server_tokens off;

add_header X-XSS-Protection "1; mode=block"; # prevent XSS
add_header X-XSS-Protection "1; mode=block";

client_body_buffer_size 10K; # raise the threshold by which requests are written to HDD instead of RAM
client_header_buffer_size 2k;
client_max_body_size 8m; # we dont accept requests larger that 8mb
client_body_buffer_size 10K;
client_header_buffer_size 1k;
client_max_body_size 8m;

sendfile on;
tcp_nopush on;
tcp_nodelay on;
sendfile on;
tcp_nopush on;
tcp_nodelay on;

keepalive_timeout 5;

Expand All @@ -47,6 +53,16 @@ http {
192.168.0.0/24 0;
}

map $http_user_agent $exclude_ua {
"~*monitoring*" 0;
default 1;
}

map $request_method $only_post {
default 0;
POST $exclude_ua;
}

map $limit $limit_key {
0 "";
1 $binary_remote_addr;
Expand All @@ -69,7 +85,7 @@ http {

# Admin console
location /graphql/admin/ {
expires 1m; # client-side caching, one minute for each API resource
expires 1m;
add_header Cache-Control "public";
add_header Pragma public;
proxy_http_version 1.1;
Expand All @@ -89,21 +105,15 @@ http {
}

location /graphql/v1beta {
access_log /dev/stdout pokeapilogformat if=$only_post;
include /ssl/cache.conf*;
# proxy_cache small;
# proxy_cache_valid 200 10d;
# proxy_cache_valid any 0;
# proxy_cache_methods POST;
# proxy_cache_key "$request_method$request_uri$request_body";
limit_req zone=graphqlDefaultLimit burst=100 nodelay;
limit_req_status 429;
expires 30m; # client-side caching, one minute for each API resource
expires 30m;
add_header Cache-Control "public";
add_header Pragma public;
# add_header X-Proxy-Cache $upstream_cache_status;
proxy_hide_header Access-Control-Allow-Origin;
add_header Access-Control-Allow-Origin *;
# add_header X-Cache-Date $upstream_http_date;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
Expand All @@ -115,7 +125,7 @@ http {
}

location /api/ {
expires 1m; # client-side caching, one minute for each API resource
expires 1m;
add_header Cache-Control "public";
add_header Pragma public;
proxy_set_header X-Real-IP $remote_addr;
Expand Down
4 changes: 1 addition & 3 deletions config/settings.py
Expand Up @@ -8,9 +8,7 @@

TEMPLATE_DEBUG = DEBUG

ADMINS = (
os.environ.get("ADMINS", "Paul Hallett,paulandrewhallett@gmail.com").split(","),
)
ADMINS = (os.environ.get("ADMINS", "Pokeapi,team@pokeapi.co").split(","),)

EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"

Expand Down
42 changes: 41 additions & 1 deletion data/v2/build.py
Expand Up @@ -36,17 +36,37 @@
"https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/",
)
)
SOUND_DIR = "{prefix}{{file_name}}".format(
prefix=os.environ.get(
"POKEAPI_CRIES_PREFIX",
"https://raw.githubusercontent.com/PokeAPI/cries/main/cries/",
)
)
IMAGE_DIR = os.getcwd() + "/data/v2/sprites/sprites/"
CRIES_DIR = os.getcwd() + "/data/v2/cries/cries/"
RESOURCE_IMAGES = []
RESOURCE_CRIES = []

for root, dirs, files in os.walk(IMAGE_DIR):
for file in files:
image_path = os.path.join(root.replace(IMAGE_DIR, ""), file)
image_path = image_path.replace("\\", "/") # convert Windows-style path to Unix
RESOURCE_IMAGES.append(image_path)

for root, dirs, files in os.walk(CRIES_DIR):
for file in files:
cry_path = os.path.join(root.replace(CRIES_DIR, ""), file)
cry_path = cry_path.replace("\\", "/") # convert Windows-style path to Unix
RESOURCE_CRIES.append(cry_path)

def file_path_or_none(file_name):

def file_path_or_none(file_name, image_file=True):
if not image_file:
return (
SOUND_DIR.format(file_name=file_name)
if file_name in RESOURCE_CRIES
else None
)
return (
MEDIA_DIR.format(file_name=file_name) if file_name in RESOURCE_IMAGES else None
)
Expand Down Expand Up @@ -1931,6 +1951,26 @@ def csv_record_to_objects(info):

build_generic((PokemonSprites,), "pokemon.csv", csv_record_to_objects)

def try_cry_names(path, info, extension):
file_name = "%s.%s" % (info[0], extension)
return file_path_or_none(path + file_name, image_file=False)

def csv_record_to_objects(info):
poke_cries = "pokemon"
latest = f"{poke_cries}/latest/"
legacy = f"{poke_cries}/legacy/"
cries = {
"latest": try_cry_names(latest, info, "ogg"),
"legacy": try_cry_names(legacy, info, "ogg"),
}
yield PokemonCries(
id=int(info[0]),
pokemon=Pokemon.objects.get(pk=int(info[0])),
cries=cries,
)

build_generic((PokemonCries,), "pokemon.csv", csv_record_to_objects)

def csv_record_to_objects(info):
yield PokemonAbility(
pokemon_id=int(info[0]),
Expand Down