mirror of
https://github.com/PokeAPI/pokeapi
synced 2024-11-25 04:40:21 +00:00
Merge pull request #623 from PokeAPI/k8s
This commit is contained in:
commit
12106f28be
37 changed files with 838 additions and 38 deletions
32
.github/workflows/docker-image.yml
vendored
32
.github/workflows/docker-image.yml
vendored
|
@ -1,4 +1,4 @@
|
|||
name: ci
|
||||
name: Build and Push Docker image
|
||||
|
||||
on:
|
||||
push:
|
||||
|
@ -12,42 +12,44 @@ jobs:
|
|||
docker:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
-
|
||||
name: Checkout
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: recursive
|
||||
-
|
||||
name: Docker meta
|
||||
- name: Docker meta
|
||||
id: meta
|
||||
uses: docker/metadata-action@v3
|
||||
with:
|
||||
# list of Docker images to use as base name for tags
|
||||
images: |
|
||||
pokeapi/pokeapi
|
||||
-
|
||||
name: Set up QEMU
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v1
|
||||
-
|
||||
name: Set up Docker Buildx
|
||||
- name: Set up Docker Buildx
|
||||
id: buildx
|
||||
uses: docker/setup-buildx-action@v1
|
||||
-
|
||||
name: Login to DockerHub
|
||||
- name: Login to DockerHub
|
||||
if: github.event_name != 'pull_request'
|
||||
uses: docker/login-action@v1
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME_NARAMSIM }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN_NARAMSIM }}
|
||||
-
|
||||
name: Build and push
|
||||
- name: Inspect builder
|
||||
run: |
|
||||
echo "Name: ${{ steps.buildx.outputs.name }}"
|
||||
echo "Endpoint: ${{ steps.buildx.outputs.endpoint }}"
|
||||
echo "Status: ${{ steps.buildx.outputs.status }}"
|
||||
echo "Flags: ${{ steps.buildx.outputs.flags }}"
|
||||
echo "Platforms: ${{ steps.buildx.outputs.platforms }}"
|
||||
- name: Build and push
|
||||
id: docker_build
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
context: .
|
||||
file: ./Resources/docker/app/Dockerfile
|
||||
push: true
|
||||
platforms: linux/amd64,linux/arm64,linux/ppc64le,linux/arm/v7,linux/arm/v6
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
-
|
||||
name: Image digest
|
||||
- name: Image digest
|
||||
run: echo ${{ steps.docker_build.outputs.digest }}
|
||||
|
|
50
.github/workflows/kustomize.yml
vendored
Normal file
50
.github/workflows/kustomize.yml
vendored
Normal file
|
@ -0,0 +1,50 @@
|
|||
name: Deploy Kustomize k8s cluster
|
||||
|
||||
on:
|
||||
workflow_run:
|
||||
workflows: ["Build and Push Docker image"]
|
||||
branches: [master, staging]
|
||||
types:
|
||||
- completed
|
||||
schedule:
|
||||
- cron: '0 0 1 * *'
|
||||
|
||||
jobs:
|
||||
create-kustomize-cluster:
|
||||
runs-on: ubuntu-latest
|
||||
if: ${{ github.event.workflow_run.conclusion == 'success' }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v2
|
||||
with:
|
||||
submodules: recursive
|
||||
- name: Lint
|
||||
run: (cd Resources/k8s/kustomize && yamllint .)
|
||||
- name: Create k8s Kind Cluster
|
||||
uses: helm/kind-action@v1.1.0
|
||||
with:
|
||||
version: v0.11.1
|
||||
- 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: K8s Apply
|
||||
run: |
|
||||
if [ ${GITHUB_REF#refs/heads/} = 'master' ]; then make kustomize-apply; else make kustomize-staging-apply; fi
|
||||
kubectl proxy &
|
||||
kubectl describe deployment
|
||||
bash Resources/scripts/wait.sh http://localhost:8001/api/v1/namespaces/pokeapi/services/pokeapi/proxy/api/v2/
|
||||
- name: Set default namespace
|
||||
run: |
|
||||
kubectl config set-context --current --namespace pokeapi
|
||||
- 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 Apply
|
||||
run: |
|
||||
kubectl wait --timeout=120s --for=condition=complete job/load-graphql
|
||||
last_command=$(kubectl get job -o jsonpath='{.status.succeeded}' load-graphql)
|
||||
test "$last_command" -eq 1
|
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -7,6 +7,6 @@ db.*
|
|||
venv*
|
||||
node_modules
|
||||
.vscode
|
||||
.env
|
||||
*.env
|
||||
Resources/nginx/ssl/*
|
||||
!Resources/nginx/ssl/*.sample.*
|
15
Makefile
15
Makefile
|
@ -100,3 +100,18 @@ hasura-apply: # Apply local Hasura configuration
|
|||
|
||||
hasura-get-anon-schema: # Dumps GraphQL schema
|
||||
gq http://localhost:8080/v1/graphql --introspect > graphql/schema.graphql
|
||||
|
||||
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
|
||||
kubectl apply -k Resources/k8s/kustomize/staging/
|
||||
|
||||
k8s-migrate: # (k8s) Run any pending migrations
|
||||
kubectl exec --namespace pokeapi deployment/pokeapi -- python manage.py migrate --settings=config.docker-compose
|
||||
|
||||
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
|
38
README.md
38
README.md
|
@ -20,7 +20,7 @@ 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 [![pyVersion37](https://img.shields.io/badge/python-3.7-blue.svg)](https://www.python.org/download/releases/3.7/)
|
||||
## Setup [![pyVersion37](https://img.shields.io/badge/python-3.7-blue.svg)](https://www.python.org/download/releases/3.7/)
|
||||
|
||||
- Download this source code into a working directory, be sure to use the flag `--recurse-submodules` to clone also our submodules.
|
||||
|
||||
|
@ -70,9 +70,9 @@ If you ever need to wipe the database use this command:
|
|||
make wipe_db
|
||||
```
|
||||
|
||||
## Docker and Compose
|
||||
## Docker and Compose [![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](https://docs.docker.com/compose/). This setup allows you to deploy a production-like environment, with separate containers for each services and is recommended if you need to simply spin up PokeAPI.
|
||||
There is also a multi-container setup, managed by [Docker Compose](https://docs.docker.com/compose/). This setup allows you to deploy a production-like environment, with separate containers for each services and is recommended if you need to simply spin up PokéAPI.
|
||||
|
||||
Start everything by
|
||||
|
||||
|
@ -90,13 +90,9 @@ docker-compose exec -T app sh -c 'echo "from data.v2.build import build_all; bui
|
|||
|
||||
Browse [localhost/api/v2/](http://localhost/api/v2/) or [localhost/api/v2/pokemon/bulbasaur/](http://localhost/api/v2/pokemon/bulbasaur/) on port `80`.
|
||||
|
||||
## GraphQL
|
||||
## GraphQL <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>
|
||||
|
||||
<a href="ttps://github.com/hasura/graphql-engine">
|
||||
<img width="100px" src="https://graphql-engine-cdn.hasura.io/img/powered_by_hasura_blue.svg" />
|
||||
</a>
|
||||
|
||||
When you start PokeAPI 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
|
||||
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
|
||||
|
||||
```sh
|
||||
# hasura cli needs to be installed and available in your $PATH: https://hasura.io/docs/latest/graphql/core/hasura-cli/install-hasura-cli.html
|
||||
|
@ -110,6 +106,30 @@ A free public GraphiQL console is browsable at the address https://beta.pokeapi.
|
|||
|
||||
A set of examples are provided in the directory [/graphql/examples](./graphql/examples) of this repository.
|
||||
|
||||
## Kubernetes [![k8s status](https://github.com/PokeAPI/pokeapi/actions/workflows/kustomize.yml/badge.svg?branch=master)](https://github.com/PokeAPI/pokeapi/actions/workflows/kustomize.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:
|
||||
|
||||
```sh
|
||||
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
|
||||
# Edit the newly created files
|
||||
```
|
||||
|
||||
Configure `kubectl` to point to a cluster and then run the following commands to start a PokéAPI service.
|
||||
|
||||
```sh
|
||||
kubectl apply -k Resources/k8s/kustomize/base/
|
||||
kubectl config set-context --current --namespace pokeapi # (Optional) Set pokeapi ns as the working ns
|
||||
# Wait for the cluster to spin up
|
||||
kubectl exec --namespace pokeapi deployment/pokeapi -- python manage.py migrate --settings=config.docker-compose # Migrate the DB
|
||||
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' # Build the db
|
||||
kubectl wait --namespace pokeapi --timeout=120s --for=condition=complete job/load-graphql # Wait for Graphql configuration job to finish
|
||||
```
|
||||
|
||||
This k8s setup creates all k8s resources inside the _Namespace_ `pokeapi`, run `kubectl delete namespace pokeapi` to delete them. It also creates a _Service_ of type `LoadBalancer` which is exposed on port `80` and `443`. Data is persisted on `12Gi` of `ReadWriteOnce` volumes.
|
||||
|
||||
## Official REST Wrappers
|
||||
|
||||
* Node server-side [PokeAPI/pokedex-promise-v2](https://github.com/PokeAPI/pokedex-promise-v2) | _Auto caching_
|
||||
|
|
|
@ -2,7 +2,6 @@ FROM python:3.7-alpine
|
|||
|
||||
ENV PYTHONUNBUFFERED 1
|
||||
ENV DJANGO_SETTINGS_MODULE 'config.docker-compose'
|
||||
ENV PYTHONHASHSEED 'random'
|
||||
|
||||
RUN mkdir /code
|
||||
WORKDIR /code
|
||||
|
@ -19,5 +18,5 @@ RUN addgroup -g 1000 -S pokeapi && \
|
|||
adduser -u 1000 -S pokeapi -G pokeapi
|
||||
|
||||
USER pokeapi
|
||||
CMD gunicorn config.wsgi:application -c gunicorn.py.ini
|
||||
CMD gunicorn config.wsgi:application -c gunicorn.conf.py
|
||||
EXPOSE 80
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
## Supported tags and respective `Dockerfile` links
|
||||
|
||||
- [`latest`](https://github.com/PokeAPI/pokeapi/blob/master/Resources/docker/app/Dockerfile)
|
||||
- [`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.7-alpine` as base image.
|
||||
|
||||
|
|
7
Resources/k8s/kustomize/.yamllint.yaml
Normal file
7
Resources/k8s/kustomize/.yamllint.yaml
Normal file
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
|
||||
extends: default
|
||||
|
||||
rules:
|
||||
document-start: disable
|
||||
line-length: disable
|
|
@ -0,0 +1,9 @@
|
|||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: haproxy-ingress-configmap
|
||||
data:
|
||||
dynamic-scaling: "true"
|
||||
ssl-redirect: "false"
|
||||
app-root: "/"
|
||||
stats-auth: pokeapi:pokeapi
|
2
Resources/k8s/kustomize/base/config/pokeapi.env.sample
Normal file
2
Resources/k8s/kustomize/base/config/pokeapi.env.sample
Normal file
|
@ -0,0 +1,2 @@
|
|||
ADMINS=PokeAPI,change.me@pokeapi.co
|
||||
BASE_URL=http://localhost/
|
|
@ -0,0 +1,25 @@
|
|||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: default-backend
|
||||
labels:
|
||||
component: default-backend
|
||||
spec:
|
||||
replicas: 2
|
||||
selector:
|
||||
matchLabels:
|
||||
component: default-backend
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
component: default-backend
|
||||
spec:
|
||||
containers:
|
||||
- name: default-backend
|
||||
image: gcr.io/google_containers/defaultbackend:1.4
|
||||
ports:
|
||||
- containerPort: 8080
|
||||
resources:
|
||||
limits:
|
||||
memory: "64Mi"
|
||||
cpu: "50m"
|
|
@ -0,0 +1,54 @@
|
|||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: graphql
|
||||
labels:
|
||||
component: graphql
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
component: graphql
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
component: graphql
|
||||
spec:
|
||||
initContainers:
|
||||
- name: pokeapi-connection-checker
|
||||
image: curlimages/curl:latest
|
||||
command: ["sh", "-c"]
|
||||
args:
|
||||
- until curl -f -s --output /dev/null http://pokeapi:80/api/v2/; do
|
||||
echo waiting for pokeapi;
|
||||
sleep 2;
|
||||
done;
|
||||
containers:
|
||||
- name: graphql-engine
|
||||
image: hasura/graphql-engine:v2.0.0-alpha.5
|
||||
ports:
|
||||
- containerPort: 8080
|
||||
env:
|
||||
- name: POSTGRES_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: postgres-env-secret
|
||||
key: POSTGRES_PASSWORD
|
||||
- name: HASURA_GRAPHQL_ADMIN_SECRET
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: graphql-env-secret
|
||||
key: HASURA_GRAPHQL_ADMIN_SECRET
|
||||
- name: HASURA_GRAPHQL_DATABASE_URL
|
||||
value: postgres://ash:$(POSTGRES_PASSWORD)@postgresql:5432/pokeapi
|
||||
- name: HASURA_GRAPHQL_ENABLE_CONSOLE
|
||||
value: "true"
|
||||
- name: HASURA_GRAPHQL_DEV_MODE
|
||||
value: "false"
|
||||
- name: HASURA_GRAPHQL_ENABLED_LOG_TYPES
|
||||
value: startup, http-log, webhook-log, websocket-log, query-log
|
||||
- name: HASURA_GRAPHQL_UNAUTHORIZED_ROLE
|
||||
value: anon
|
||||
- name: HASURA_GRAPHQL_ENABLE_TELEMETRY
|
||||
value: "false"
|
||||
resources: {}
|
|
@ -0,0 +1,47 @@
|
|||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: haproxy-ingress-controller
|
||||
labels:
|
||||
component: haproxy-ingress
|
||||
spec:
|
||||
selector:
|
||||
matchLabels:
|
||||
component: haproxy-ingress
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
component: haproxy-ingress
|
||||
spec:
|
||||
serviceAccountName: ingress-controller
|
||||
containers:
|
||||
- name: haproxy-ingress-controller
|
||||
image: quay.io/jcmoraisjr/haproxy-ingress:v0.12.3
|
||||
resources:
|
||||
limits:
|
||||
memory: "256Mi"
|
||||
cpu: "500m"
|
||||
args:
|
||||
- --default-ssl-certificate=$(POD_NAMESPACE)/tls-secret
|
||||
- --configmap=$(POD_NAMESPACE)/haproxy-ingress-configmap
|
||||
- --reload-strategy=native
|
||||
ports:
|
||||
- name: http
|
||||
containerPort: 80
|
||||
- name: https
|
||||
containerPort: 443
|
||||
- name: stat
|
||||
containerPort: 1936
|
||||
livenessProbe:
|
||||
httpGet:
|
||||
path: /healthz
|
||||
port: 10253
|
||||
env:
|
||||
- name: POD_NAME
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: metadata.name
|
||||
- name: POD_NAMESPACE
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: metadata.namespace
|
|
@ -0,0 +1,65 @@
|
|||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: pokeapi
|
||||
labels:
|
||||
component: pokeapi
|
||||
spec:
|
||||
replicas: 2
|
||||
selector:
|
||||
matchLabels:
|
||||
component: pokeapi
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
component: pokeapi
|
||||
spec:
|
||||
initContainers:
|
||||
- name: postgres-connection-checker
|
||||
image: postgres:13.3-alpine
|
||||
command: ['sh', '-c']
|
||||
args:
|
||||
- until pg_isready -h postgresql -p 5432; do
|
||||
echo waiting for database;
|
||||
sleep 2;
|
||||
done;
|
||||
containers:
|
||||
- name: pokeapi
|
||||
image: pokeapi/pokeapi:master
|
||||
ports:
|
||||
- containerPort: 8080
|
||||
securityContext: # CI: Github Actions kills this container if not run with root. Otherwise, it's safe to use the default pokeapi/pokeapi user and remove these lines.
|
||||
allowPrivilegeEscalation: false
|
||||
runAsUser: 0
|
||||
env:
|
||||
- name: SERVER_PORT
|
||||
value: "8080"
|
||||
- name: POSTGRES_HOST
|
||||
value: postgresql
|
||||
- name: POSTGRES_USER
|
||||
value: ash
|
||||
- name: POSTGRES_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: postgres-env-secret
|
||||
key: POSTGRES_PASSWORD
|
||||
- name: POSTGRES_DB
|
||||
value: pokeapi
|
||||
- name: REDIS_CONNECTION_STRING
|
||||
value: redis://redis:6379/1
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: pokeapi-configmap
|
||||
resources: {}
|
||||
readinessProbe:
|
||||
periodSeconds: 5
|
||||
initialDelaySeconds: 5
|
||||
httpGet:
|
||||
path: /api/v2/
|
||||
port: 8080
|
||||
livenessProbe:
|
||||
periodSeconds: 5
|
||||
initialDelaySeconds: 5
|
||||
httpGet:
|
||||
path: /api/v2/
|
||||
port: 8080
|
|
@ -0,0 +1,41 @@
|
|||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: postgresql
|
||||
labels:
|
||||
component: postgresql
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
component: postgresql
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
component: postgresql
|
||||
spec:
|
||||
containers:
|
||||
- name: postgresql
|
||||
image: postgres:13.3-alpine
|
||||
ports:
|
||||
- containerPort: 5432
|
||||
env:
|
||||
- name: POSTGRES_USER
|
||||
value: ash
|
||||
- name: POSTGRES_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: postgres-env-secret
|
||||
key: POSTGRES_PASSWORD
|
||||
- name: PGDATA
|
||||
value: /var/lib/postgresql/data/pgdata
|
||||
- name: POSTGRES_DB
|
||||
value: pokeapi
|
||||
resources: {}
|
||||
volumeMounts:
|
||||
- mountPath: /var/lib/postgresql/data
|
||||
name: postgres-claim0
|
||||
volumes:
|
||||
- name: postgres-claim0
|
||||
persistentVolumeClaim:
|
||||
claimName: postgres-claim0
|
|
@ -0,0 +1,29 @@
|
|||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: redis
|
||||
labels:
|
||||
component: redis
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
component: redis
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
component: redis
|
||||
spec:
|
||||
containers:
|
||||
- name: redis
|
||||
image: redis:6.2.3-alpine
|
||||
ports:
|
||||
- containerPort: 6379
|
||||
resources: {}
|
||||
volumeMounts:
|
||||
- mountPath: /data
|
||||
name: redis-claim0
|
||||
volumes:
|
||||
- name: redis-claim0
|
||||
persistentVolumeClaim:
|
||||
claimName: redis-claim0
|
37
Resources/k8s/kustomize/base/jobs/load-graphql.yaml
Normal file
37
Resources/k8s/kustomize/base/jobs/load-graphql.yaml
Normal file
|
@ -0,0 +1,37 @@
|
|||
apiVersion: batch/v1
|
||||
kind: Job
|
||||
metadata:
|
||||
name: load-graphql
|
||||
spec:
|
||||
ttlSecondsAfterFinished: 200
|
||||
template:
|
||||
spec:
|
||||
restartPolicy: Never
|
||||
initContainers:
|
||||
- name: pokeapi-last-built-resource-connection-checker
|
||||
image: curlimages/curl:latest
|
||||
command: ['sh', '-c']
|
||||
args:
|
||||
- until curl -f -s --output /dev/null http://pokeapi:80/api/v2/pal-park-area/5/;
|
||||
do echo waiting for pokeapi;
|
||||
sleep 2;
|
||||
done;
|
||||
containers:
|
||||
- name: load-graphql
|
||||
image: debian:buster
|
||||
env:
|
||||
- name: HASURA_GRAPHQL_ADMIN_SECRET
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: graphql-env-secret
|
||||
key: HASURA_GRAPHQL_ADMIN_SECRET
|
||||
command: ["sh", "-c"]
|
||||
args:
|
||||
- apt-get update &&
|
||||
apt-get install -y git curl &&
|
||||
curl -L https://github.com/hasura/graphql-engine/raw/stable/cli/get.sh | bash &&
|
||||
hasura update-cli --version v2.0.0-alpha.5 &&
|
||||
git clone https://github.com/PokeAPI/pokeapi.git &&
|
||||
cd pokeapi &&
|
||||
git checkout staging &&
|
||||
hasura md apply --endpoint http://graphql:8080 --project graphql --admin-secret $(HASURA_GRAPHQL_ADMIN_SECRET)
|
38
Resources/k8s/kustomize/base/kustomization.yaml
Normal file
38
Resources/k8s/kustomize/base/kustomization.yaml
Normal file
|
@ -0,0 +1,38 @@
|
|||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
|
||||
namespace: pokeapi
|
||||
|
||||
configMapGenerator:
|
||||
- name: pokeapi-configmap
|
||||
files:
|
||||
- config/pokeapi.env
|
||||
|
||||
secretGenerator:
|
||||
- name: postgres-env-secret
|
||||
env: secrets/postgres.env
|
||||
type: Opaque
|
||||
- name: graphql-env-secret
|
||||
env: secrets/graphql.env
|
||||
type: Opaque
|
||||
|
||||
resources:
|
||||
- other/namespace.yaml
|
||||
- other/ingress-controller-rbac.yaml
|
||||
- config/haproxy-ingress-configmap.yaml
|
||||
- services/default-service.yaml
|
||||
- services/pokeapi-service.yaml
|
||||
- services/postgres-service.yaml
|
||||
- services/redis-service.yaml
|
||||
- services/graphql-service.yaml
|
||||
- services/cloud.yaml
|
||||
- volumes/postgres-persistentvolumeclaim.yaml
|
||||
- volumes/redis-persistentvolumeclaim.yaml
|
||||
- deployments/default-deployment.yaml
|
||||
- deployments/postgres-deployment.yaml
|
||||
- deployments/redis-deployment.yaml
|
||||
- deployments/pokeapi-deployment.yaml
|
||||
- deployments/graphql-deployment.yaml
|
||||
- deployments/haproxy-ingress-controller.yaml
|
||||
- other/ingress.yaml
|
||||
- jobs/load-graphql.yaml
|
125
Resources/k8s/kustomize/base/other/ingress-controller-rbac.yaml
Normal file
125
Resources/k8s/kustomize/base/other/ingress-controller-rbac.yaml
Normal file
|
@ -0,0 +1,125 @@
|
|||
---
|
||||
apiVersion: v1
|
||||
kind: ServiceAccount
|
||||
metadata:
|
||||
name: ingress-controller
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: ClusterRole
|
||||
metadata:
|
||||
name: ingress-controller
|
||||
rules:
|
||||
- apiGroups:
|
||||
- ""
|
||||
resources:
|
||||
- configmaps
|
||||
- endpoints
|
||||
- nodes
|
||||
- pods
|
||||
- secrets
|
||||
verbs:
|
||||
- list
|
||||
- watch
|
||||
- apiGroups:
|
||||
- ""
|
||||
resources:
|
||||
- nodes
|
||||
verbs:
|
||||
- get
|
||||
- apiGroups:
|
||||
- ""
|
||||
resources:
|
||||
- services
|
||||
verbs:
|
||||
- get
|
||||
- list
|
||||
- watch
|
||||
- apiGroups:
|
||||
- extensions
|
||||
- networking.k8s.io
|
||||
resources:
|
||||
- ingresses
|
||||
- ingressclasses
|
||||
verbs:
|
||||
- get
|
||||
- list
|
||||
- watch
|
||||
- apiGroups:
|
||||
- ""
|
||||
resources:
|
||||
- events
|
||||
verbs:
|
||||
- create
|
||||
- patch
|
||||
- apiGroups:
|
||||
- "extensions"
|
||||
resources:
|
||||
- ingresses/status
|
||||
verbs:
|
||||
- update
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: Role
|
||||
metadata:
|
||||
name: ingress-controller
|
||||
rules:
|
||||
- apiGroups:
|
||||
- ""
|
||||
resources:
|
||||
- configmaps
|
||||
- pods
|
||||
- secrets
|
||||
- namespaces
|
||||
verbs:
|
||||
- get
|
||||
- apiGroups:
|
||||
- ""
|
||||
resources:
|
||||
- configmaps
|
||||
verbs:
|
||||
- get
|
||||
- update
|
||||
- apiGroups:
|
||||
- ""
|
||||
resources:
|
||||
- configmaps
|
||||
verbs:
|
||||
- create
|
||||
- apiGroups:
|
||||
- ""
|
||||
resources:
|
||||
- endpoints
|
||||
verbs:
|
||||
- get
|
||||
- create
|
||||
- update
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: ClusterRoleBinding
|
||||
metadata:
|
||||
name: ingress-controller
|
||||
roleRef:
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
kind: ClusterRole
|
||||
name: ingress-controller
|
||||
subjects:
|
||||
- kind: ServiceAccount
|
||||
name: ingress-controller
|
||||
- apiGroup: rbac.authorization.k8s.io
|
||||
kind: User
|
||||
name: ingress-controller
|
||||
---
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: RoleBinding
|
||||
metadata:
|
||||
name: ingress-controller
|
||||
roleRef:
|
||||
apiGroup: rbac.authorization.k8s.io
|
||||
kind: Role
|
||||
name: ingress-controller
|
||||
subjects:
|
||||
- kind: ServiceAccount
|
||||
name: ingress-controller
|
||||
- apiGroup: rbac.authorization.k8s.io
|
||||
kind: User
|
||||
name: ingress-controller
|
50
Resources/k8s/kustomize/base/other/ingress.yaml
Normal file
50
Resources/k8s/kustomize/base/other/ingress.yaml
Normal file
|
@ -0,0 +1,50 @@
|
|||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: pokeapi-ingress
|
||||
annotations:
|
||||
kubernetes.io/ingress.class: "haproxy"
|
||||
ingress.kubernetes.io/config-backend: |
|
||||
compression algo gzip
|
||||
compression type application/json
|
||||
spec:
|
||||
defaultBackend:
|
||||
service:
|
||||
name: default-backend
|
||||
port:
|
||||
number: 8080
|
||||
rules:
|
||||
- http:
|
||||
paths:
|
||||
- path: /api/v2
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: pokeapi
|
||||
port:
|
||||
number: 80
|
||||
---
|
||||
apiVersion: networking.k8s.io/v1
|
||||
kind: Ingress
|
||||
metadata:
|
||||
name: graphql-ingress
|
||||
annotations:
|
||||
kubernetes.io/ingress.class: "haproxy"
|
||||
ingress.kubernetes.io/config-backend: |
|
||||
http-request replace-path /graphql(.*) \1
|
||||
spec:
|
||||
defaultBackend:
|
||||
service:
|
||||
name: default-backend
|
||||
port:
|
||||
number: 8080
|
||||
rules:
|
||||
- http:
|
||||
paths:
|
||||
- path: /graphql
|
||||
pathType: Prefix
|
||||
backend:
|
||||
service:
|
||||
name: graphql
|
||||
port:
|
||||
number: 8080
|
6
Resources/k8s/kustomize/base/other/namespace.yaml
Normal file
6
Resources/k8s/kustomize/base/other/namespace.yaml
Normal file
|
@ -0,0 +1,6 @@
|
|||
apiVersion: v1
|
||||
kind: Namespace
|
||||
metadata:
|
||||
name: pokeapi
|
||||
labels:
|
||||
name: pokeapi
|
1
Resources/k8s/kustomize/base/secrets/graphql.env.sample
Normal file
1
Resources/k8s/kustomize/base/secrets/graphql.env.sample
Normal file
|
@ -0,0 +1 @@
|
|||
HASURA_GRAPHQL_ADMIN_SECRET=pokeapi-change-me
|
1
Resources/k8s/kustomize/base/secrets/postgres.env.sample
Normal file
1
Resources/k8s/kustomize/base/secrets/postgres.env.sample
Normal file
|
@ -0,0 +1 @@
|
|||
POSTGRES_PASSWORD=pokeapi-change-me
|
21
Resources/k8s/kustomize/base/services/cloud.yaml
Normal file
21
Resources/k8s/kustomize/base/services/cloud.yaml
Normal file
|
@ -0,0 +1,21 @@
|
|||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: haproxy-ingress
|
||||
labels:
|
||||
component: haproxy-ingress
|
||||
spec:
|
||||
type: LoadBalancer # TODO: Change to `LoadBalancer`
|
||||
externalTrafficPolicy: Local
|
||||
ports:
|
||||
- name: public-http
|
||||
port: 80
|
||||
targetPort: http
|
||||
- name: public-https
|
||||
port: 443
|
||||
targetPort: http
|
||||
- name: public-stat
|
||||
port: 1936
|
||||
targetPort: stat
|
||||
selector:
|
||||
component: haproxy-ingress
|
12
Resources/k8s/kustomize/base/services/default-service.yaml
Normal file
12
Resources/k8s/kustomize/base/services/default-service.yaml
Normal file
|
@ -0,0 +1,12 @@
|
|||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: default-backend
|
||||
labels:
|
||||
component: default-backend
|
||||
spec:
|
||||
selector:
|
||||
component: default-backend
|
||||
ports:
|
||||
- port: 8080
|
||||
targetPort: 8080
|
12
Resources/k8s/kustomize/base/services/graphql-service.yaml
Normal file
12
Resources/k8s/kustomize/base/services/graphql-service.yaml
Normal file
|
@ -0,0 +1,12 @@
|
|||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: graphql
|
||||
labels:
|
||||
component: graphql
|
||||
spec:
|
||||
selector:
|
||||
component: graphql
|
||||
ports:
|
||||
- port: 8080
|
||||
targetPort: 8080
|
14
Resources/k8s/kustomize/base/services/pokeapi-service.yaml
Normal file
14
Resources/k8s/kustomize/base/services/pokeapi-service.yaml
Normal file
|
@ -0,0 +1,14 @@
|
|||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: pokeapi
|
||||
labels:
|
||||
component: pokeapi
|
||||
annotations:
|
||||
ingress.kubernetes.io/balance-algorithm: leastconn
|
||||
spec:
|
||||
selector:
|
||||
component: pokeapi
|
||||
ports:
|
||||
- port: 80
|
||||
targetPort: 8080
|
12
Resources/k8s/kustomize/base/services/postgres-service.yaml
Normal file
12
Resources/k8s/kustomize/base/services/postgres-service.yaml
Normal file
|
@ -0,0 +1,12 @@
|
|||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: postgresql
|
||||
labels:
|
||||
component: postgresql
|
||||
spec:
|
||||
selector:
|
||||
component: postgresql
|
||||
ports:
|
||||
- port: 5432
|
||||
targetPort: 5432
|
12
Resources/k8s/kustomize/base/services/redis-service.yaml
Normal file
12
Resources/k8s/kustomize/base/services/redis-service.yaml
Normal file
|
@ -0,0 +1,12 @@
|
|||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: redis
|
||||
labels:
|
||||
component: redis
|
||||
spec:
|
||||
selector:
|
||||
component: redis
|
||||
ports:
|
||||
- port: 6379
|
||||
targetPort: 6379
|
|
@ -0,0 +1,27 @@
|
|||
apiVersion: v1
|
||||
kind: PersistentVolume
|
||||
metadata:
|
||||
name: postgres-volume0
|
||||
labels:
|
||||
type: local
|
||||
component: postgres
|
||||
spec:
|
||||
capacity:
|
||||
storage: 10Gi
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
hostPath: # TODO: change to a cloud-solution
|
||||
path: "/mnt/data"
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
name: postgres-claim0
|
||||
labels:
|
||||
component: postgres
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 10Gi
|
|
@ -0,0 +1,27 @@
|
|||
apiVersion: v1
|
||||
kind: PersistentVolume
|
||||
metadata:
|
||||
name: redis-volume0
|
||||
labels:
|
||||
type: local
|
||||
component: redis
|
||||
spec:
|
||||
capacity:
|
||||
storage: 2Gi
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
hostPath: # TODO: change to a cloud-solution
|
||||
path: "/mnt/data"
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: PersistentVolumeClaim
|
||||
metadata:
|
||||
name: redis-claim0
|
||||
labels:
|
||||
component: redis
|
||||
spec:
|
||||
accessModes:
|
||||
- ReadWriteOnce
|
||||
resources:
|
||||
requests:
|
||||
storage: 2Gi
|
9
Resources/k8s/kustomize/staging/kustomization.yaml
Normal file
9
Resources/k8s/kustomize/staging/kustomization.yaml
Normal file
|
@ -0,0 +1,9 @@
|
|||
apiVersion: kustomize.config.k8s.io/v1beta1
|
||||
kind: Kustomization
|
||||
|
||||
bases:
|
||||
- ../base
|
||||
|
||||
images:
|
||||
- name: pokeapi/pokeapi
|
||||
newTag: staging
|
|
@ -154,7 +154,8 @@ EOF
|
|||
|
||||
# If the job was started by a Pull Request and not by a cron job, add a comment to notify the users
|
||||
notify_engine_pr() {
|
||||
if [[ $1 == "start" || $1 == "end_failed" || $1 == "end_success" || $1 == "end_no_deploy" || $1 == "end_no_new_data" ]]; then
|
||||
local -r allowed_events='start end_failed end_success end_no_deploy end_no_new_data'
|
||||
if [[ "$allowed_events" == *"$1"* ]] && [[ "$CIRCLE_BRANCH" == 'master' ]]; then
|
||||
engine_repo_pr_number=$(get_invokator_pr_number)
|
||||
if [ "$engine_repo_pr_number" != "null" ] && [ -n "$CIRCLE_USERNAME" ]; then
|
||||
curl -f -H "$auth_header" -X POST --data "$(pr_input_updater_$1)" "https://api.github.com/repos/$org/$engine_repo/issues/$engine_repo_pr_number/comments"
|
||||
|
|
23
Resources/scripts/wait.sh
Normal file
23
Resources/scripts/wait.sh
Normal file
|
@ -0,0 +1,23 @@
|
|||
#!/bin/bash
|
||||
|
||||
wait_for_http() {
|
||||
local url="$1"
|
||||
local max_seconds=1000
|
||||
local end_time=$(( $(date +%s) + max_seconds ))
|
||||
local success='false'
|
||||
echo "Waiting for $url"
|
||||
while [ "$(date +%s)" -lt "$end_time" ]; do # Loop until interval has elapsed.
|
||||
sleep 2
|
||||
if [ "$(curl -s -o /dev/null -L -w '%{http_code}' "$url")" == "200" ]; then
|
||||
success='true'
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ "$success" = 'true' ]; then
|
||||
exit 0
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
wait_for_http "${1:-http://localhost/api/v2/}"
|
|
@ -8,21 +8,27 @@ DEBUG = False
|
|||
|
||||
TEMPLATE_DEBUG = DEBUG
|
||||
|
||||
ADMINS = (("Paul Hallett", "paulandrewhallett@gmail.com"),)
|
||||
ADMINS = (
|
||||
os.environ.get("ADMINS", "Paul Hallett,paulandrewhallett@gmail.com").split(","),
|
||||
)
|
||||
|
||||
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
|
||||
|
||||
MANAGERS = ADMINS
|
||||
|
||||
BASE_URL = "http://pokeapi.co"
|
||||
BASE_URL = os.environ.get("BASE_URL", "http://pokeapi.co")
|
||||
|
||||
# Hosts/domain names that are valid for this site; required if DEBUG is False
|
||||
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
|
||||
ALLOWED_HOSTS = [".pokeapi.co", "localhost", "127.0.0.1"]
|
||||
ALLOWED_HOSTS = [
|
||||
os.environ.get("ALLOWED_HOSTS", ".pokeapi.co"),
|
||||
"localhost",
|
||||
"127.0.0.1",
|
||||
]
|
||||
|
||||
TIME_ZONE = "Europe/London"
|
||||
TIME_ZONE = os.environ.get("TIME_ZONE", "Europe/London")
|
||||
|
||||
LANGUAGE_CODE = "en-gb"
|
||||
LANGUAGE_CODE = os.environ.get("LANGUAGE_CODE", "en-gb")
|
||||
|
||||
SITE_ID = 1
|
||||
|
||||
|
@ -40,8 +46,6 @@ USE_TZ = True
|
|||
# Explicitly define test runner to avoid warning messages on test execution
|
||||
TEST_RUNNER = "django.test.runner.DiscoverRunner"
|
||||
|
||||
SECRET_KEY = "4nksdock439320df*(^x2_scm-o$*py3e@-awu-n^hipkm%2l$sw$&2l#"
|
||||
|
||||
MIDDLEWARE = [
|
||||
"corsheaders.middleware.CorsMiddleware",
|
||||
"django.middleware.common.CommonMiddleware",
|
||||
|
|
|
@ -8,5 +8,5 @@
|
|||
idle_timeout: 180
|
||||
max_connections: 50
|
||||
retries: 1
|
||||
tables: "!include default\\tables\\tables.yaml"
|
||||
functions: "!include default\\functions\\functions.yaml"
|
||||
tables: "!include default/tables/tables.yaml"
|
||||
functions: "!include default/functions/functions.yaml"
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import os
|
||||
from multiprocessing import cpu_count
|
||||
|
||||
bind = '0.0.0.0:80'
|
||||
bind = "0.0.0.0:{}".format(os.environ.get("SERVER_PORT", "80"))
|
||||
workers = cpu_count() * 2
|
||||
threads = cpu_count() * 2
|
Loading…
Reference in a new issue