diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index dbcbad6..4972a52 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -4,7 +4,8 @@ "features": { "ghcr.io/devcontainers/features/docker-in-docker:2": { "moby": true, - "version": "latest" + "_comment": "cannot use latest for now because of this current issue: https://github.com/kubernetes-sigs/kind/issues/3696", + "version": "26.1.4" }, "ghcr.io/devcontainers/features/kubectl-helm-minikube:1": { "version": "latest", diff --git a/.devcontainer/installMoreTools.sh b/.devcontainer/installMoreTools.sh index f79a115..bed43af 100644 --- a/.devcontainer/installMoreTools.sh +++ b/.devcontainer/installMoreTools.sh @@ -9,6 +9,12 @@ tar -xvf score-compose_${SCORE_COMPOSE_VERSION}_linux_amd64.tar.gz chmod +x score-compose sudo mv score-compose /usr/local/bin +SCORE_K8S_VERSION=$(curl -sL https://api.github.com/repos/score-spec/score-k8s/releases/latest | jq -r .tag_name) +wget https://github.com/score-spec/score-k8s/releases/download/${SCORE_K8S_VERSION}/score-k8s_${SCORE_K8S_VERSION}_linux_amd64.tar.gz +tar -xvf score-k8s_${SCORE_K8S_VERSION}_linux_amd64.tar.gz +chmod +x score-k8s +sudo mv score-k8s /usr/local/bin + HUMCTL_VERSION=$(curl -sL https://api.github.com/repos/humanitec/cli/releases/latest | jq -r .tag_name) curl -fLO https://github.com/humanitec/cli/releases/download/${HUMCTL_VERSION}/cli_${HUMCTL_VERSION:1}_linux_amd64.tar.gz tar -xvf cli_${HUMCTL_VERSION:1}_linux_amd64.tar.gz diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 3096834..2ba4d09 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -9,7 +9,7 @@ jobs: strategy: matrix: apps: ["order", "product", "store-front", "makeline", "store-admin"] - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 env: HUMCTL_VERSION: '*' steps: @@ -26,7 +26,7 @@ jobs: --org ${{ secrets.HUMANITEC_ORG }} \ --strict score-compose: - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 env: SCORE_COMPOSE_VERSION: 'latest' steps: @@ -40,4 +40,30 @@ jobs: version: ${{ env.SCORE_COMPOSE_VERSION }} - name: make compose-test run: | - make compose-test \ No newline at end of file + make compose-test + score-k8s: + runs-on: ubuntu-24.04 + env: + SCORE_K8S_VERSION: 'latest' + steps: + - name: checkout code + uses: actions/checkout@v4 + - name: install score-k8s + uses: score-spec/setup-score@v3 + with: + file: score-k8s + token: ${{ secrets.GITHUB_TOKEN }} + version: ${{ env.SCORE_K8S_VERSION }} + - name: make kind-create-cluster + run: | + make kind-create-cluster + - name: make k8s-up + id: k8s-up + run: | + make k8s-up + - name: catch k8s-up errors + if: ${{ failure() && steps.k8s-up.outcome == 'failure' }} + run: | + kubectl get events + kubectl logs \ + -l app.kubernetes.io/name=store-admin \ No newline at end of file diff --git a/.gitignore b/.gitignore index 562b981..5659e25 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ .score-compose/* !.score-compose/00-service.provisioners.yaml compose.yaml +.score-k8s/* +!.score-k8s/00-service.provisioners.yaml +manifests.yaml \ No newline at end of file diff --git a/.score-k8s/00-service.provisioners.yaml b/.score-k8s/00-service.provisioners.yaml new file mode 100644 index 0000000..a8bc855 --- /dev/null +++ b/.score-k8s/00-service.provisioners.yaml @@ -0,0 +1,7 @@ +- uri: template://service-provisioners/static-service + type: service + init: | + name: {{ splitList "." .Id | last }} + outputs: | + {{ $w := (index .WorkloadServices .Init.name) }} + name: {{ $w.ServiceName | quote }} \ No newline at end of file diff --git a/Makefile b/Makefile index 35cda15..a51ed07 100644 --- a/Makefile +++ b/Makefile @@ -37,6 +37,52 @@ compose-test: compose-up compose-down: docker compose down -v --remove-orphans || true +.score-k8s/state.yaml: + score-k8s init \ + --no-sample + +manifests.yaml: apps/makeline/score.yaml apps/order/score.yaml apps/product/score.yaml apps/store-admin/score.yaml apps/store-front/score.yaml .score-k8s/state.yaml Makefile + score-k8s generate \ + apps/makeline/score.yaml \ + apps/order/score.yaml \ + apps/product/score.yaml \ + apps/store-admin/score.yaml \ + apps/store-front/score.yaml + +## Create a local Kind cluster. +.PHONY: kind-create-cluster +kind-create-cluster: + ./scripts/setup-kind-cluster.sh + +NAMESPACE ?= default +## Generate a manifests.yaml file from the score spec and apply it in Kubernetes. +.PHONY: k8s-up +k8s-up: manifests.yaml + kubectl apply \ + -f manifests.yaml \ + -n ${NAMESPACE} + kubectl wait deployments/store-front \ + -n ${NAMESPACE} \ + --for condition=Available \ + --timeout=90s + kubectl wait pods \ + -n ${NAMESPACE} \ + -l app.kubernetes.io/name=store-front \ + --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#store-front.dns --format '{{ .host }}') + +## Delete the deployment of the local container in Kubernetes. +.PHONY: k8s-down +k8s-down: + kubectl delete \ + -f manifests.yaml \ + -n ${NAMESPACE} + ## Deploy the workloads to Humanitec. .PHONY: humanitec-deploy humanitec-deploy: diff --git a/README.md b/README.md index 6db7394..3146e3b 100644 --- a/README.md +++ b/README.md @@ -6,13 +6,24 @@ Get the [Azure-Samples/aks-store-demo](https://github.com/Azure-Samples/aks-stor ![](https://github.com/Azure-Samples/aks-store-demo/raw/main/assets/demo-arch.png) -## Local deployment +## Local deployment with Docker Compose -You will need to [install `score-compose`](https://docs.score.dev/docs/score-implementation/score-compose/) locally. - -Deploy locally: +Deploy and test locally with Docker compose: ```bash make compose-up + +make compose-test +``` + +## Local deployment with Kind cluster + +Deploy and test locally with Kind cluster: +```bash +make kind-create-cluster + +make k8s-up + +make k8s-test ``` ## Humanitec deployment diff --git a/scripts/setup-kind-cluster.sh b/scripts/setup-kind-cluster.sh new file mode 100755 index 0000000..7e9bb72 --- /dev/null +++ b/scripts/setup-kind-cluster.sh @@ -0,0 +1,35 @@ +#!/bin/bash +set -o errexit + +cat <