Add --env-file to ctr
Closes #3517 Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package oci
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
@@ -1200,3 +1201,24 @@ func WithLinuxDevice(path, permissions string) SpecOpts {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// WithEnvFile adds environment variables from a file to the container's spec
|
||||
func WithEnvFile(path string) SpecOpts {
|
||||
return func(_ context.Context, _ Client, _ *containers.Container, s *Spec) error {
|
||||
var vars []string
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
sc := bufio.NewScanner(f)
|
||||
for sc.Scan() {
|
||||
if sc.Err() != nil {
|
||||
return sc.Err()
|
||||
}
|
||||
vars = append(vars, sc.Text())
|
||||
}
|
||||
return WithEnv(vars)(nil, nil, nil, s)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user