Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use local image when testing k8s #1028

Merged
merged 28 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,12 @@ 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 ${docker_config}

Expand Down
1 change: 1 addition & 0 deletions Resources/k8s/kustomize/base/config/pokeapi.env.sample
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
ADMINS=PokeAPI,[email protected]
BASE_URL=http://localhost/
POKEAPI_CHECKOUT_REF=master
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.16.1
image: hasura/graphql-engine:v2.36.4
ports:
- containerPort: 8080
env:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ spec:
containers:
- name: pokeapi
image: pokeapi/pokeapi:master
imagePullPolicy: Always
imagePullPolicy: IfNotPresent
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.
Expand Down
14 changes: 9 additions & 5 deletions Resources/k8s/kustomize/base/jobs/load-graphql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ spec:
secretKeyRef:
name: graphql-env-secret
key: HASURA_GRAPHQL_ADMIN_SECRET
- name: POKEAPI_CHECKOUT_REF
valueFrom:
configMapKeyRef:
name: pokeapi-configmap
key: POKEAPI_CHECKOUT_REF
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.8 &&
- apt-get update && apt-get install -y curl git &&
curl -L https://github.com/hasura/graphql-engine/raw/stable/cli/get.sh | VERSION=v2.36.4 bash &&
cd /tmp &&
git clone https://github.com/PokeAPI/pokeapi.git &&
cd pokeapi &&
git checkout staging &&
(git checkout $(POKEAPI_CHECKOUT_REF) || git checkout master) &&
hasura md apply --endpoint http://graphql:8080 --project graphql --admin-secret $(HASURA_GRAPHQL_ADMIN_SECRET)
2 changes: 1 addition & 1 deletion Resources/k8s/kustomize/base/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace: pokeapi

configMapGenerator:
- name: pokeapi-configmap
files:
envs:
- config/pokeapi.env

secretGenerator:
Expand Down
9 changes: 9 additions & 0 deletions Resources/k8s/kustomize/local/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization

bases:
- ../base

images:
- name: pokeapi/pokeapi
newTag: local
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ services:
- ./Resources/nginx/ssl:/ssl:ro
- graphql_cache:/tmp/cache
graphql-engine:
image: hasura/graphql-engine:v2.36.1-ce
image: hasura/graphql-engine:v2.36.4
ports:
- "8080:8080"
depends_on:
Expand Down