Skip to content

Commit

Permalink
score-compose init|generate (#119)
Browse files Browse the repository at this point in the history
* Makefile

* make score-compose|compose-up|compose-test

* Fix compose.override

* app vs. workload vs. container

* Fix container image

* Fix container image

* Fix container image in helm

* Fix container name in Helm

* prepare container image for helm

* fix typo
  • Loading branch information
mathieu-benoit authored Apr 19, 2024
1 parent 4e81e67 commit f1eadf7
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 32 deletions.
35 changes: 13 additions & 22 deletions .github/workflows/open-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ env:
IMAGE_NAME: ${{ secrets.REGISTRY_LOCATION }}-docker.pkg.dev/${{ secrets.PROJECT_ID }}/${{ secrets.REGISTRY_NAME }}/${{ vars.APP_NAME }}
SCORE_COMPOSE_VERSION: 'latest'
SCORE_HELM_VERSION: 'latest'
WORKLOAD_NAME: my-sample-app
WORKLOAD_NAME: my-sample-workload
CONTAINER_NAME: my-sample-container
HUMCTL_VERSION: '0.21.0'
jobs:
build-run-test-push:
Expand All @@ -36,40 +37,30 @@ jobs:
file: score-compose
token: ${{ secrets.GITHUB_TOKEN }}
version: ${{ env.SCORE_COMPOSE_VERSION }}
- name: generate docker compose files
- name: score-compose
run: |
docker build -t ${{ env.IMAGE_NAME }}:${{ env.ENVIRONMENT_ID }} app/
score-compose run \
--build app/ \
-f score/score.yaml \
-o compose.yaml
make score-compose
cat <<EOF > compose.override.yaml
services:
${{ env.WORKLOAD_NAME }}:
image: ${{ env.IMAGE_NAME }}:${{ env.ENVIRONMENT_ID }}
${{ env.WORKLOAD_NAME }}-${{ env.CONTAINER_NAME }}:
read_only: true
cap_drop:
- ALL
user: "1000"
EOF
- name: build & run container
- name: compose-up
run: |
docker compose \
up \
--build \
-d \
--wait \
--wait-timeout 30
- name: test container
make compose-up
- name: compose-test
run: |
sleep 10
curl \
-s \
--connect-timeout 30 \
localhost:8080
make compose-test
- name: create kind cluster
run: |
kind create cluster
- name: prepare container 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 }}
- name: install score-helm
uses: score-spec/setup-score@v2
Expand All @@ -92,7 +83,7 @@ jobs:
${{ env.WORKLOAD_NAME }} \
score-helm-charts/workload \
--values ${{ env.WORKLOAD_NAME }}-values.yaml \
--set containers.${{ env.WORKLOAD_NAME }}.image.name=${{ env.IMAGE_NAME }}:${{ env.ENVIRONMENT_ID }} \
--set containers.${{ env.CONTAINER_NAME }}.image.name=${{ env.IMAGE_NAME }}:${{ env.ENVIRONMENT_ID }} \
--wait \
--timeout=30s
kubectl wait \
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.score-compose/99-default.provisioners.yaml
.score-compose/state.yaml
.score-compose/mounts/routing-ToNP4f/nginx.conf
.score-compose/mounts/routing-opq6wX/nginx.conf
compose.yaml
42 changes: 42 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
score-compose:
score-compose init \
--no-sample
score-compose generate score/score.yaml \
--build my-sample-container=app/ \
--override-property containers.my-sample-container.variables.MESSAGE="Hello, Compose!"

compose-up:
docker compose up --build -d

compose-test:
curl localhost:8080

compose-down:
docker compose down -v --remove-orphans

score-helm:
score-helm run \
-f score.yaml \
-p containers.my-sample-container.image=sail-sharp-my-sample-app-my-sample-app \
-p containers.my-sample-container.variables.MESSAGE="Hello, Kubernetes!" \
-o values.yaml

NAMESPACE ?= default
k8s-up:
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

k8s-test:
kubectl port-forward service/my-sample-workload 8080:8080

k8s-down:
helm uninstall \
-n ${NAMESPACE} \
my-sample-workload
2 changes: 1 addition & 1 deletion score/humanitec.score.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: humanitec.org/v1b1
profile: humanitec/default-module
spec:
containers:
my-sample-app:
my-sample-container:
env:
- name: POD_NAME
value: "${pod.metadata.name}"
Expand Down
4 changes: 2 additions & 2 deletions score/score-with-file-content-in-shared-values.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
apiVersion: score.dev/v1b1
metadata:
name: my-sample-app
name: my-sample-workload
containers:
my-sample-app:
my-sample-container:
image: .
resources:
limits:
Expand Down
4 changes: 2 additions & 2 deletions score/score-with-file-source.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
apiVersion: score.dev/v1b1
metadata:
name: my-sample-app
name: my-sample-workload
containers:
my-sample-app:
my-sample-container:
image: .
resources:
limits:
Expand Down
4 changes: 2 additions & 2 deletions score/score-with-shared-values.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
apiVersion: score.dev/v1b1
metadata:
name: my-sample-app
name: my-sample-workload
containers:
my-sample-app:
my-sample-container:
image: .
resources:
limits:
Expand Down
2 changes: 1 addition & 1 deletion score/score.deploy.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
apiVersion: config.humanitec.io/v1b1
kind: ScoreDeployConfig
workloads:
- name: my-sample-app/my-sample-app
- name: my-sample-app/my-sample-workload
specFile: ./score.yaml
extensionsFile: ./humanitec.score.yaml
4 changes: 2 additions & 2 deletions score/score.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
apiVersion: score.dev/v1b1
metadata:
name: my-sample-app
name: my-sample-workload
containers:
my-sample-app:
my-sample-container:
image: .
resources:
limits:
Expand Down

0 comments on commit f1eadf7

Please sign in to comment.