diff --git a/.github/workflows/docker-k8s.yml b/.github/workflows/docker-k8s.yml index 691612524..628790ff2 100644 --- a/.github/workflows/docker-k8s.yml +++ b/.github/workflows/docker-k8s.yml @@ -66,10 +66,11 @@ jobs: - name: Lint k8s run: (cd Resources/k8s/kustomize && yamllint .) - name: Create k8s Kind Cluster - uses: helm/kind-action@v1.12.0 + uses: helm/kind-action@v1.13.0 with: cluster_name: pokeapi - version: v0.21.0 + config: Resources/kind/config-ga.yaml + version: v0.31.0 - name: Create deployment configuration run: | cp Resources/k8s/kustomize/base/secrets/postgres.env.sample Resources/k8s/kustomize/base/secrets/postgres.env @@ -79,7 +80,7 @@ jobs: run: kind load docker-image pokeapi/pokeapi:local --name pokeapi - name: K8s Apply run: | - make kustomize-local-apply + make kustomize-ga-apply kubectl proxy & sleep 1 bash Resources/scripts/wait.sh http://localhost:8001/api/v1/namespaces/pokeapi/services/pokeapi/proxy/api/v2/ diff --git a/Makefile b/Makefile index 8f1235877..3f772660d 100755 --- a/Makefile +++ b/Makefile @@ -133,6 +133,9 @@ kustomize-staging-apply: # (Kustomize) Run kubectl apply -k on the connected k8 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/ +kustomize-ga-apply: # (Kustomize) Run kubectl apply -k on the connected k8s cluster using the Github Actions config (share host data with the cluster) + kubectl apply -k Resources/k8s/kustomize/ga/ + k8s-migrate: # (k8s) Run any pending migrations kubectl exec --namespace pokeapi deployment/pokeapi -- python manage.py migrate ${docker_config} diff --git a/Resources/k8s/kustomize/base/deployments/pokeapi-deployment.yaml b/Resources/k8s/kustomize/base/deployments/pokeapi-deployment.yaml index 38cb2d4fc..c039dfeb2 100644 --- a/Resources/k8s/kustomize/base/deployments/pokeapi-deployment.yaml +++ b/Resources/k8s/kustomize/base/deployments/pokeapi-deployment.yaml @@ -5,7 +5,7 @@ metadata: labels: component: pokeapi spec: - replicas: 2 + replicas: 1 selector: matchLabels: component: pokeapi @@ -29,17 +29,11 @@ spec: args: - apk add --update git && git clone --depth=1 --single-branch --branch=master --recurse-submodules --shallow-submodules https://github.com/PokeAPI/pokeapi.git && - mv /code/pokeapi/data/v2/cries/* /tmp/cries/ && - mv /code/pokeapi/data/v2/csv/* /tmp/csv/ && - mv /code/pokeapi/data/v2/sprites/* /tmp/sprites/ + mv /code/pokeapi/data/v2/* /tmp/ workingDir: /code volumeMounts: - - mountPath: /tmp/cries - name: cries-data-share - - mountPath: /tmp/csv - name: csv-data-share - - mountPath: /tmp/sprites - name: sprites-data-share + - mountPath: /tmp/ + name: data-share containers: - name: pokeapi image: pokeapi/pokeapi:master @@ -69,12 +63,8 @@ spec: - configMapRef: name: pokeapi-configmap volumeMounts: - - mountPath: /code/data/v2/cries - name: cries-data-share - - mountPath: /code/data/v2/csv - name: csv-data-share - - mountPath: /code/data/v2/sprites - name: sprites-data-share + - mountPath: /code/data/v2/ + name: data-share resources: {} readinessProbe: periodSeconds: 5 @@ -89,9 +79,5 @@ spec: path: /api/v2/ port: 8080 volumes: - - name: cries-data-share - emptyDir: {} - - name: csv-data-share - emptyDir: {} - - name: sprites-data-share + - name: data-share emptyDir: {} diff --git a/Resources/k8s/kustomize/ga/kustomization.yaml b/Resources/k8s/kustomize/ga/kustomization.yaml new file mode 100644 index 000000000..0ab7404d3 --- /dev/null +++ b/Resources/k8s/kustomize/ga/kustomization.yaml @@ -0,0 +1,11 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +resources: + - ../local + +patches: + - path: pokeapi-deployment-patch.yaml + target: + kind: Deployment + labelSelector: component=pokeapi diff --git a/Resources/k8s/kustomize/ga/pokeapi-deployment-patch.yaml b/Resources/k8s/kustomize/ga/pokeapi-deployment-patch.yaml new file mode 100644 index 000000000..80742c585 --- /dev/null +++ b/Resources/k8s/kustomize/ga/pokeapi-deployment-patch.yaml @@ -0,0 +1,23 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: pokeapi +spec: + template: + spec: + initContainers: + - name: data-download + image: alpine:3.21.2 + command: ['ls'] + args: ['/tmp/csv'] + containers: + - name: pokeapi + volumeMounts: + - mountPath: /code/data/v2/ + name: data-share + volumes: + - name: data-share + hostPath: + path: /code/pokeapi/data/v2/ + emptyDir: + $patch: delete diff --git a/Resources/kind/config-ga.yaml b/Resources/kind/config-ga.yaml new file mode 100644 index 000000000..7f61a41c4 --- /dev/null +++ b/Resources/kind/config-ga.yaml @@ -0,0 +1,7 @@ +apiVersion: kind.x-k8s.io/v1alpha4 +kind: Cluster +nodes: + - role: control-plane + extraMounts: + - hostPath: /home/runner/work/pokeapi/pokeapi/data/v2/ + containerPath: /code/pokeapi/data/v2/ \ No newline at end of file diff --git a/data/v2/sprites b/data/v2/sprites index 96631ea77..4bcd17051 160000 --- a/data/v2/sprites +++ b/data/v2/sprites @@ -1 +1 @@ -Subproject commit 96631ea777d78ba608c86676f9f8ed8ae018ce28 +Subproject commit 4bcd17051efacd74966305ac87a0330b6131259a