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

Use new API for mounting files #266

Open
wants to merge 1 commit into
base: master
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
46 changes: 23 additions & 23 deletions pkg/koyeb/flags_list/file_mounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,32 @@
kerrors "github.com/koyeb/koyeb-cli/pkg/koyeb/errors"
)

type FlagFileMount struct {
type FlagFile struct {
BaseFlag
path string
permissions string
content string
}

func GetNewFileMountListFromFlags() func(values []string) ([]Flag[koyeb.FileMount], error) {
return func(values []string) ([]Flag[koyeb.FileMount], error) {
ret := make([]Flag[koyeb.FileMount], 0, len(values))
func GetNewFilestListFromFlags() func(values []string) ([]Flag[koyeb.File], error) {

Check failure on line 20 in pkg/koyeb/flags_list/file_mounts.go

View workflow job for this annotation

GitHub Actions / check

undefined: koyeb.File

Check failure on line 20 in pkg/koyeb/flags_list/file_mounts.go

View workflow job for this annotation

GitHub Actions / check

undefined: koyeb.File
return func(values []string) ([]Flag[koyeb.File], error) {

Check failure on line 21 in pkg/koyeb/flags_list/file_mounts.go

View workflow job for this annotation

GitHub Actions / check

undefined: koyeb.File
ret := make([]Flag[koyeb.File], 0, len(values))

Check failure on line 22 in pkg/koyeb/flags_list/file_mounts.go

View workflow job for this annotation

GitHub Actions / check

undefined: koyeb.File

for _, value := range values {
hc := &FlagFileMount{BaseFlag: BaseFlag{cliValue: value}}
hc := &FlagFile{BaseFlag: BaseFlag{cliValue: value}}
components := strings.Split(value, ":")

if strings.HasPrefix(components[0], "!") {
if len(components) > 1 {
return nil, &kerrors.CLIError{
What: "Error while configuring the service",
Why: fmt.Sprintf("unable to parse the file mount\"%s\"", hc.cliValue),
Why: fmt.Sprintf("unable to parse the file flag value \"%s\"", hc.cliValue),
Additional: []string{
"To remove a mounted file from the service, prefix the path with '!', e.g. '!path'",
"The source should not be specified to remove it from the service",
},
Orig: nil,
Solution: "Fix the file mount and try again",
Solution: "Fix the file flag value and try again",
}
}
hc.markedForDeletion = true
Expand All @@ -44,40 +44,40 @@
if len(components) != 2 && len(components) != 3 {
return nil, &kerrors.CLIError{
What: "Error while configuring the service",
Why: fmt.Sprintf("unable to parse the file mount\"%s\"", hc.cliValue),
Why: fmt.Sprintf("unable to parse the file flag value \"%s\"", hc.cliValue),
Additional: []string{
"File mount must be specified as SOURCE:PATH[:PERMISSIONS]",
"File flag value must be specified as SOURCE:PATH[:PERMISSIONS]",
"To remove a mounted file from the service, prefix the path with '!', e.g. '!path'",
},
Orig: nil,
Solution: "Fix the file mount and try again",
Solution: "Fix the file flag value and try again",
}
}
hc.path = components[1]
path := components[0]
if _, err := os.Stat(path); errors.Is(err, os.ErrNotExist) {
return nil, &kerrors.CLIError{
What: "Error while configuring the service",
Why: fmt.Sprintf("unable to parse the file mount \"%s\"", hc.cliValue),
Why: fmt.Sprintf("unable to parse the file flag value \"%s\"", hc.cliValue),
Additional: []string{
"File mount must be specified as SOURCE:PATH[:PERMISSIONS]",
"To remove a file mount from the service, prefix it with '!', e.g. '!path'",
"File flag value must be specified as SOURCE:PATH[:PERMISSIONS]",
"To remove a mounted file from the service, prefix the path with '!', e.g. '!path'",
},
Orig: nil,
Solution: "Fix the file mount and try again",
Solution: "Fix the file flag value and try again",
}
}
data, err := os.ReadFile(path)
if err != nil {
return nil, &kerrors.CLIError{
What: "Error while configuring the service",
Why: fmt.Sprintf("unable to read the file mount\"%s\"", hc.cliValue),
Why: fmt.Sprintf("unable to read the file flag value \"%s\"", hc.cliValue),
Additional: []string{
"File mount must be specified as SOURCE:PATH[:PERMISSIONS]",
"File flag value must be specified as SOURCE:PATH[:PERMISSIONS]",
"To remove a file mount from the service, prefix it with '!', e.g. '!path'",
},
Orig: nil,
Solution: "Fix the file mount and try again",
Solution: "Fix the file flag value and try again",
}
}
hc.content = string(data)
Expand All @@ -89,13 +89,13 @@
if len(permissions) != 4 {
return nil, &kerrors.CLIError{
What: "Error while configuring the service",
Why: fmt.Sprintf("unable to parse the file mount\"%s\"", hc.cliValue),
Why: fmt.Sprintf("unable to parse the file flag value \"%s\"", hc.cliValue),
Additional: []string{
"File mount permission must be specified as SOURCE:PATH:PERMISSIONS",
"To remove a file mount from the service, prefix it with '!', e.g. '!path'",
},
Orig: nil,
Solution: "Fix the permissions in file mount and try again",
Solution: "Fix the permissions in file flag value and try again",
}
}
hc.permissions = permissions
Expand All @@ -106,18 +106,18 @@
}
}

func (f *FlagFileMount) IsEqualTo(hc koyeb.FileMount) bool {
func (f *FlagFile) IsEqualTo(hc koyeb.File) bool {

Check failure on line 109 in pkg/koyeb/flags_list/file_mounts.go

View workflow job for this annotation

GitHub Actions / check

undefined: koyeb.File
return hc.GetPath() == f.path
}

func (f *FlagFileMount) UpdateItem(hc *koyeb.FileMount) {
func (f *FlagFile) UpdateItem(hc *koyeb.File) {

Check failure on line 113 in pkg/koyeb/flags_list/file_mounts.go

View workflow job for this annotation

GitHub Actions / check

undefined: koyeb.File
hc.Content = &f.content
hc.Path = &f.path
hc.Permissions = &f.permissions
}

func (f *FlagFileMount) CreateNewItem() *koyeb.FileMount {
item := koyeb.NewFileMountWithDefaults()
func (f *FlagFile) CreateNewItem() *koyeb.File{

Check failure on line 119 in pkg/koyeb/flags_list/file_mounts.go

View workflow job for this annotation

GitHub Actions / check

undefined: koyeb.File
item := koyeb.NewFileWithDefaults()

Check failure on line 120 in pkg/koyeb/flags_list/file_mounts.go

View workflow job for this annotation

GitHub Actions / check

undefined: koyeb.NewFileWithDefaults (typecheck)
f.UpdateItem(item)
return item
}
16 changes: 8 additions & 8 deletions pkg/koyeb/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"github.com/koyeb/koyeb-api-client-go/api/v1/koyeb"
"github.com/koyeb/koyeb-cli/pkg/koyeb/dates"
"github.com/koyeb/koyeb-cli/pkg/koyeb/errors"
"github.com/koyeb/koyeb-cli/pkg/koyeb/flags_list"

Check failure on line 12 in pkg/koyeb/services.go

View workflow job for this annotation

GitHub Actions / check

could not import github.com/koyeb/koyeb-cli/pkg/koyeb/flags_list (-: # github.com/koyeb/koyeb-cli/pkg/koyeb/flags_list
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
Expand Down Expand Up @@ -378,10 +378,10 @@
"To delete a volume, use !VOLUME, for example --volume '!myvolume'\n",
)
flags.StringSlice(
"mount-config-file",
"file",
nil,
"Mount a copy of local file as a file in the service container using the format LOCAL_FILE:PATH:[PERMISSIONS] for example --mount-file /etc/data.yaml:/etc/data.yaml:0644\n"+
"To delete a file mount, use !PATH, for example --mount-file !/etc/data.yaml\n",
"Mount a copy of local file as a file in the service container using the format LOCAL_FILE:PATH:[PERMISSIONS] for example --file /etc/data.yaml:/etc/data.yaml:0644\n"+
"To delete a file mount, use !PATH, for example --file !/etc/data.yaml\n",
)

// Configure aliases: for example, allow user to use --port instead of --ports
Expand Down Expand Up @@ -556,11 +556,11 @@
}
definition.SetVolumes(volumes)

fileMounts, err := h.parseFileMounts(ctx, flags, definition.FileMounts)
files, err := h.parseFiles(ctx, flags, definition.Files)
if err != nil {
return err
}
definition.SetFileMounts(fileMounts)
definition.SetFiles(files)

return nil
}
Expand Down Expand Up @@ -1754,9 +1754,9 @@
return parseListFlags("volumes", flags_list.GetNewVolumeListFromFlags(wrappedResolveVolumeId), flags, currentVolumes)
}

// Parse --mount-config-file
func (h *ServiceHandler) parseFileMounts(ctx *CLIContext, flags *pflag.FlagSet, currentFileMounts []koyeb.FileMount) ([]koyeb.FileMount, error) {
return parseListFlags("mount-config-file", flags_list.GetNewFileMountListFromFlags(), flags, currentFileMounts)
// Parse --file
func (h *ServiceHandler) parseFiles(ctx *CLIContext, flags *pflag.FlagSet, currentFiles []koyeb.File) ([]koyeb.File, error) {
return parseListFlags("file", flags_list.GetNewFilestListFromFlags(), flags, currentFiles)
}

// DeploymentStrategy is a type alias for koyeb.DeploymentStrategyType which implements the pflag.Value interface.
Expand Down
Loading