Skip to content

Commit cccbcdd

Browse files
authored
Merge pull request #1028 from PokeAPI/kustomize
Use local image when testing k8s
2 parents fa6ccb6 + 0197863 commit cccbcdd

File tree

12 files changed

+128
-102
lines changed

12 files changed

+128
-102
lines changed
File renamed without changes.

.github/workflows/docker-build.yml

Lines changed: 0 additions & 42 deletions
This file was deleted.

.github/workflows/docker-k8s.yml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: Build Docker image and create k8s with it
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
docker:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v4
12+
with:
13+
submodules: recursive
14+
- name: Docker meta
15+
id: meta
16+
uses: docker/metadata-action@v5
17+
with:
18+
images: pokeapi/pokeapi
19+
- name: Set up QEMU
20+
uses: docker/setup-qemu-action@v3
21+
- name: Set up Docker Buildx
22+
id: buildx
23+
uses: docker/setup-buildx-action@v3
24+
- name: Build
25+
id: docker_build
26+
uses: docker/build-push-action@v5
27+
with:
28+
context: .
29+
file: ./Resources/docker/app/Dockerfile
30+
push: false
31+
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6
32+
tags: pokeapi/pokeapi:local
33+
labels: ${{ steps.meta.outputs.labels }}
34+
- name: Image digest
35+
run: echo ${{ steps.docker_build.outputs.digest }}
36+
k8s:
37+
runs-on: ubuntu-latest
38+
steps:
39+
- name: Checkout
40+
uses: actions/checkout@v4
41+
with:
42+
submodules: recursive
43+
- name: Docker meta
44+
id: meta
45+
uses: docker/metadata-action@v5
46+
with:
47+
images: pokeapi/pokeapi
48+
- name: Set up QEMU
49+
uses: docker/setup-qemu-action@v3
50+
- name: Set up Docker Buildx
51+
id: buildx
52+
uses: docker/setup-buildx-action@v3
53+
- name: Build
54+
id: docker_build
55+
uses: docker/build-push-action@v5
56+
with:
57+
context: .
58+
file: ./Resources/docker/app/Dockerfile
59+
push: false
60+
load: true
61+
platforms: local
62+
tags: pokeapi/pokeapi:local
63+
labels: ${{ steps.meta.outputs.labels }}
64+
- name: Image digest
65+
run: echo ${{ steps.docker_build.outputs.digest }}
66+
- name: Lint k8s
67+
run: (cd Resources/k8s/kustomize && yamllint .)
68+
- name: Create k8s Kind Cluster
69+
uses: helm/[email protected]
70+
with:
71+
cluster_name: pokeapi
72+
version: v0.21.0
73+
- name: Create deployment configuration
74+
run: |
75+
cp Resources/k8s/kustomize/base/secrets/postgres.env.sample Resources/k8s/kustomize/base/secrets/postgres.env
76+
cp Resources/k8s/kustomize/base/secrets/graphql.env.sample Resources/k8s/kustomize/base/secrets/graphql.env
77+
cp Resources/k8s/kustomize/base/config/pokeapi.env.sample Resources/k8s/kustomize/base/config/pokeapi.env
78+
- name: Load local image to Kind
79+
run: kind load docker-image pokeapi/pokeapi:local --name pokeapi
80+
- name: K8s Apply
81+
run: |
82+
make kustomize-local-apply
83+
kubectl proxy &
84+
sleep 1
85+
bash Resources/scripts/wait.sh http://localhost:8001/api/v1/namespaces/pokeapi/services/pokeapi/proxy/api/v2/
86+
- name: Set default namespace and print info
87+
run: |
88+
kubectl config set-context --current --namespace pokeapi
89+
kubectl describe deployment
90+
- name: Migrate and build data
91+
run: |
92+
make k8s-migrate
93+
make k8s-build-db
94+
bash Resources/scripts/wait.sh http://localhost:8001/api/v1/namespaces/pokeapi/services/pokeapi/proxy/api/v2/pal-park-area/5/
95+
- name: K8s wait for job
96+
run: |
97+
kubectl wait --timeout=600s --for=condition=complete job/load-graphql
98+
last_command=$(kubectl get job -o jsonpath='{.status.succeeded}' load-graphql)
99+
test "$last_command" -eq 1
100+
- name: Get GQL output
101+
run: kubectl logs jobs/load-graphql

.github/workflows/kustomize.yml

Lines changed: 0 additions & 50 deletions
This file was deleted.

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,12 @@ hasura-get-anon-schema: # Dumps GraphQL schema
116116
kustomize-apply: # (Kustomize) Run kubectl apply -k on the connected k8s cluster
117117
kubectl apply -k Resources/k8s/kustomize/base/
118118

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

122+
kustomize-local-apply: # (Kustomize) Run kubectl apply -k on the connected k8s cluster using the locally available pokeapi/pokeapi:local
123+
kubectl apply -k Resources/k8s/kustomize/local/
124+
122125
k8s-migrate: # (k8s) Run any pending migrations
123126
kubectl exec --namespace pokeapi deployment/pokeapi -- python manage.py migrate ${docker_config}
124127

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
ADMINS=PokeAPI,[email protected]
22
BASE_URL=http://localhost/
3+
POKEAPI_CHECKOUT_REF=master

Resources/k8s/kustomize/base/deployments/graphql-deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ spec:
2525
done;
2626
containers:
2727
- name: graphql-engine
28-
image: hasura/graphql-engine:v2.16.1
28+
image: hasura/graphql-engine:v2.36.4
2929
ports:
3030
- containerPort: 8080
3131
env:

Resources/k8s/kustomize/base/deployments/pokeapi-deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ spec:
2626
containers:
2727
- name: pokeapi
2828
image: pokeapi/pokeapi:master
29-
imagePullPolicy: Always
29+
imagePullPolicy: IfNotPresent
3030
ports:
3131
- containerPort: 8080
3232
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.

Resources/k8s/kustomize/base/jobs/load-graphql.yaml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,17 @@ spec:
2525
secretKeyRef:
2626
name: graphql-env-secret
2727
key: HASURA_GRAPHQL_ADMIN_SECRET
28+
- name: POKEAPI_CHECKOUT_REF
29+
valueFrom:
30+
configMapKeyRef:
31+
name: pokeapi-configmap
32+
key: POKEAPI_CHECKOUT_REF
2833
command: ["sh", "-c"]
2934
args:
30-
- apt-get update &&
31-
apt-get install -y git curl &&
32-
curl -L https://github.com/hasura/graphql-engine/raw/stable/cli/get.sh | bash &&
33-
hasura update-cli --version v2.0.8 &&
35+
- apt-get update && apt-get install -y curl git &&
36+
curl -L https://github.com/hasura/graphql-engine/raw/stable/cli/get.sh | VERSION=v2.36.4 bash &&
37+
cd /tmp &&
3438
git clone https://github.com/PokeAPI/pokeapi.git &&
3539
cd pokeapi &&
36-
git checkout staging &&
40+
(git checkout $(POKEAPI_CHECKOUT_REF) || git checkout master) &&
3741
hasura md apply --endpoint http://graphql:8080 --project graphql --admin-secret $(HASURA_GRAPHQL_ADMIN_SECRET)

Resources/k8s/kustomize/base/kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace: pokeapi
55

66
configMapGenerator:
77
- name: pokeapi-configmap
8-
files:
8+
envs:
99
- config/pokeapi.env
1010

1111
secretGenerator:

0 commit comments

Comments
 (0)