Skip to content

Commit

Permalink
Merge branch 'PokeAPI:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Deleca7755 authored Oct 20, 2024
2 parents fb6cc71 + fbb24bf commit d4e0013
Show file tree
Hide file tree
Showing 70 changed files with 27,944 additions and 6,998 deletions.
3 changes: 3 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ jobs:
- run:
name: Run tests
command: make test
- run:
name: Generate OpenAPI schema
command: make openapi-generate
build:
docker:
- image: cimg/python:3.10.9
Expand Down
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ graphql
.vscode
.github
.circleci
docker-compose.yml
docker-compose*
.dockerignore
/*.md
/*.js
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,24 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
submodules: recursive
- name: Docker meta
id: meta
uses: docker/metadata-action@v3
uses: docker/metadata-action@v5
with:
# list of Docker images to use as base name for tags
images: |
pokeapi/pokeapi
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
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@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME_NARAMSIM }}
password: ${{ secrets.DOCKERHUB_TOKEN_NARAMSIM }}
Expand All @@ -43,12 +43,12 @@ jobs:
echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
uses: docker/build-push-action@v5
with:
context: .
file: ./Resources/docker/app/Dockerfile
push: true
platforms: linux/amd64,linux/arm64,linux/ppc64le,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
42 changes: 0 additions & 42 deletions .github/workflows/docker-build.yml

This file was deleted.

101 changes: 101 additions & 0 deletions .github/workflows/docker-k8s.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
name: Build Docker image and create k8s with it

on:
pull_request:

jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
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: Build
id: docker_build
uses: docker/build-push-action@v5
with:
context: .
file: ./Resources/docker/app/Dockerfile
push: false
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6
tags: pokeapi/pokeapi:local
labels: ${{ steps.meta.outputs.labels }}
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
k8s:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
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: Build
id: docker_build
uses: docker/build-push-action@v5
with:
context: .
file: ./Resources/docker/app/Dockerfile
push: false
load: true
platforms: local
tags: pokeapi/pokeapi:local
labels: ${{ steps.meta.outputs.labels }}
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
- name: Lint k8s
run: (cd Resources/k8s/kustomize && yamllint .)
- name: Create k8s Kind Cluster
uses: helm/[email protected]
with:
cluster_name: pokeapi
version: v0.21.0
- name: Create deployment configuration
run: |
cp Resources/k8s/kustomize/base/secrets/postgres.env.sample Resources/k8s/kustomize/base/secrets/postgres.env
cp Resources/k8s/kustomize/base/secrets/graphql.env.sample Resources/k8s/kustomize/base/secrets/graphql.env
cp Resources/k8s/kustomize/base/config/pokeapi.env.sample Resources/k8s/kustomize/base/config/pokeapi.env
- name: Load local image to Kind
run: kind load docker-image pokeapi/pokeapi:local --name pokeapi
- name: K8s Apply
run: |
make kustomize-local-apply
kubectl proxy &
sleep 1
bash Resources/scripts/wait.sh http://localhost:8001/api/v1/namespaces/pokeapi/services/pokeapi/proxy/api/v2/
- name: Set default namespace and print info
run: |
kubectl config set-context --current --namespace pokeapi
kubectl describe deployment
- name: Migrate and build data
run: |
make k8s-migrate
make k8s-build-db
bash Resources/scripts/wait.sh http://localhost:8001/api/v1/namespaces/pokeapi/services/pokeapi/proxy/api/v2/pal-park-area/5/
- name: K8s wait for job
run: |
kubectl wait --timeout=600s --for=condition=complete job/load-graphql
last_command=$(kubectl get job -o jsonpath='{.status.succeeded}' load-graphql)
test "$last_command" -eq 1
- name: Get GQL output
run: kubectl logs jobs/load-graphql
50 changes: 0 additions & 50 deletions .github/workflows/kustomize.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "data/v2/sprites"]
path = data/v2/sprites
url = https://github.com/PokeAPI/sprites.git
[submodule "data/v2/cries"]
path = data/v2/cries
url = https://github.com/PokeAPI/cries.git
50 changes: 30 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
veekun_pokedex_repository = ../pokedex
local_config = --settings=config.local
docker_config = --settings=config.docker-compose
gql_compose_config = -f docker-compose.yml -f Resources/compose/docker-compose-prod-graphql.yml

.PHONY: help
.SILENT:
Expand Down Expand Up @@ -41,39 +42,42 @@ make-migrations: # Create migrations files if schema has changed
shell: # Load a shell
python manage.py shell ${local_config}

openapi-generate:
python manage.py spectacular --color --file openapi.yml ${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 Expand Up @@ -112,14 +116,17 @@ hasura-get-anon-schema: # Dumps GraphQL schema
kustomize-apply: # (Kustomize) Run kubectl apply -k on the connected k8s cluster
kubectl apply -k Resources/k8s/kustomize/base/

kustomize-staging-apply: # (Kustomize) Run kubectl apply -k on the connected k8s cluster
kustomize-staging-apply: # (Kustomize) Run kubectl apply -k on the connected k8s cluster using pokeapi/pokeapi:staging
kubectl apply -k Resources/k8s/kustomize/staging/

kustomize-local-apply: # (Kustomize) Run kubectl apply -k on the connected k8s cluster using the locally available pokeapi/pokeapi:local
kubectl apply -k Resources/k8s/kustomize/local/

k8s-migrate: # (k8s) Run any pending migrations
kubectl exec --namespace pokeapi deployment/pokeapi -- python manage.py migrate --settings=config.docker-compose
kubectl exec --namespace pokeapi deployment/pokeapi -- python manage.py migrate ${docker_config}

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'
kubectl exec --namespace pokeapi deployment/pokeapi -- sh -c 'echo "from data.v2.build import build_all; build_all()" | python manage.py shell ${docker_config}'

k8s-delete: # (k8s) Delete pokeapi namespace
kubectl delete namespace pokeapi
Expand All @@ -135,17 +142,20 @@ down-graphql-prod:
docker system prune --all --volumes --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
docker compose stop graphql-engine
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
docker compose -f docker-compose.yml -f Resources/compose/docker-compose-prod-graphql.yml up -d app
make docker-migrate
make docker-build-db
docker compose stop app
sync; echo 3 > /proc/sys/vm/drop_caches
docker compose exec -T web sh -c 'rm -rf /tmp/cache/*'
docker compose start graphql-engine
docker compose ${gql_compose_config} stop app cache
docker compose ${gql_compose_config} up --pull always -d graphql-engine graphiql
sleep 120
make hasura-apply
docker compose ${gql_compose_config} up --pull always -d web
docker compose exec -T web sh -c 'rm -rf /tmp/cache/*'
docker image prune -af
sync; echo 3 > /proc/sys/vm/drop_caches
Loading

0 comments on commit d4e0013

Please sign in to comment.