Skip to content

Commit

Permalink
Merge branch 'master' into veekun-scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Naramsim authored Jan 31, 2025
2 parents e8bf90d + 41c4856 commit cc439d9
Show file tree
Hide file tree
Showing 59 changed files with 15,530 additions and 9,777 deletions.
6 changes: 3 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: 2.1
jobs:
test:
docker:
- image: cimg/python:3.10.9
- image: cimg/python:3.12.8
steps:
- checkout
- run:
Expand All @@ -25,7 +25,7 @@ jobs:
command: make openapi-generate
build:
docker:
- image: cimg/python:3.10.9
- image: cimg/python:3.12.8
steps:
- checkout
- run:
Expand All @@ -44,7 +44,7 @@ jobs:
command: make build-db
deploy:
machine:
image: ubuntu-2204:2023.10.1
image: ubuntu-2204:2024.11.1
resource_class: large
steps:
- checkout
Expand Down
5 changes: 4 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ docker-compose*
/*.js
.env
*pycache*
target
target
data/v2/cries
data/v2/csv
data/v2/sprites
12 changes: 5 additions & 7 deletions .github/workflows/docker-build-and-push.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build and Push Docker image
name: Push Docker image

on:
push:
Expand All @@ -20,17 +20,15 @@ jobs:
id: meta
uses: docker/metadata-action@v5
with:
# list of Docker images to use as base name for tags
images: |
pokeapi/pokeapi
images: pokeapi/pokeapi
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME_NARAMSIM }}
password: ${{ secrets.DOCKERHUB_TOKEN_NARAMSIM }}
Expand All @@ -43,12 +41,12 @@ jobs:
echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
- name: Build and push
id: docker_build
uses: docker/build-push-action@v5
uses: docker/build-push-action@v6
with:
context: .
file: ./Resources/docker/app/Dockerfile
push: true
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6
platforms: linux/amd64,linux/arm64 #,linux/arm/v7,linux/arm/v6
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Image digest
Expand Down
21 changes: 17 additions & 4 deletions .github/workflows/docker-k8s.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build Docker image and create k8s with it
name: Test Docker, Compose and k8s

on:
pull_request:
Expand All @@ -23,12 +23,12 @@ jobs:
uses: docker/setup-buildx-action@v3
- name: Build
id: docker_build
uses: docker/build-push-action@v5
uses: docker/build-push-action@v6
with:
context: .
file: ./Resources/docker/app/Dockerfile
push: false
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6
platforms: linux/amd64,linux/arm64 #,linux/arm/v7,linux/arm/v6
tags: pokeapi/pokeapi:local
labels: ${{ steps.meta.outputs.labels }}
- name: Image digest
Expand Down Expand Up @@ -66,7 +66,7 @@ jobs:
- name: Lint k8s
run: (cd Resources/k8s/kustomize && yamllint .)
- name: Create k8s Kind Cluster
uses: helm/kind-action@v1.10.0
uses: helm/kind-action@v1.12.0
with:
cluster_name: pokeapi
version: v0.21.0
Expand Down Expand Up @@ -99,3 +99,16 @@ jobs:
test "$last_command" -eq 1
- name: Get GQL output
run: kubectl logs jobs/load-graphql
compose:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build dev environment
run: |
docker compose -f docker-compose.yml -f docker-compose-dev.yml up -d
sleep 30
- name: Assert containers running
run: |
last_command=$(docker ps | grep 'pokeapi-' | wc -l)
test "$last_command" -eq 5
34 changes: 34 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Release

on:
push:
tags:
- '*.*.*'

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Build
run: |
docker compose -f docker-compose.yml -f docker-compose-dev.yml up -d
make docker-migrate
make docker-build-db
- name: Dump DB
run: docker compose exec -T -u postgres db sh -c "cd /tmp && pg_dump -h localhost -Fc -U ash pokeapi | gzip > pokeapi.dump.zip"
- name: Copy dump
run: |
docker compose cp db:/tmp/pokeapi.dump.zip ./
ls -larth
- name: Release
uses: softprops/action-gh-release@c95fe1489396fe8a9eb87c0abf8aa5b2ef267fda
if: startsWith(github.ref, 'refs/tags/')
with:
draft: true
fail_on_unmatched_files: true
files: pokeapi.dump.zip
generate_release_notes: true
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,14 @@ start-graphql-prod:
down-graphql-prod:
docker container rm $(docker container ls -aq) -f
docker system prune --all --volumes --force
docker volume prune --all --force
sync; echo 3 > /proc/sys/vm/drop_caches

# Nginx doesn't start if upstream graphql-engine is down
update-graphql-data-prod:
docker compose ${gql_compose_config} stop
git pull origin master
git submodule update --init
git submodule update --remote --merge
docker compose ${gql_compose_config} up --pull always -d app cache db
sync; echo 3 > /proc/sys/vm/drop_caches
make docker-migrate
Expand Down
27 changes: 18 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,20 @@ A RESTful API for Pokémon - [pokeapi.co](https://pokeapi.co)

> Beta GraphQL support is rolling out! Check out the [GraphQL paragraph](#graphql--) for more info.
## Setup   [![pyVersion310](https://img.shields.io/badge/python-3.10-blue.svg)](https://www.python.org/download/releases/3.10/)

## Table of Contents

- [Setup](#setup)
- [Database setup](#database-setup)
- [Docker and Compose](#docker-and-compose)
- [GraphQL](#graphql)
- [Kubernetes](#kubernetes)
- [Wrappers](#wrappers)
- [Donations](#donations)
- [Join Us On Slack!](#join-us-on-slack)
- [Contributing](#contributing)

## Setup <a id="setup"></a> &nbsp; [![pyVersion310](https://img.shields.io/badge/python-3.12-blue.svg)](https://www.python.org/download/releases/3.10/)

- Download this source code into a working directory, be sure to use the flag `--recurse-submodules` to clone also our submodules.

Expand All @@ -43,7 +56,7 @@ A RESTful API for Pokémon - [pokeapi.co](https://pokeapi.co)
make serve
```

### Database setup
## Database setup

To build or rebuild the database by applying any CSV file update, run

Expand All @@ -70,7 +83,7 @@ make migrate

Run `make help` to see all tasks.

## Docker and Compose &nbsp; [![docker hub](https://img.shields.io/docker/v/pokeapi/pokeapi?label=tag&sort=semver)](https://hub.docker.com/r/pokeapi/pokeapi)
## Docker and Compose <a id="docker-and-compose"></a> &nbsp; [![docker hub](https://img.shields.io/docker/v/pokeapi/pokeapi?label=tag&sort=semver)](https://hub.docker.com/r/pokeapi/pokeapi)

There is also a multi-container setup, managed by [Docker Compose V2](https://docs.docker.com/compose/). This setup allows you to deploy a production-like environment, with separate containers for each service, and is recommended if you need to simply spin up PokéAPI.

Expand Down Expand Up @@ -103,7 +116,7 @@ make docker-make-migrations
make docker-migrate
```
## GraphQL &nbsp; <a href="ttps://github.com/hasura/graphql-engine"><img height="29px" src="https://graphql-engine-cdn.hasura.io/img/powered_by_hasura_blue.svg"/></a>
## GraphQL <a id="graphql"></a> &nbsp; <a href="ttps://github.com/hasura/graphql-engine"><img height="29px" src="https://graphql-engine-cdn.hasura.io/img/powered_by_hasura_blue.svg"/></a>
When you start PokéAPI with the above Docker Compose setup, an [Hasura Engine](https://github.com/hasura/graphql-engine) server is started as well. It's possible to track all the PokeAPI tables and foreign keys by simply

Expand All @@ -119,7 +132,7 @@ A free public GraphiQL console is browsable at the address https://beta.pokeapi.

A set of examples is provided in the directory [/graphql/examples](./graphql/examples) of this repository.

## Kubernetes &nbsp; [![Build Docker image and create k8s with it](https://github.com/PokeAPI/pokeapi/actions/workflows/docker-k8s.yml/badge.svg)](https://github.com/PokeAPI/pokeapi/actions/workflows/docker-k8s.yml)
## Kubernetes <a id="kubernetes"></a> &nbsp; [![Build Docker image and create k8s with it](https://github.com/PokeAPI/pokeapi/actions/workflows/docker-k8s.yml/badge.svg)](https://github.com/PokeAPI/pokeapi/actions/workflows/docker-k8s.yml)

[Kustomize](https://kubernetes.io/docs/tasks/manage-kubernetes-objects/kustomization/) files are provided in the folder https://github.com/PokeAPI/pokeapi/tree/master/Resources/k8s/kustomize/base/. Create and change your secrets:

Expand Down Expand Up @@ -223,7 +236,3 @@ To contribute to this repository:
- We'll accept your changes after review.
Simple!
## Deprecation
As of October 2018, the v1 API has been removed from PokéAPI. For more information, see [pokeapi.co/docs/v1.html](https://pokeapi.co/docs/v1.html).
14 changes: 8 additions & 6 deletions Resources/compose/docker-compose-prod-graphql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ services:
restart: "no"

web:
volumes:
- graphiql:/public-console:ro
depends_on:
graphiql:
condition: service_started
graphql-engine:
condition: service_healthy
logging:
driver: gcplogs

Expand All @@ -30,10 +33,9 @@ services:
HASURA_GRAPHQL_EVENTS_HTTP_POOL_SIZE: 10

graphiql:
image: pokeapi/graphiql:1.0.1
command: sh -c 'cp -a /app/static/. /transfer/ && tail -f /etc/passwd'
volumes:
- graphiql:/transfer
image: pokeapi/graphiql:2.0.0
expose:
- 80
depends_on:
- graphql-engine
restart: always
Expand Down
27 changes: 19 additions & 8 deletions Resources/docker/app/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
FROM python:3.10-alpine
FROM python:3.12.8-alpine3.21 AS builder

ENV PYTHONUNBUFFERED 1
ENV DJANGO_SETTINGS_MODULE 'config.docker-compose'
ENV PYTHONUNBUFFERED=1

RUN mkdir /code
WORKDIR /code

ADD requirements.txt /code/
RUN apk add --no-cache postgresql-libs libstdc++
RUN apk add --no-cache --virtual .build-deps gcc g++ musl-dev \
postgresql-dev rust cargo && \
python3 -m pip install -r requirements.txt --no-cache-dir && \
apk --purge del .build-deps
postgresql-dev binutils rust cargo && \
python3 -m pip install -r requirements.txt --no-cache-dir

FROM python:3.12.8-alpine3.21

ENV PYTHONUNBUFFERED=1
ENV DJANGO_SETTINGS_MODULE='config.docker-compose'

RUN mkdir /code
WORKDIR /code

COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin

ADD . /code/

RUN addgroup -g 1000 -S pokeapi && \
adduser -u 1000 -S pokeapi -G pokeapi

USER pokeapi
CMD gunicorn config.wsgi:application -c gunicorn.conf.py

CMD ["gunicorn", "config.wsgi:application", "-c", "gunicorn.conf.py"]

EXPOSE 80
2 changes: 1 addition & 1 deletion Resources/docker/app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
- [`master`](https://github.com/PokeAPI/pokeapi/blob/master/Resources/docker/app/Dockerfile)
- [`staging`](https://github.com/PokeAPI/pokeapi/blob/staging/Resources/docker/app/Dockerfile)

> `pokeapi` uses `python:3.10-alpine` as base image.
> `pokeapi` uses `python:3.12.8-alpine3.21` as base image.
## What is PokeAPI?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ spec:
done;
containers:
- name: graphql-engine
image: hasura/graphql-engine:v2.36.4
image: hasura/graphql-engine:v2.45.1
ports:
- containerPort: 8080
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ spec:
serviceAccountName: ingress-controller
containers:
- name: haproxy-ingress-controller
image: quay.io/jcmoraisjr/haproxy-ingress:v0.14.0
image: quay.io/jcmoraisjr/haproxy-ingress:v0.14.7
resources:
limits:
memory: "256Mi"
Expand Down
33 changes: 32 additions & 1 deletion Resources/k8s/kustomize/base/deployments/pokeapi-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,30 @@ spec:
spec:
initContainers:
- name: postgres-connection-checker
image: postgres:15.1-alpine
image: postgres:17.2-alpine3.21
command: ['sh', '-c']
args:
- until pg_isready -h postgresql -p 5432; do
echo waiting for database;
sleep 2;
done;
- name: data-download
image: alpine:3.21.2
command: ['sh', '-c']
args:
- apk add --update git &&
git clone --depth=1 --single-branch --branch=master --recurse-submodules --shallow-submodules https://github.com/PokeAPI/pokeapi.git &&
mv /code/pokeapi/data/v2/cries/* /tmp/cries/ &&
mv /code/pokeapi/data/v2/csv/* /tmp/csv/ &&
mv /code/pokeapi/data/v2/sprites/* /tmp/sprites/
workingDir: /code
volumeMounts:
- mountPath: /tmp/cries
name: cries-data-share
- mountPath: /tmp/csv
name: csv-data-share
- mountPath: /tmp/sprites
name: sprites-data-share
containers:
- name: pokeapi
image: pokeapi/pokeapi:master
Expand Down Expand Up @@ -51,6 +68,13 @@ spec:
envFrom:
- configMapRef:
name: pokeapi-configmap
volumeMounts:
- mountPath: /code/data/v2/cries
name: cries-data-share
- mountPath: /code/data/v2/csv
name: csv-data-share
- mountPath: /code/data/v2/sprites
name: sprites-data-share
resources: {}
readinessProbe:
periodSeconds: 5
Expand All @@ -64,3 +88,10 @@ spec:
httpGet:
path: /api/v2/
port: 8080
volumes:
- name: cries-data-share
emptyDir: {}
- name: csv-data-share
emptyDir: {}
- name: sprites-data-share
emptyDir: {}
Loading

0 comments on commit cc439d9

Please sign in to comment.