Skip to content

Commit

Permalink
Merge pull request #18 from score-spec/optimize-makefile
Browse files Browse the repository at this point in the history
Optimize Makefile
  • Loading branch information
mathieu-benoit authored Apr 19, 2024
2 parents 4f99963 + 59f4a88 commit 3f6a37d
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 22 deletions.
13 changes: 4 additions & 9 deletions .github/workflows/run-tests-on-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ jobs:
file: score-compose
token: ${{ secrets.GITHUB_TOKEN }}
version: ${{ env.SCORE_COMPOSE_VERSION }}
- name: make score-compose
- name: make compose.yaml
run: |
make score-compose
make compose.yaml
- name: make compose-up
run: |
make compose-up
- name: make compose-test
run: |
sleep 10
make compose-test
- name: create kind cluster
run: |
Expand All @@ -39,17 +38,13 @@ jobs:
file: score-helm
token: ${{ secrets.GITHUB_TOKEN }}
version: ${{ env.SCORE_HELM_VERSION }}
- name: make score-helm
- name: make values.yaml
run: |
make score-helm
make values.yaml
- name: make k8s-up
id: helm-install
run: |
make k8s-up
kubectl wait \
--for=condition=available \
--timeout=30s \
deployment/${{ env.WORKLOAD_NAME }}
- name: catch helm install errors
if: ${{ failure() && steps.helm-install.outcome == 'failure' }}
run: |
Expand Down
69 changes: 56 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,33 +1,64 @@
# 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:

include .env

score-compose:
score-compose init
CONTAINER_IMAGE = hello-world:test

compose.yaml: score.yaml
score-compose init \
--no-sample
score-compose generate score.yaml \
--build=hello-world=. \
--build 'hello-world={"context":".","tags":["${CONTAINER_IMAGE}"]}' \
--override-property containers.hello-world.variables.MESSAGE="Hello, Compose!"

compose-up:
docker compose up --build -d
## 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

compose-test:
## Generate a compose.yaml file from the score spec, launch it and test (curl) the exposed container.
.PHONY: compose-test
compose-test: compose-up
sleep 5
curl localhost:8080

## Delete the containers running via compose down.
.PHONY: compose-down
compose-down:
docker compose down -v --remove-orphans
docker compose down -v --remove-orphans || true

score-helm:
values.yaml: score.yaml
score-helm run \
-f score.yaml \
-p containers.hello-world.image=sample-score-app-hello-world \
-p containers.hello-world.image=${CONTAINER_IMAGE} \
-p containers.hello-world.variables.MESSAGE="Hello, Kubernetes!" \
-p containers.hello-world.variables.DB_PASSWORD=${DB_PASSWORD} \
-p containers.hello-world.variables.DB_USER=${DB_USERNAME} \
-p containers.hello-world.variables.DB_DATABASE=${DB_NAME} \
-p containers.hello-world.variables.DB_HOST=postgres \
-o values.yaml

## 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
k8s-up:
.PHONY: k8s-up
k8s-up: values.yaml
$(MAKE) k8s-down || true
$(MAKE) compose-down || true
kubectl create deployment postgres \
--image=postgres:alpine \
-n ${NAMESPACE}
Expand All @@ -44,11 +75,23 @@ k8s-up:
--repo https://score-spec.github.io/score-helm-charts \
workload \
--values values.yaml \
--set containers.hello-world.image.name=registry.humanitec.io/public/sample-score-app:latest
--set containers.hello-world.image.name=${CONTAINER_IMAGE}

k8s-test:
kubectl port-forward service/hello-world 8080:8080
## Expose the container deployed in Kubernetes via port-forward.
.PHONY: k8s-test
k8s-test: k8s-up
kubectl wait pods \
-n ${NAMESPACE} \
-l app.kubernetes.io/name=hello-world \
--for condition=Ready \
--timeout=90s
kubectl port-forward \
-n ${NAMESPACE} \
service/hello-world \
8080:8080

## Delete the the deployment of the local container in Kubernetes.
.PHONY: k8s-down
k8s-down:
kubectl delete deployment postgres \
-n ${NAMESPACE}
Expand Down

0 comments on commit 3f6a37d

Please sign in to comment.