-
Notifications
You must be signed in to change notification settings - Fork 33
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
Import gojail pkg into runj repo #13
base: main
Are you sure you want to change the base?
Changes from all commits
a1772e5
1c91492
9c89966
89d5243
70c7e47
8096046
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import ( | |
|
||
"go.sbk.wtf/runj/jail" | ||
"go.sbk.wtf/runj/oci" | ||
"go.sbk.wtf/runj/pkg/gojail" | ||
"go.sbk.wtf/runj/runtimespec" | ||
"go.sbk.wtf/runj/state" | ||
|
||
|
@@ -129,14 +130,19 @@ the console's pseudoterminal`) | |
} else if *consoleSocket != "" { | ||
return errors.New("console-socket provided but Process.Terminal is false") | ||
} | ||
var confPath string | ||
confPath, err = jail.CreateConfig(id, rootPath) | ||
|
||
jailconfig := make(map[string]interface{}) | ||
jailconfig["name"] = id | ||
jailconfig["path"] = rootPath | ||
jailconfig["persist"] = true | ||
|
||
j, err := gojail.JailCreate(jailconfig) | ||
if err != nil { | ||
return err | ||
} | ||
if err := jail.CreateJail(cmd.Context(), confPath); err != nil { | ||
return err | ||
return fmt.Errorf("failed creating jail: %w", err) | ||
} | ||
s.JID = int(j.ID()) | ||
s.Save() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Saving should be handled by the |
||
|
||
err = jail.Mount(ociConfig) | ||
if err != nil { | ||
return err | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -3,10 +3,10 @@ package main | |||||||||||
import ( | ||||||||||||
"errors" | ||||||||||||
"fmt" | ||||||||||||
"os" | ||||||||||||
|
||||||||||||
"go.sbk.wtf/runj/jail" | ||||||||||||
"go.sbk.wtf/runj/oci" | ||||||||||||
"go.sbk.wtf/runj/pkg/gojail" | ||||||||||||
"go.sbk.wtf/runj/runtimespec" | ||||||||||||
"go.sbk.wtf/runj/state" | ||||||||||||
|
||||||||||||
|
@@ -32,6 +32,10 @@ func deleteCommand() *cobra.Command { | |||||||||||
RunE: func(cmd *cobra.Command, args []string) error { | ||||||||||||
disableUsage(cmd) | ||||||||||||
id := args[0] | ||||||||||||
s, err := state.Load(id) | ||||||||||||
if err != nil { | ||||||||||||
return fmt.Errorf("delete: failed to load state: %w", err) | ||||||||||||
} | ||||||||||||
running, err := jail.IsRunning(cmd.Context(), id, 0) | ||||||||||||
if err != nil { | ||||||||||||
return fmt.Errorf("delete: failed to determine if jail is running: %w", err) | ||||||||||||
|
@@ -43,14 +47,11 @@ func deleteCommand() *cobra.Command { | |||||||||||
if err != nil { | ||||||||||||
return fmt.Errorf("delete: failed to find entrypoint process: %w", err) | ||||||||||||
} | ||||||||||||
confPath := jail.ConfPath(id) | ||||||||||||
if _, err := os.Stat(confPath); err != nil { | ||||||||||||
return errors.New("invalid jail id provided") | ||||||||||||
} | ||||||||||||
err = jail.DestroyJail(cmd.Context(), confPath, id) | ||||||||||||
j, err := gojail.JailGetByID(gojail.JailID(s.JID)) | ||||||||||||
if err != nil { | ||||||||||||
return err | ||||||||||||
return fmt.Errorf("delete: failed to get jail: %w", err) | ||||||||||||
} | ||||||||||||
j.Destroy() | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||
var ociConfig *runtimespec.Spec | ||||||||||||
ociConfig, err = oci.LoadConfig(id) | ||||||||||||
if err != nil { | ||||||||||||
|
This file was deleted.
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why pass the container ID and not the JID?
id
appears to only be used to load the state (line 70), and then the resulting state is only used to find the JID (line 75).I'd prefer to avoid having
runj-entrypoint
read the state file if possible.