Skip to content

Commit d55e66d

Browse files
committed
changes made
Signed-off-by: rabelmervin <[email protected]>
1 parent f1f509f commit d55e66d

File tree

4 files changed

+109
-3
lines changed

4 files changed

+109
-3
lines changed

internal/command/default.provisioners.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,4 +798,4 @@
798798
download certificate from container per command like: \n
799799
\tdocker cp [CONTAINER-NAME]:/usr/share/elasticsearch/config/certs/ca/ca.crt /tmp/ \n
800800
and than check connection per culr like: \n
801-
\tcurl --cacert /tmp/ca.crt -u {{ .State.username }}:{{ .State.password }} https://localhost:{{ .Init.publishPort }}"
801+
\tcurl --cacert /tmp/ca.crt -u {{ .State.username }}:{{ .State.password }} https://localhost:{{ .Init.publishPort }}"

internal/command/init.go

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
package command
1616

1717
import (
18+
"context"
1819
_ "embed"
1920
"errors"
2021
"fmt"
22+
"io"
2123
"log/slog"
2224
"os"
2325
"path/filepath"
@@ -31,6 +33,21 @@ import (
3133
"github.com/score-spec/score-compose/internal/provisioners/loader"
3234
)
3335

36+
func GetStdinFile(ctx context.Context) ([]byte, error) {
37+
// Check if stdin is being piped
38+
stat, err := os.Stdin.Stat()
39+
if err != nil {
40+
return nil, err
41+
}
42+
43+
// Check if stdin is a pipe
44+
if (stat.Mode() & os.ModeCharDevice) == 0 {
45+
return io.ReadAll(os.Stdin)
46+
}
47+
48+
return nil, fmt.Errorf("no stdin data provided")
49+
}
50+
3451
const (
3552
DefaultScoreFileContent = `# Score provides a developer-centric and platform-agnostic
3653
# Workload specification to improve developer productivity and experience.
@@ -199,11 +216,28 @@ the new provisioners will take precedence.
199216

200217
if v, _ := cmd.Flags().GetStringArray(initCmdProvisionerFlag); len(v) > 0 {
201218
for i, vi := range v {
219+
var data []byte
220+
221+
if vi == "-" {
222+
data, err = GetStdinFile(cmd.Context())
223+
} else {
224+
// Existing URI loading logic
225+
data, err = uriget.GetFile(cmd.Context(), vi)
226+
}
227+
202228
data, err := uriget.GetFile(cmd.Context(), vi)
203229
if err != nil {
204230
return fmt.Errorf("failed to load provisioner %d: %w", i+1, err)
205231
}
206-
if err := loader.SaveProvisionerToDirectory(sd.Path, vi, data); err != nil {
232+
233+
var saveFilename string
234+
if vi == "-" {
235+
saveFilename = fmt.Sprintf("stdin-provisioner-%d%s", i+1, loader.DefaultSuffix)
236+
} else {
237+
saveFilename = vi
238+
}
239+
240+
if err := loader.SaveProvisionerToDirectory(sd.Path, saveFilename, data); err != nil {
207241
return fmt.Errorf("failed to save provisioner %d: %w", i+1, err)
208242
}
209243
}
@@ -230,7 +264,9 @@ func init() {
230264
"- HTTPS : https://host/file\n"+
231265
"- Git (SSH) : git-ssh://git@host/repo.git/file\n"+
232266
"- Git (HTTPS) : git-https://host/repo.git/file\n"+
233-
"- OCI : oci://[registry/][namespace/]repository[:tag|@digest][#file]")
267+
"- OCI : oci://[registry/][namespace/]repository[:tag|@digest][#file]\n"+
268+
"- Local File : /path/to/local/file\n"+
269+
"- Stdin : - (read from standard input)")
234270

235271
rootCmd.AddCommand(initCmd)
236272
}

provisioner.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Score provides a developer-centric and platform-agnostic
2+
# Workload specification to improve developer productivity and experience.
3+
# Score eliminates configuration management between local and remote environments.
4+
#
5+
# Specification reference: https://docs.score.dev/docs/reference/score-spec-reference/
6+
---
7+
8+
# Score specification version
9+
apiVersion: score.dev/v1b1
10+
11+
metadata:
12+
name: example
13+
14+
containers:
15+
hello-world:
16+
image: nginx:latest
17+
18+
# Uncomment the following for a custom entrypoint command
19+
# command: []
20+
21+
# Uncomment the following for custom arguments
22+
# args: []
23+
24+
# Environment variables to inject into the container
25+
variables:
26+
EXAMPLE_VARIABLE: "example-value"
27+
28+
service:
29+
ports:
30+
# Expose the http port from nginx on port 8080
31+
www:
32+
port: 8080
33+
targetPort: 80
34+
35+
resources: {}

score.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Score provides a developer-centric and platform-agnostic
2+
# Workload specification to improve developer productivity and experience.
3+
# Score eliminates configuration management between local and remote environments.
4+
#
5+
# Specification reference: https://docs.score.dev/docs/reference/score-spec-reference/
6+
---
7+
8+
# Score specification version
9+
apiVersion: score.dev/v1b1
10+
11+
metadata:
12+
name: example
13+
14+
containers:
15+
hello-world:
16+
image: nginx:latest
17+
18+
# Uncomment the following for a custom entrypoint command
19+
# command: []
20+
21+
# Uncomment the following for custom arguments
22+
# args: []
23+
24+
# Environment variables to inject into the container
25+
variables:
26+
EXAMPLE_VARIABLE: "example-value"
27+
28+
service:
29+
ports:
30+
# Expose the http port from nginx on port 8080
31+
www:
32+
port: 8080
33+
targetPort: 80
34+
35+
resources: {}

0 commit comments

Comments
 (0)