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

Merged
merged 4 commits into from
Jan 17, 2025
Merged
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 go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/gofrs/uuid v4.3.0+incompatible
github.com/gorilla/websocket v1.5.0
github.com/iancoleman/strcase v0.2.0
github.com/koyeb/koyeb-api-client-go v0.0.0-20241206143543-39fbd0d0bf5e
github.com/koyeb/koyeb-api-client-go v0.0.0-20250117143439-03648cc5a823
github.com/logrusorgru/aurora v2.0.3+incompatible
github.com/manifoldco/promptui v0.9.0
github.com/mitchellh/go-homedir v1.1.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,12 @@ github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLf
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/koyeb/koyeb-api-client-go v0.0.0-20241129081540-9cecbc45397f h1:jzyPhhyZgLKA3FXMNxyEZiETROBEde4uI4qwHsliBrk=
github.com/koyeb/koyeb-api-client-go v0.0.0-20241129081540-9cecbc45397f/go.mod h1:+oQfFj2WL3gi9Pb+UHbob4D7xaT52mPfKyH1UvWa4PQ=
github.com/koyeb/koyeb-api-client-go v0.0.0-20241206143120-7817d20778fd h1:krjNLKRYbBEExAIEI1maqyo9P3oF1cKevQXiVedTX18=
github.com/koyeb/koyeb-api-client-go v0.0.0-20241206143120-7817d20778fd/go.mod h1:+oQfFj2WL3gi9Pb+UHbob4D7xaT52mPfKyH1UvWa4PQ=
github.com/koyeb/koyeb-api-client-go v0.0.0-20241206143543-39fbd0d0bf5e h1:/pSEDHiuCglPMooi0kcQay0ZmJ1fZys8qre6Jz2iQ7Q=
github.com/koyeb/koyeb-api-client-go v0.0.0-20241206143543-39fbd0d0bf5e/go.mod h1:+oQfFj2WL3gi9Pb+UHbob4D7xaT52mPfKyH1UvWa4PQ=
github.com/koyeb/koyeb-api-client-go v0.0.0-20250106150959-2940e5613765 h1:OaJezhu0iuR0XN6y5Sxc6uARWyPx1WG1ZjBgVgG7jvw=
github.com/koyeb/koyeb-api-client-go v0.0.0-20250106150959-2940e5613765/go.mod h1:+oQfFj2WL3gi9Pb+UHbob4D7xaT52mPfKyH1UvWa4PQ=
github.com/koyeb/koyeb-api-client-go v0.0.0-20250117143439-03648cc5a823 h1:icM+7zADUhhsv1DSXVHdT3UusXWOsZ25aolFPmhgPiU=
github.com/koyeb/koyeb-api-client-go v0.0.0-20250117143439-03648cc5a823/go.mod h1:+oQfFj2WL3gi9Pb+UHbob4D7xaT52mPfKyH1UvWa4PQ=
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
Expand Down
56 changes: 28 additions & 28 deletions pkg/koyeb/flags_list/file_mounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,32 @@ import (
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 GetNewConfigFilestListFromFlags() func(values []string) ([]Flag[koyeb.ConfigFile], error) {
return func(values []string) ([]Flag[koyeb.ConfigFile], error) {
ret := make([]Flag[koyeb.ConfigFile], 0, len(values))

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 config-file flag value \"%s\"", hc.cliValue),
Additional: []string{
"To remove a mounted file from the service, prefix the path with '!', e.g. '!path'",
"To remove a mounted config 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 config-file flag value and try again",
}
}
hc.markedForDeletion = true
Expand All @@ -44,40 +44,40 @@ func GetNewFileMountListFromFlags() func(values []string) ([]Flag[koyeb.FileMoun
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 confi-file flag value \"%s\"", hc.cliValue),
Additional: []string{
"File mount must be specified as SOURCE:PATH[:PERMISSIONS]",
"To remove a mounted file from the service, prefix the path with '!', e.g. '!path'",
"Config file flag value must be specified as SOURCE:PATH[:PERMISSIONS]",
"To remove a mounted config file from the service, prefix the path with '!', e.g. '!path'",
},
Orig: nil,
Solution: "Fix the file mount and try again",
Solution: "Fix the config-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 locate file at \"%s\"", path),
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'",
"Config file flag value must be specified as SOURCE:PATH[:PERMISSIONS]",
"To remove a mounted config file from the service, prefix the path with '!', e.g. '!path'",
},
Orig: nil,
Solution: "Fix the file mount and try again",
Solution: "Fix the config-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 \"%s\"", path),
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'",
"Config file flag value must be specified as SOURCE:PATH[:PERMISSIONS]",
"To remove a config file mount from the service, prefix it with '!', e.g. '!path'",
},
Orig: nil,
Solution: "Fix the file mount and try again",
Solution: "Fix the config-file flag value and try again",
}
}
hc.content = string(data)
Expand All @@ -89,13 +89,13 @@ func GetNewFileMountListFromFlags() func(values []string) ([]Flag[koyeb.FileMoun
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 permissions \"%s\"", permissions),
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'",
"File mount permission must be specified as SOURCE:PATH:PERMISSIONS and in format like 0644",
"To remove a config 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 config-file flag value and try again",
}
}
hc.permissions = permissions
Expand All @@ -106,18 +106,18 @@ func GetNewFileMountListFromFlags() func(values []string) ([]Flag[koyeb.FileMoun
}
}

func (f *FlagFileMount) IsEqualTo(hc koyeb.FileMount) bool {
func (f *FlagFile) IsEqualTo(hc koyeb.ConfigFile) bool {
return hc.GetPath() == f.path
}

func (f *FlagFileMount) UpdateItem(hc *koyeb.FileMount) {
func (f *FlagFile) UpdateItem(hc *koyeb.ConfigFile) {
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.ConfigFile {
item := koyeb.NewConfigFileWithDefaults()
f.UpdateItem(item)
return item
}
17 changes: 9 additions & 8 deletions pkg/koyeb/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,11 @@ func (h *ServiceHandler) addServiceDefinitionFlagsForAllSources(flags *pflag.Fla
"To delete a volume, use !VOLUME, for example --volume '!myvolume'\n",
)
flags.StringSlice(
"mount-config-file",
"config-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]\n"+
"for example --config-file /etc/data.yaml:/etc/data.yaml:0644\n"+
"To delete a file mount, use !PATH, for example --config-file !/etc/data.yaml\n",
)

// Configure aliases: for example, allow user to use --port instead of --ports
Expand Down Expand Up @@ -556,11 +557,11 @@ func (h *ServiceHandler) parseServiceDefinitionFlags(ctx *CLIContext, flags *pfl
}
definition.SetVolumes(volumes)

fileMounts, err := h.parseFileMounts(ctx, flags, definition.FileMounts)
files, err := h.parseConfigFiles(ctx, flags, definition.ConfigFiles)
if err != nil {
return err
}
definition.SetFileMounts(fileMounts)
definition.SetConfigFiles(files)

return nil
}
Expand Down Expand Up @@ -1754,9 +1755,9 @@ func (h *ServiceHandler) parseVolumes(ctx *CLIContext, flags *pflag.FlagSet, cur
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 --config-file
func (h *ServiceHandler) parseConfigFiles(ctx *CLIContext, flags *pflag.FlagSet, currentFiles []koyeb.ConfigFile) ([]koyeb.ConfigFile, error) {
return parseListFlags("config-file", flags_list.GetNewConfigFilestListFromFlags(), flags, currentFiles)
}

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