-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMakefile
More file actions
125 lines (106 loc) · 4.7 KB
/
Makefile
File metadata and controls
125 lines (106 loc) · 4.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# Disable all the default make stuff
MAKEFLAGS += --no-builtin-rules
.SUFFIXES:
## Display a list of the documented make targets
.PHONY: help
help:
@echo Documented Make targets:
@perl -e 'undef $$/; while (<>) { while ($$_ =~ /## (.*?)(?:\n# .*)*\n.PHONY:\s+(\S+).*/mg) { printf "\033[36m%-30s\033[0m %s\n", $$2, $$1 } }' $(MAKEFILE_LIST) | sort
.PHONY: .FORCE
.FORCE:
WORKLOAD_NAME = my-sample-workload
CONTAINER_NAME = my-sample-container
CONTAINER_IMAGE = ${WORKLOAD_NAME}:test
## Manually build the container image.
.PHONY: build-container
build-container:
docker build -t ${CONTAINER_IMAGE} --sbom=true --provenance=true app/
## Manually buildx the container image.
.PHONY: buildx-container
buildx-container:
docker buildx build -t ${CONTAINER_IMAGE} --load --attest type=provenance,mode=max app/
.score-compose/state.yaml:
score-compose init \
--no-sample \
--patch-templates https://raw.githubusercontent.com/score-spec/community-patchers/refs/heads/main/score-compose/unprivileged.tpl
compose.yaml: score/score.yaml .score-compose/state.yaml Makefile
score-compose generate score/score.yaml \
--build '${CONTAINER_NAME}={"context":"app/","tags":["${CONTAINER_IMAGE}"]}' \
--override-property containers.${CONTAINER_NAME}.variables.MESSAGE="Hello, Compose!"
## Generate a compose.yaml file from the score spec and launch it.
.PHONY: compose-up
compose-up: compose.yaml
docker compose up --build -d --remove-orphans --wait
sleep 5
## Generate a compose.yaml file from the score spec, launch it and test (curl) the exposed container.
.PHONY: compose-test
compose-test: compose-up
docker ps
curl $$(score-compose resources get-outputs dns.default#${WORKLOAD_NAME}.dns --format '{{ .host }}:8080')
curl $$(score-compose resources get-outputs dns.default#${WORKLOAD_NAME}.dns --format '{{ .host }}:8080') | grep "Hello, Compose! on amd64."
curl $$(score-compose resources get-outputs dns.default#${WORKLOAD_NAME}.dns --format '{{ .host }}:8080/healthz')
curl $$(score-compose resources get-outputs dns.default#${WORKLOAD_NAME}.dns --format '{{ .host }}:8080/healthz') | grep "Healthy"
## Delete the containers running via compose down.
.PHONY: compose-down
compose-down:
docker compose down -v --remove-orphans || true
.score-k8s/state.yaml:
score-k8s init \
--no-sample \
--patch-templates https://raw.githubusercontent.com/score-spec/community-patchers/refs/heads/main/score-k8s/unprivileged.tpl \
--patch-templates https://raw.githubusercontent.com/score-spec/community-patchers/refs/heads/main/score-k8s/service-account.tpl
manifests.yaml: score/score.yaml .score-k8s/state.yaml Makefile
score-k8s generate score/score.yaml \
--image ${CONTAINER_IMAGE} \
--override-property containers.${CONTAINER_NAME}.variables.MESSAGE="Hello, Kubernetes!"
## 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 get pods -n ${NAMESPACE}
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 }}')
curl $$(score-k8s resources get-outputs dns.default#${WORKLOAD_NAME}.dns --format '{{ .host }}') | grep "Hello, Kubernetes! on amd64."
curl $$(score-k8s resources get-outputs dns.default#${WORKLOAD_NAME}.dns --format '{{ .host }}/healthz')
curl $$(score-k8s resources get-outputs dns.default#${WORKLOAD_NAME}.dns --format '{{ .host }}/healthz') | grep "Healthy"
## Delete the deployment of the local container in Kubernetes.
.PHONY: k8s-down
k8s-down:
kubectl delete \
-f manifests.yaml \
-n ${NAMESPACE}
## Generate catalog-info.yaml for Backstage.
.PHONY: generate-catalog-info
generate-catalog-info:
score-k8s init \
--no-sample \
--patch-templates https://raw.githubusercontent.com/score-spec/community-patchers/refs/heads/main/score-k8s/backstage-catalog-entities.tpl
score-k8s generate \
--namespace sail-sharp \
--generate-namespace \
--image ghcr.io/mathieu-benoit/my-sample-workload:latest \
score/score.yaml \
--output catalog-info.yaml
sed 's,$$GITHUB_REPO,mathieu-benoit/sail-sharp,g' -i catalog-info.yaml