Skip to content

Commit

Permalink
Merge pull request #4 from Humanitec-DemoOrg/score-k8s
Browse files Browse the repository at this point in the history
`score-k8s`
  • Loading branch information
mathieu-benoit authored Sep 11, 2024
2 parents 1f0380e + 2d7b37a commit 25c1ab4
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions .devcontainer/installMoreTools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 29 additions & 3 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -40,4 +40,30 @@ jobs:
version: ${{ env.SCORE_COMPOSE_VERSION }}
- name: make compose-test
run: |
make compose-test
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.score-compose/*
!.score-compose/00-service.provisioners.yaml
compose.yaml
.score-k8s/*
!.score-k8s/00-service.provisioners.yaml
manifests.yaml
7 changes: 7 additions & 0 deletions .score-k8s/00-service.provisioners.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
46 changes: 46 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
19 changes: 15 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 35 additions & 0 deletions scripts/setup-kind-cluster.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash
set -o errexit

cat <<EOF | kind create cluster --config=-
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
extraPortMappings:
- containerPort: 31000
hostPort: 80
protocol: TCP
EOF

kubectl apply \
-f https://github.com/kubernetes-sigs/gateway-api/releases/download/v1.1.0/standard-install.yaml

helm install ngf oci://ghcr.io/nginxinc/charts/nginx-gateway-fabric \
--create-namespace \
-n nginx-gateway \
--set service.type=NodePort \
--set-json 'service.ports=[{"port":80,"nodePort":31000}]'

kubectl apply -f - <<EOF
apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
name: default
spec:
gatewayClassName: nginx
listeners:
- name: http
port: 80
protocol: HTTP
EOF

0 comments on commit 25c1ab4

Please sign in to comment.