diff --git a/templates/node-service/content/Dockerfile b/templates/node-service/content/Dockerfile index 984ef66..4f82e57 100644 --- a/templates/node-service/content/Dockerfile +++ b/templates/node-service/content/Dockerfile @@ -1,9 +1,9 @@ -FROM alpine:3.20.0 as builder +FROM alpine:3 as builder RUN apk add --no-cache nodejs npm COPY package*.json ./ RUN npm install --only=prod -FROM alpine:3.20.0 +FROM alpine:3 RUN apk add --no-cache nodejs COPY --from=builder /node_modules ./node_modules COPY index.js index.js diff --git a/templates/podinfo-example/content/.gitignore b/templates/podinfo-example/content/.gitignore index e3ec6e1..6da8838 100644 --- a/templates/podinfo-example/content/.gitignore +++ b/templates/podinfo-example/content/.gitignore @@ -1,2 +1,4 @@ .score-compose/ -compose.yaml \ No newline at end of file +compose.yaml +.score-k8s/ +manifests.yaml \ No newline at end of file diff --git a/templates/podinfo-example/content/Makefile b/templates/podinfo-example/content/Makefile index 9f2d425..65e59cd 100644 --- a/templates/podinfo-example/content/Makefile +++ b/templates/podinfo-example/content/Makefile @@ -37,4 +37,51 @@ compose-test: compose-up ## Delete the containers running via compose down. .PHONY: compose-down compose-down: - docker compose down -v --remove-orphans || true \ No newline at end of file + docker compose down -v --remove-orphans || true + +.score-k8s/state.yaml: + score-k8s init \ + --no-sample + +manifests.yaml: score.yaml .score-k8s/state.yaml Makefile + score-k8s generate score.yaml \ + --image ${CONTAINER_IMAGE} + +## Create a local Kind cluster. +.PHONY: kind-create-cluster +kind-create-cluster: + ./scripts/setup-kind-cluster.sh + +## Load the local container image in the current Kind cluster. +.PHONY: kind-load-image +kind-load-image: + kind load docker-image ${CONTAINER_IMAGE} + +NAMESPACE ?= default +## Generate a manifests.yaml file from the score spec, deploy it to Kubernetes and wait for the Pods to be Ready. +.PHONY: k8s-up +k8s-up: manifests.yaml + kubectl apply \ + -f manifests.yaml \ + -n ${NAMESPACE} + kubectl wait deployments/${WORKLOAD_NAME} \ + -n ${NAMESPACE} \ + --for condition=Available \ + --timeout=90s + kubectl wait pods \ + -n ${NAMESPACE} \ + -l app.kubernetes.io/name=${WORKLOAD_NAME} \ + --for condition=Ready \ + --timeout=90s + +## Expose the container deployed in Kubernetes via port-forward. +.PHONY: k8s-test +k8s-test: k8s-up + curl $$(score-k8s resources get-outputs dns.default#${WORKLOAD_NAME}.dns --format '{{ .host }}') + +## Delete the deployment of the local container in Kubernetes. +.PHONY: k8s-down +k8s-down: + kubectl delete \ + -f manifests.yaml \ + -n ${NAMESPACE} \ No newline at end of file diff --git a/templates/podinfo-example/content/scripts/setup-kind-cluster.sh b/templates/podinfo-example/content/scripts/setup-kind-cluster.sh new file mode 100755 index 0000000..7e9bb72 --- /dev/null +++ b/templates/podinfo-example/content/scripts/setup-kind-cluster.sh @@ -0,0 +1,35 @@ +#!/bin/bash +set -o errexit + +cat <