Skip to content

Commit 29865e2

Browse files
authored
feat: added implementation example (#1)
* feat: added implementation example Signed-off-by: Ben Meier <ben.meier@humanitec.com> * fix: add resolves resource params to the output spec Signed-off-by: Ben Meier <ben.meier@humanitec.com> * fix: test Signed-off-by: Ben Meier <ben.meier@humanitec.com> * chore: expand readme example Signed-off-by: Ben Meier <ben.meier@humanitec.com> --------- Signed-off-by: Ben Meier <ben.meier@humanitec.com>
1 parent ce7a7ef commit 29865e2

15 files changed

Lines changed: 1190 additions & 1 deletion

File tree

.github/workflows/ci.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: CI
2+
on:
3+
push:
4+
pull_request:
5+
jobs:
6+
test:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: checkout
10+
uses: actions/checkout@v4
11+
- name: setup-go
12+
uses: actions/setup-go@v5
13+
with:
14+
go-version-file: go.mod
15+
- name: test
16+
run: go run gotest.tools/gotestsum@latest --format github-actions
17+
- name: lint
18+
uses: golangci/golangci-lint-action@v6
19+
with:
20+
version: latest

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.score-implementation-sample/
2+
score.yaml
3+
.idea/
4+
manifests.yaml

README.md

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,85 @@
11
# score-implementation-sample
2-
score-implementation-sample
2+
3+
This score-implementation-sample is a template repo for creating a new Score implementation following the conventions laid out in [Score Compose](https://github.com/score-spec/score-compose) and [Score K8s](https://github.com/score-spec/score-k8s).
4+
5+
This sample comes complete with:
6+
7+
1. CLI skeleton including `init` and`generate` subcommands
8+
- `generate --overrides-file` and `generate --override-property` for applying Score overrides before conversion
9+
- `generate --image` for overriding the workload image before conversion.
10+
- Full placeholder support for `${metadata...}` and `${resource...}` expressions in the workload variables, files, and resource params.
11+
2. State directory storage in `.score-implementation-sample/`
12+
3. `TODO` in place of resource provisioning and workload conversion
13+
14+
To adapt this for your target platform, you should:
15+
16+
1. Rename the go module by replacing all instances of `github.com/score-spec/score-implementation-sample` with your own module name.
17+
2. Replace all other instances of `score-implementation-sample` with your own `score-xyz` name including renaming the `cmd/score-implementation-sample` directory.
18+
3. Run the tests with `go test -v ./...`.
19+
4. Change the `TODO` in [provisioning.go](./internal/provisioners/provisioning.go) to provision resources and set the resource outputs. The existing implementation resolves placeholders in the resource params but does not set any resource outputs.
20+
5. Change the `TODO` in [convert.go](./internal/convert/convert.go) to convert workloads into the target manifest form. The existing implementation resolves placeholders in the variables and files sections but just returns the workload spec as yaml content in the manifests.
21+
22+
Good luck, and have fun!
23+
24+
## Demo
25+
26+
Write the following to `score.yaml`:
27+
28+
```yaml
29+
apiVersion: score.dev/v1b1
30+
metadata:
31+
name: example
32+
containers:
33+
main:
34+
image: stefanprodan/podinfo
35+
variables:
36+
key: value
37+
dynamic: ${metadata.name}
38+
files:
39+
- target: /somefile
40+
content: |
41+
${metadata.name}
42+
resources:
43+
thing:
44+
type: something
45+
params:
46+
x: ${metadata.name}
47+
```
48+
49+
And run:
50+
51+
```
52+
go run ./ init
53+
go run ./ generate score.yaml
54+
```
55+
56+
The output `manifests.yaml` contains the following which indicates:
57+
58+
1. Resources were "provisioned" and their parameters interpolated.
59+
2. Workloads were converted by copying them to the output manifests with variables or files interpolated as required.
60+
61+
```yaml
62+
apiVersion: score.dev/v1b1
63+
metadata:
64+
name: example
65+
containers:
66+
main:
67+
files:
68+
- content: |
69+
example
70+
noExpand: true
71+
target: /somefile
72+
image: stefanprodan/podinfo
73+
variables:
74+
dynamic: example
75+
key: value
76+
resources:
77+
thing:
78+
params:
79+
x: example
80+
type: something
81+
```
82+
83+
## A note on licensing
84+
85+
Most code files here retain the Apache licence header since they were copied or adapted from the reference `score-compose` which is Apache licensed. Any modifications to these files should retain the Apache licence and attribution.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright 2024 Humanitec
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package main
16+
17+
import (
18+
"fmt"
19+
"os"
20+
21+
"github.com/score-spec/score-implementation-sample/internal/command"
22+
)
23+
24+
func main() {
25+
if err := command.Execute(); err != nil {
26+
_, _ = fmt.Fprintln(os.Stderr, "Error: "+err.Error())
27+
os.Exit(1)
28+
}
29+
}

go.mod

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module github.com/score-spec/score-implementation-sample
2+
3+
go 1.23.0
4+
5+
toolchain go1.23.2
6+
7+
require (
8+
github.com/imdario/mergo v1.0.1
9+
github.com/score-spec/score-go v1.8.3
10+
github.com/spf13/cobra v1.8.1
11+
github.com/spf13/pflag v1.0.5
12+
github.com/stretchr/testify v1.9.0
13+
gopkg.in/yaml.v3 v3.0.1
14+
)
15+
16+
require (
17+
dario.cat/mergo v1.0.1 // indirect
18+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
19+
github.com/inconshreveable/mousetrap v1.1.0 // indirect
20+
github.com/kr/pretty v0.3.1 // indirect
21+
github.com/mitchellh/mapstructure v1.5.0 // indirect
22+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
23+
github.com/rogpeppe/go-internal v1.12.0 // indirect
24+
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 // indirect
25+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
26+
)
27+
28+
replace github.com/imdario/mergo => dario.cat/mergo v1.0.0

go.sum

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk=
2+
dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
3+
dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s=
4+
dario.cat/mergo v1.0.1/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk=
5+
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
6+
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
7+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
8+
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
9+
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
10+
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
11+
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
12+
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
13+
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
14+
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
15+
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
16+
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
17+
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
18+
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
19+
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
20+
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
21+
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
22+
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
23+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
24+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
25+
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
26+
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
27+
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
28+
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
29+
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 h1:lZUw3E0/J3roVtGQ+SCrUrg3ON6NgVqpn3+iol9aGu4=
30+
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1/go.mod h1:uToXkOrWAZ6/Oc07xWQrPOhJotwFIyu2bBVN41fcDUY=
31+
github.com/score-spec/score-go v1.8.3 h1:5flFFFQO/I3ollH02vW+ycDrnhgjQzgQZ86o1Db+hUo=
32+
github.com/score-spec/score-go v1.8.3/go.mod h1:v8UV2rUfz5obXNMtndKvjskOMP4xmwhG1RSBrBK2B1M=
33+
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
34+
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
35+
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
36+
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
37+
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
38+
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
39+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
40+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
41+
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
42+
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
43+
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 commit comments

Comments
 (0)