diff --git a/internal/command/default.provisioners.yaml b/internal/command/default.provisioners.yaml index 2dfc4c1..d17aba2 100644 --- a/internal/command/default.provisioners.yaml +++ b/internal/command/default.provisioners.yaml @@ -798,4 +798,4 @@ download certificate from container per command like: \n \tdocker cp [CONTAINER-NAME]:/usr/share/elasticsearch/config/certs/ca/ca.crt /tmp/ \n and than check connection per culr like: \n - \tcurl --cacert /tmp/ca.crt -u {{ .State.username }}:{{ .State.password }} https://localhost:{{ .Init.publishPort }}" + \tcurl --cacert /tmp/ca.crt -u {{ .State.username }}:{{ .State.password }} https://localhost:{{ .Init.publishPort }}" \ No newline at end of file diff --git a/internal/command/init.go b/internal/command/init.go index 2e7e218..d28dd63 100644 --- a/internal/command/init.go +++ b/internal/command/init.go @@ -15,9 +15,11 @@ package command import ( + "context" _ "embed" "errors" "fmt" + "io" "log/slog" "os" "path/filepath" @@ -31,6 +33,21 @@ import ( "github.com/score-spec/score-compose/internal/provisioners/loader" ) +func GetStdinFile(ctx context.Context) ([]byte, error) { + // Check if stdin is being piped + stat, err := os.Stdin.Stat() + if err != nil { + return nil, err + } + + // Check if stdin is a pipe + if (stat.Mode() & os.ModeCharDevice) == 0 { + return io.ReadAll(os.Stdin) + } + + return nil, fmt.Errorf("no stdin data provided") +} + const ( DefaultScoreFileContent = `# Score provides a developer-centric and platform-agnostic # Workload specification to improve developer productivity and experience. @@ -199,11 +216,28 @@ the new provisioners will take precedence. if v, _ := cmd.Flags().GetStringArray(initCmdProvisionerFlag); len(v) > 0 { for i, vi := range v { + var data []byte + + if vi == "-" { + data, err = GetStdinFile(cmd.Context()) + } else { + // Existing URI loading logic + data, err = uriget.GetFile(cmd.Context(), vi) + } + data, err := uriget.GetFile(cmd.Context(), vi) if err != nil { return fmt.Errorf("failed to load provisioner %d: %w", i+1, err) } - if err := loader.SaveProvisionerToDirectory(sd.Path, vi, data); err != nil { + + var saveFilename string + if vi == "-" { + saveFilename = fmt.Sprintf("stdin-provisioner-%d%s", i+1, loader.DefaultSuffix) + } else { + saveFilename = vi + } + + if err := loader.SaveProvisionerToDirectory(sd.Path, saveFilename, data); err != nil { return fmt.Errorf("failed to save provisioner %d: %w", i+1, err) } } @@ -230,7 +264,9 @@ func init() { "- HTTPS : https://host/file\n"+ "- Git (SSH) : git-ssh://git@host/repo.git/file\n"+ "- Git (HTTPS) : git-https://host/repo.git/file\n"+ - "- OCI : oci://[registry/][namespace/]repository[:tag|@digest][#file]") + "- OCI : oci://[registry/][namespace/]repository[:tag|@digest][#file]\n"+ + "- Local File : /path/to/local/file\n"+ + "- Stdin : - (read from standard input)") rootCmd.AddCommand(initCmd) } diff --git a/provisioner.yaml b/provisioner.yaml new file mode 100644 index 0000000..f2fa13d --- /dev/null +++ b/provisioner.yaml @@ -0,0 +1,35 @@ +# Score provides a developer-centric and platform-agnostic +# Workload specification to improve developer productivity and experience. +# Score eliminates configuration management between local and remote environments. +# +# Specification reference: https://docs.score.dev/docs/reference/score-spec-reference/ +--- + +# Score specification version +apiVersion: score.dev/v1b1 + +metadata: + name: example + +containers: + hello-world: + image: nginx:latest + + # Uncomment the following for a custom entrypoint command + # command: [] + + # Uncomment the following for custom arguments + # args: [] + + # Environment variables to inject into the container + variables: + EXAMPLE_VARIABLE: "example-value" + +service: + ports: + # Expose the http port from nginx on port 8080 + www: + port: 8080 + targetPort: 80 + +resources: {} diff --git a/score.yaml b/score.yaml new file mode 100644 index 0000000..f2fa13d --- /dev/null +++ b/score.yaml @@ -0,0 +1,35 @@ +# Score provides a developer-centric and platform-agnostic +# Workload specification to improve developer productivity and experience. +# Score eliminates configuration management between local and remote environments. +# +# Specification reference: https://docs.score.dev/docs/reference/score-spec-reference/ +--- + +# Score specification version +apiVersion: score.dev/v1b1 + +metadata: + name: example + +containers: + hello-world: + image: nginx:latest + + # Uncomment the following for a custom entrypoint command + # command: [] + + # Uncomment the following for custom arguments + # args: [] + + # Environment variables to inject into the container + variables: + EXAMPLE_VARIABLE: "example-value" + +service: + ports: + # Expose the http port from nginx on port 8080 + www: + port: 8080 + targetPort: 80 + +resources: {}