Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize Makefile #120

Merged
merged 3 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 11 additions & 27 deletions .github/workflows/open-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ jobs:
file: score-compose
token: ${{ secrets.GITHUB_TOKEN }}
version: ${{ env.SCORE_COMPOSE_VERSION }}
- name: score-compose
- name: make compose.yaml
run: |
make score-compose
make compose.yaml
cat <<EOF > compose.override.yaml
services:
${{ env.WORKLOAD_NAME }}-${{ env.CONTAINER_NAME }}:
Expand All @@ -48,48 +48,31 @@ jobs:
- ALL
user: "1000"
EOF
- name: compose-up
- name: make compose-up
run: |
make compose-up
- name: compose-test
- name: make compose-test
run: |
sleep 10
make compose-test
- name: create kind cluster
run: |
kind create cluster
- name: prepare container image
- name: make kind-load-image
run: |
docker tag sail-sharp-${{ env.WORKLOAD_NAME }}-${{ env.CONTAINER_NAME }} ${{ env.IMAGE_NAME }}:${{ env.ENVIRONMENT_ID }}
kind load docker-image ${{ env.IMAGE_NAME }}:${{ env.ENVIRONMENT_ID }}
make kind-load-image
- name: install score-helm
uses: score-spec/setup-score@v2
with:
file: score-helm
token: ${{ secrets.GITHUB_TOKEN }}
version: ${{ env.SCORE_HELM_VERSION }}
- name: generate helm values file
- name: make values.yaml
run: |
score-helm run \
-f score/score.yaml \
-o ${{ env.WORKLOAD_NAME }}-values.yaml
- name: helm install
make values.yaml
- name: make k8s-up
id: helm-install
run: |
helm repo add \
score-helm-charts \
https://score-spec.github.io/score-helm-charts
helm install \
${{ env.WORKLOAD_NAME }} \
score-helm-charts/workload \
--values ${{ env.WORKLOAD_NAME }}-values.yaml \
--set containers.${{ env.CONTAINER_NAME }}.image.name=${{ env.IMAGE_NAME }}:${{ env.ENVIRONMENT_ID }} \
--wait \
--timeout=30s
kubectl wait \
--for=condition=available \
--timeout=30s \
deployment/${{ env.WORKLOAD_NAME }}
make k8s-up
- name: catch helm install errors
if: ${{ failure() && steps.helm-install.outcome == 'failure' }}
run: |
Expand Down Expand Up @@ -119,6 +102,7 @@ jobs:
|| true
- name: push the container to gar
run: |
docker tag ${{ env.CONTAINER_NAME }}:test ${{ env.IMAGE_NAME }}:${{ env.ENVIRONMENT_ID }}
docker push \
${{ env.IMAGE_NAME }}:${{ env.ENVIRONMENT_ID }}
deploy-preview-env:
Expand Down
6 changes: 2 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
.score-compose/99-default.provisioners.yaml
.score-compose/state.yaml
.score-compose/mounts/routing-ToNP4f/nginx.conf
.score-compose/mounts/routing-opq6wX/nginx.conf
.score-compose/
compose.yaml
values.yaml
60 changes: 47 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,41 +1,75 @@
score-compose:
# Disable all the default make stuff
MAKEFLAGS += --no-builtin-rules
.SUFFIXES:

## Display a list of the documented make targets
.PHONY: help
mathieu-benoit marked this conversation as resolved.
Show resolved Hide resolved
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:

CONTAINER_IMAGE = my-sample-container:test
compose.yaml: score/score.yaml
score-compose init \
--no-sample
score-compose generate score/score.yaml \
--build my-sample-container=app/ \
--build 'my-sample-container={"context":"app/","tags":["${CONTAINER_IMAGE}"]}' \
--override-property containers.my-sample-container.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/score.yaml
score-helm run \
-f score.yaml \
-p containers.my-sample-container.image=sail-sharp-my-sample-app-my-sample-app \
-f score/score.yaml \
-p containers.my-sample-container.image=${CONTAINER_IMAGE} \
-p containers.my-sample-container.variables.MESSAGE="Hello, Kubernetes!" \
-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:
## Deploy the local container in Kubernetes.
.PHONY: k8s-up
k8s-up: values.yaml
$(MAKE) k8s-down || true
$(MAKE) compose-down || true
helm upgrade \
-n ${NAMESPACE} \
--install \
--create-namespace \
my-sample-workload \
--repo https://score-spec.github.io/score-helm-charts \
workload \
--values values.yaml \
--set containers.my-sample-container.image.name=registry.humanitec.io/public/sample-score-app:latest
--values values.yaml

k8s-test:
## Expose the container deployed in Kubernetes via port-forward.
.PHONY: k8s-test
k8s-test: k8s-up
sleep 5
kubectl port-forward service/my-sample-workload 8080:8080

## Delete the the deployment of the local container in Kubernetes.
.PHONY: k8s-down
k8s-down:
helm uninstall \
-n ${NAMESPACE} \
Expand Down
Loading