Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changes made for provisoners flag #221

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we please move this functionality over to https://github.com/score-spec/score-go/blob/main/uriget/uriget.go#L155 as part of the file type getter? This is a good place to add unit tests too.

This is common functionality that we can use and document in all the consumers of this library. This would allow the uri to be documented as either: file://- or just -.

I can help get this turned around quickly :)

// 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 = "from-stdin.provisioners.yaml"
} 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
Copy link
Contributor

@7h3-3mp7y-m4n 7h3-3mp7y-m4n Dec 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @rabelmervin you should not add this file cause it's irrelevant to issue #220
Also, it is of no use.

# 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: {}
Comment on lines +1 to +35
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for this, If you want to add examples, you should refer to this and in a separate PR.

Loading