feat: allow staging and master deployment

This commit is contained in:
Alessandro Pezzè 2021-06-05 22:58:10 +02:00
parent fbe39b62c2
commit b2ec70d8f7
27 changed files with 26 additions and 9 deletions

View file

@ -24,12 +24,16 @@ jobs:
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: |
cp Resources/k8s/kustomize/secrets/postgres.env.sample Resources/k8s/kustomize/secrets/postgres.env
cp Resources/k8s/kustomize/secrets/graphql.env.sample Resources/k8s/kustomize/secrets/graphql.env
make kustomize-apply
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: |

View file

@ -102,7 +102,10 @@ 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/
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

View file

@ -108,18 +108,19 @@ A set of examples are provided in the directory [/graphql/examples](./graphql/ex
## 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/. Create and change your secrets:
[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/secrets/postgres.env.sample Resources/k8s/kustomize/secrets/postgres.env
cp Resources/k8s/kustomize/secrets/graphql.env.sample Resources/k8s/kustomize/secrets/graphql.env
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/
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

View file

@ -25,7 +25,7 @@ spec:
done;
containers:
- name: pokeapi
image: pokeapi/pokeapi:staging
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.

View file

@ -0,0 +1,9 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
bases:
- ../base
images:
- name: pokeapi/pokeapi
newTag: staging