-
Notifications
You must be signed in to change notification settings - Fork 362
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
Feature: build cluster image with buildah #1611
Feature: build cluster image with buildah #1611
Conversation
b89013c
to
0068f7a
Compare
Maybe the sealer imageSpec and image is not in need any more.
The ImageConfig is valuable probably.
We can store essential information in annotations of manifest from OCI v1 image.
For the Cmd and Arg, I think we don't need to record the data from parent image. |
0068f7a
to
9103c74
Compare
} | ||
|
||
return generateDigest(tmp) | ||
return "", nil |
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.
Ignore modification of this file.
@sealerio/sealer-maintainers @sealerio/sealer-reviewers Help me review this, plz. |
f9f99d0
to
34a7eee
Compare
Codecov Report
@@ Coverage Diff @@
## main #1611 +/- ##
==========================================
+ Coverage 14.04% 14.08% +0.03%
==========================================
Files 78 78
Lines 6691 6675 -16
==========================================
Hits 940 940
+ Misses 5637 5621 -16
Partials 114 114
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
6e538a6
to
7000139
Compare
8983c23
to
f1e76ff
Compare
test/testhelper/settings/common.go
Outdated
@@ -78,8 +78,8 @@ var ( | |||
AccessKey = os.Getenv("ACCESSKEYID") | |||
AccessSecret = os.Getenv("ACCESSKEYSECRET") | |||
Region = os.Getenv("RegionID") | |||
TestImageName = "" //default: registry.cn-qingdao.aliyuncs.com/sealer-io/kubernetes:v1.19.8 | |||
TestNydusImageName = "" //default: registry.cn-qingdao.aliyuncs.com/sealer-io/kubernetes-nydus:v1.19.8 | |||
TestImageName = "registry.cn-qingdao.aliyuncs.com/sealer-io/kubernetes:v1.19.8.test" //default: registry.cn-qingdao.aliyuncs.com/sealer-io/kubernetes:v1.19.8 |
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.
change it back before merging.
9cf1600
to
fbebb19
Compare
9250043
to
e6590e4
Compare
131b45b
to
c55919f
Compare
@justadogistaken Conflict happens. Please update this ASAP. And we will merge this with high priority. |
cbbe78f
to
fa5c8ba
Compare
/test apply |
apply/driver/local.go
Outdated
if err := applier.ImageEngine.RemoveContainer(&imagecommon.RemoveContainerOptions{ | ||
All: true, | ||
}); err != nil { | ||
logrus.Warnf("failed to clean the buildah contaienrs: %v", err) |
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.
typo, s/contaienrs/containers
@@ -60,48 +69,114 @@ build with args: | |||
sealer build -f Kubefile -t my-kubernetes:1.19.8 --build-arg MY_ARG=abc,PASSWORD=Sealer123 . | |||
`, | |||
RunE: func(cmd *cobra.Command, args []string) error { | |||
buildContext := args[0] | |||
return buildSealerImage() |
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.
Here you directly ignore the args, because you have not passed args into function buildSealerImage(). Then I am wondering if we could update Args: cobra.MaximumNArgs(1),
to be Args: cobra.NoArgs,
.
cmd/sealer/cmd/tag.go
Outdated
Example: `sealer tag kubernetes:v1.19.8 registry.cn-qingdao.aliyuncs.com/sealer-apps/kubernetes:v1.19.8`, | ||
Args: cobra.ExactArgs(2), | ||
Use: "tag", | ||
Short: "create a new tag that refers to a local ClusterImage", |
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.
create one or more tags? Since you allow to input multiple tags.
) | ||
|
||
// application image: if cluster cmd not nil, use cluster cmd directly | ||
if imageType == common.AppImage { | ||
if len(clusterCmd) != 0 { | ||
return clusterCmd | ||
} | ||
return image.Spec.ImageConfig.Cmd.Current | ||
return clusterCmd |
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.
if len(clusterCmd) != 0 {
return clusterCmd
}
return clusterCmd
I think the condition is useless. You can directly return clusterCmd
.
return options, kubefiles, nil | ||
} | ||
|
||
func (engine *Engine) build(cxt context.Context, kubefiles []string, options define.BuildOptions) (id string, err error) { |
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.
I found that this function always returns a nil-error. Is it reasonable? @justadogistaken
pkg/imageengine/buildah/commit.go
Outdated
return err | ||
} | ||
if len(candidates) == 0 { | ||
return errors.Errorf("error parsing target image name %q", image) |
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.
I suggest that you could print the detailed error reason, like xxx candidate name is empty
?
to add error message readability?
} | ||
|
||
func openBuilder(ctx context.Context, store storage.Store, name string) (builder *buildah.Builder, err error) { | ||
if name != "" { |
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.
What will happen if name
is empty string? The code logic seems to implicit when name
is empty string.
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.
Will "return nil, errors.Errorf("error finding build container")"
pkg/imageengine/buildah/common.go
Outdated
return context.TODO() | ||
} | ||
|
||
func getFormat(format string) (string, error) { |
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.
How about naming this function getImageType()
?
pkg/imageengine/buildah/copy.go
Outdated
return errors.Errorf("src must be specified") | ||
} | ||
if len(opts.DestinationInContainer) == 0 { | ||
return errors.Errorf("destination in container must be specifuled") |
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.
s/specifuled/specified
return nil | ||
} | ||
|
||
func onBuild(builder *buildah.Builder, quiet bool) error { |
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.
I suggest that we define this function like the following way:
func (builder *buildah.Builder) Build(quiet bool) error
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.
This function if copied from buildah.
pkg/imageengine/buildah/from.go
Outdated
size := len(args) | ||
if size > 1 { | ||
dest = args[size-1] | ||
args = args[:size-1] |
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.
try to use another name, like srcs = args[:size-1]
? although the original one has no incorrectness, different naming may bring more convenience.
pkg/imageengine/buildah/from.go
Outdated
case "WORKINGDIR": | ||
builder.SetWorkDir(strings.Join(args, " ")) | ||
default: | ||
logrus.Errorf("unknown OnBuild command %q; ignored", onBuildSpec) |
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.
I think we should return an error, since unexpected command is input. And we should consider it as illegal behaviour.
) | ||
|
||
// TODO do we have an util or unified local storage accessing pattern? | ||
func writeFileIfNotExist(path string, content []byte) error { |
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.
Quite strange for the function definition. We usually create one if it does not exist, but we seldom write it it the path does not exist. Maybe we could separate the function into two parts, createFileIfNotExist and writefile.
pkg/imageengine/buildah/manifest.go
Outdated
case "v2s2", "docker": | ||
manifestType = manifest.DockerV2Schema2MediaType | ||
default: | ||
return errors.Errorf("unknown format %q. Choose on of the supported formats: 'oci' or 'v2s2'", opts.Format) |
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.
s/on/one
pkg/imageengine/buildah/mount.go
Outdated
func (engine *Engine) Mount(opts *options.MountOptions) ([]options.JSONMount, error) { | ||
containers := opts.Containers | ||
if len(containers) == 0 { | ||
return []options.JSONMount{}, errors.Errorf("id/name of containers mube be specifiled") |
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.
s/specifiled/specified
s/mube/must
pkg/imageengine/buildah/push.go
Outdated
case "v2s2", "docker": | ||
manifestType = manifest.DockerV2Schema2MediaType | ||
default: | ||
return errors.Errorf("unknown format %q. Choose on of the supported formats: 'oci', 'v2s1', or 'v2s2'", opts.Format) |
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.
s/on/one
Signed-off-by: david.bao <[email protected]>
fa5c8ba
to
2dd7a0e
Compare
LGTM, great work 👍🏻 |
Describe what this PR does / why we need it
Sealer has integrated the buildah to build a cluster image.
But There are some todos.
How to save container images?
solution: scan the whole kubefile, pre-download all "http://" to build context. And check the
image:
of them, then save then in registry under build context. Finally add an instructionCOPY registry /
before real building procedure.Semantic translator.
All basic instructions are
FROM
,ADD
,COPY
,RUN
. We will implement all new instructions based on these basics.So we are going to need a Semantic translator.
A brief flow as following:
todos:
images
. Add label to image.