Skip to content

Commit

Permalink
changes made
Browse files Browse the repository at this point in the history
Signed-off-by: rabelmervin <[email protected]>
  • Loading branch information
rabelmervin committed Dec 14, 2024
1 parent f1f509f commit d55e66d
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 3 deletions.
2 changes: 1 addition & 1 deletion internal/command/default.provisioners.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}"
40 changes: 38 additions & 2 deletions internal/command/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
package command

import (
"context"
_ "embed"
"errors"
"fmt"
"io"
"log/slog"
"os"
"path/filepath"
Expand All @@ -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.
Expand Down Expand Up @@ -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)
}
}
Expand All @@ -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)
}
Expand Down
35 changes: 35 additions & 0 deletions provisioner.yaml
Original file line number Diff line number Diff line change
@@ -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: {}
35 changes: 35 additions & 0 deletions score.yaml
Original file line number Diff line number Diff line change
@@ -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: {}

0 comments on commit d55e66d

Please sign in to comment.