@@ -33,25 +33,14 @@ import (
3333
3434// Install a binary image into the opt service
3535func (c * Client ) Install (ctx context.Context , image Image , opts ... InstallOpts ) error {
36- resp , err := c .IntrospectionService ().Plugins (ctx , & introspectionapi.PluginsRequest {
37- Filters : []string {
38- "id==opt" ,
39- },
40- })
41- if err != nil {
42- return err
43- }
44- if len (resp .Plugins ) != 1 {
45- return errors .New ("opt service not enabled" )
46- }
47- path := resp .Plugins [0 ].Exports ["path" ]
48- if path == "" {
49- return errors .New ("opt path not exported" )
50- }
5136 var config InstallConfig
5237 for _ , o := range opts {
5338 o (& config )
5439 }
40+ path , err := c .getInstallPath (ctx , config )
41+ if err != nil {
42+ return err
43+ }
5544 var (
5645 cs = image .ContentStore ()
5746 platform = platforms .Default ()
@@ -89,3 +78,25 @@ func (c *Client) Install(ctx context.Context, image Image, opts ...InstallOpts)
8978 }
9079 return nil
9180}
81+
82+ func (c * Client ) getInstallPath (ctx context.Context , config InstallConfig ) (string , error ) {
83+ if config .Path != "" {
84+ return config .Path , nil
85+ }
86+ resp , err := c .IntrospectionService ().Plugins (ctx , & introspectionapi.PluginsRequest {
87+ Filters : []string {
88+ "id==opt" ,
89+ },
90+ })
91+ if err != nil {
92+ return "" , err
93+ }
94+ if len (resp .Plugins ) != 1 {
95+ return "" , errors .New ("opt service not enabled" )
96+ }
97+ path := resp .Plugins [0 ].Exports ["path" ]
98+ if path == "" {
99+ return "" , errors .New ("opt path not exported" )
100+ }
101+ return path , nil
102+ }
0 commit comments