-
Notifications
You must be signed in to change notification settings - Fork 4
image build support #122
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
Draft
iignatevich
wants to merge
1
commit into
main
Choose a base branch
from
kubernetes_image_build_support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
image build support #122
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,8 @@ const ( | |
containerFlagRebuildImage = "rebuild-image" | ||
containerFlagEntrypoint = "entrypoint" | ||
containerFlagExec = "exec" | ||
containerRegistryURL = "registry-url" | ||
containerRegistryType = "registry-type" | ||
) | ||
|
||
type runtimeContainer struct { | ||
|
@@ -50,15 +52,20 @@ type runtimeContainer struct { | |
nameprv ContainerNameProvider | ||
|
||
// Runtime flags | ||
isSetRemote bool | ||
copyBack bool | ||
removeImg bool | ||
noCache bool | ||
rebuildImage bool | ||
entrypoint string | ||
entrypointSet bool | ||
exec bool | ||
volumeFlags string | ||
// @todo need to think about a better way to handle this. | ||
runtimeFlags driver.RuntimeFlags | ||
|
||
//isSetRemote bool | ||
//copyBack bool | ||
//removeImg bool | ||
//noCache bool | ||
//rebuildImage bool | ||
//entrypoint string | ||
//entrypointSet bool | ||
//exec bool | ||
//volumeFlags string | ||
//registryURL string | ||
//registryType string | ||
} | ||
|
||
// ContainerNameProvider provides an ability to generate a random container name | ||
|
@@ -156,6 +163,19 @@ func (c *runtimeContainer) GetFlags() *FlagsGroup { | |
Type: jsonschema.Boolean, | ||
Default: false, | ||
}, | ||
&DefParameter{ | ||
Name: containerRegistryURL, | ||
Title: "k8s Images registry URL", | ||
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. Use Kubernetes for all frontend strings. k8s is mostly for development. It seems we need to be able to specify registry in the global config. We may as well have multiple registries. |
||
Type: jsonschema.String, | ||
Default: "localhost:5000", | ||
}, | ||
&DefParameter{ | ||
Name: containerRegistryType, | ||
Title: "k8s Images registry type", | ||
Type: jsonschema.String, | ||
Enum: []any{driver.RegistryNone, driver.RegistryLocal, driver.RegistryRemote}, | ||
Default: driver.RegistryLocal, | ||
}, | ||
} | ||
|
||
flags.AddDefinitions(definitions) | ||
|
@@ -184,32 +204,40 @@ func (c *runtimeContainer) SetFlags(input *Input) error { | |
flags := input.GroupFlags(c.flags.GetName()) | ||
|
||
if v, ok := flags[containerFlagRemote]; ok { | ||
c.isSetRemote = v.(bool) | ||
c.runtimeFlags.IsSetRemote = v.(bool) | ||
} | ||
|
||
if v, ok := flags[containerFlagCopyBack]; ok { | ||
c.copyBack = v.(bool) | ||
c.runtimeFlags.CopyBack = v.(bool) | ||
} | ||
|
||
if r, ok := flags[containerFlagRemoveImage]; ok { | ||
c.removeImg = r.(bool) | ||
c.runtimeFlags.RemoveImg = r.(bool) | ||
} | ||
|
||
if nc, ok := flags[containerFlagNoCache]; ok { | ||
c.noCache = nc.(bool) | ||
c.runtimeFlags.NoCache = nc.(bool) | ||
} | ||
|
||
if rb, ok := flags[containerFlagRebuildImage]; ok { | ||
c.rebuildImage = rb.(bool) | ||
c.runtimeFlags.RebuildImage = rb.(bool) | ||
} | ||
|
||
if e, ok := flags[containerFlagEntrypoint]; ok && e != "" { | ||
c.entrypointSet = true | ||
c.entrypoint = e.(string) | ||
c.runtimeFlags.EntrypointSet = true | ||
c.runtimeFlags.Entrypoint = e.(string) | ||
} | ||
|
||
if ex, ok := flags[containerFlagExec]; ok { | ||
c.exec = ex.(bool) | ||
c.runtimeFlags.Exec = ex.(bool) | ||
} | ||
|
||
if rt, ok := flags[containerRegistryType]; ok { | ||
c.runtimeFlags.RegistryType = rt.(string) | ||
} | ||
|
||
if rurl, ok := flags[containerRegistryURL]; ok { | ||
c.runtimeFlags.RegistryURL = rurl.(string) | ||
} | ||
|
||
return nil | ||
|
@@ -241,15 +269,17 @@ func (c *runtimeContainer) Init(ctx context.Context, _ *Action) (err error) { | |
if !c.isRemote() && c.isSELinuxEnabled(ctx) { | ||
// Check SELinux settings to allow reading the FS inside a container. | ||
// Use the lowercase z flag to allow concurrent actions access to the FS. | ||
c.volumeFlags += ":z" | ||
c.runtimeFlags.VolumeFlags += ":z" | ||
launchr.Term().Warning().Printfln( | ||
"SELinux is detected. The volumes will be mounted with the %q flags, which will relabel your files.\n"+ | ||
"This process may take time or potentially break existing permissions.", | ||
c.volumeFlags, | ||
c.runtimeFlags.VolumeFlags, | ||
) | ||
c.Log().Warn("using selinux flags", "flags", c.volumeFlags) | ||
c.Log().Warn("using selinux flags", "flags", c.runtimeFlags.VolumeFlags) | ||
} | ||
|
||
c.crt.SetRuntimeFlags(c.runtimeFlags) | ||
|
||
return nil | ||
} | ||
|
||
|
@@ -298,7 +328,7 @@ func (c *runtimeContainer) Execute(ctx context.Context, a *Action) (err error) { | |
|
||
// Remove the used image if it was specified. | ||
defer func() { | ||
if !c.removeImg { | ||
if !c.runtimeFlags.RemoveImg { | ||
return | ||
} | ||
log.Debug("removing container image after run") | ||
|
@@ -405,7 +435,7 @@ func (c *runtimeContainer) imageRemove(ctx context.Context, a *Action) error { | |
|
||
func (c *runtimeContainer) isRebuildRequired(bi *driver.BuildDefinition) (bool, error) { | ||
// @todo test image cache resolution somehow. | ||
if c.imgccres == nil || bi == nil || !c.rebuildImage { | ||
if c.imgccres == nil || bi == nil || !c.runtimeFlags.RebuildImage { | ||
return false, nil | ||
} | ||
|
||
|
@@ -454,7 +484,7 @@ func (c *runtimeContainer) imageEnsure(ctx context.Context, a *Action) error { | |
status, err := crt.ImageEnsure(ctx, driver.ImageOptions{ | ||
Name: image, | ||
Build: buildInfo, | ||
NoCache: c.noCache, | ||
NoCache: c.runtimeFlags.NoCache, | ||
ForceRebuild: forceRebuild, | ||
}) | ||
if err != nil { | ||
|
@@ -521,13 +551,13 @@ func (c *runtimeContainer) createContainerDef(a *Action, cname string) driver.Co | |
|
||
// Override an entrypoint if it was set in flags. | ||
var entrypoint []string | ||
if c.entrypointSet { | ||
entrypoint = []string{c.entrypoint} | ||
if c.runtimeFlags.EntrypointSet { | ||
entrypoint = []string{c.runtimeFlags.Entrypoint} | ||
} | ||
|
||
// Override Command with exec command. | ||
cmd := runDef.Container.Command | ||
if c.exec { | ||
if c.runtimeFlags.Exec { | ||
cmd = a.Input().ArgsPositional() | ||
} | ||
|
||
|
@@ -556,8 +586,8 @@ func (c *runtimeContainer) createContainerDef(a *Action, cname string) driver.Co | |
) | ||
} else { | ||
createOpts.Binds = []string{ | ||
launchr.MustAbs(a.WorkDir()) + ":" + containerHostMount + c.volumeFlags, | ||
launchr.MustAbs(a.Dir()) + ":" + containerActionMount + c.volumeFlags, | ||
launchr.MustAbs(a.WorkDir()) + ":" + containerHostMount + c.runtimeFlags.VolumeFlags, | ||
launchr.MustAbs(a.Dir()) + ":" + containerActionMount + c.runtimeFlags.VolumeFlags, | ||
} | ||
} | ||
return createOpts | ||
|
@@ -591,7 +621,7 @@ func (c *runtimeContainer) copyAllToContainer(ctx context.Context, cid string, a | |
} | ||
|
||
func (c *runtimeContainer) copyAllFromContainer(ctx context.Context, cid string, a *Action) (err error) { | ||
if !c.isRemote() || !c.copyBack { | ||
if !c.isRemote() || !c.runtimeFlags.CopyBack { | ||
return nil | ||
} | ||
// @todo it's a bad implementation considering consequential runs, need to find a better way to sync with remote. | ||
|
@@ -670,5 +700,5 @@ func (c *runtimeContainer) isSELinuxEnabled(ctx context.Context) bool { | |
} | ||
|
||
func (c *runtimeContainer) isRemote() bool { | ||
return c.isRemoteRuntime || c.isSetRemote | ||
return c.isRemoteRuntime || c.runtimeFlags.IsSetRemote | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Driver must not know about runtime flags. You can save flags in the struct, but move it back to runtime.