Skip to content
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

New command: build to build images using minikube #11164

Merged
merged 28 commits into from
Apr 25, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
af5828d
Add initial re-implementation of the build command
afbjorklund Mar 7, 2021
a274482
Add some basic support for setting the image tag
afbjorklund Mar 8, 2021
9ef5d25
Add support for build directory and Dockerfile
afbjorklund Mar 8, 2021
6f26e4b
Generate documentation for the build command
afbjorklund Mar 8, 2021
6cfbf2c
Move minikube build cmd to minikube image build
afbjorklund Mar 10, 2021
844c696
Make sure to show output from build cmd
afbjorklund Mar 10, 2021
c94a6d7
Make sure to pass any file param to build
afbjorklund Mar 10, 2021
f670368
Move absolute file path handling to machine
afbjorklund Mar 10, 2021
22150fb
Don't add build context to the default file
afbjorklund Mar 10, 2021
a8a8788
Don't fail when the default file is passed
afbjorklund Mar 10, 2021
02b4267
Add option for pushing image to registry
afbjorklund Mar 10, 2021
40cbe65
Improve comments and remove docker daemon
afbjorklund Mar 12, 2021
9f9958f
Allow building image from an url as well
afbjorklund Mar 12, 2021
db203cd
Allow building tarball from stdin stream
afbjorklund Mar 12, 2021
c961190
Allow passing environ and options to build
afbjorklund Mar 12, 2021
947e31a
Add git url support to containerd runtime
afbjorklund Mar 12, 2021
e230f02
Address lint append suggestions from gocritic
afbjorklund Mar 12, 2021
9516122
Add example parameters to the usage help text
afbjorklund Mar 16, 2021
c715324
Regenerate documentation for the unit test
afbjorklund Mar 24, 2021
f7e0777
Clean up duplicated function etc after merge
afbjorklund Mar 25, 2021
943561b
Clean up the order of the image commands
afbjorklund Mar 25, 2021
a5f835b
Add skeleton for minikube image integration test
afbjorklund Apr 21, 2021
93c40d1
Make sure to start buildkit socket for containerd
afbjorklund Apr 22, 2021
c9a0a7a
Move the BuildImage test over to functional test
afbjorklund Apr 23, 2021
5d8d3d3
Use canonical names for the functional test images
afbjorklund Apr 23, 2021
d508459
url.Parse treats DOS volumes as URL schemes
afbjorklund Apr 23, 2021
96e199c
Support building a path local to the machine
afbjorklund Apr 23, 2021
4d0c0c6
The docker container runtime doesn't show name
afbjorklund Apr 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add some basic support for setting the image tag
  • Loading branch information
afbjorklund committed Apr 21, 2021
commit a2744827c33135092bb8a847c640fa631f1d952a
7 changes: 6 additions & 1 deletion cmd/minikube/cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ import (
"k8s.io/minikube/pkg/minikube/reason"
)

var (
tag string
)

// buildCmd represents the build command
var buildCmd = &cobra.Command{
Use: "build",
Expand All @@ -42,11 +46,12 @@ minikube build .`,
exit.Error(reason.Usage, "loading profile", err)
}
img := args[0]
if err := machine.BuildImage(img, "test:latest", []*config.Profile{profile}); err != nil {
if err := machine.BuildImage(img, tag, []*config.Profile{profile}); err != nil {
exit.Error(reason.GuestImageBuild, "Failed to build image", err)
}
},
}

func init() {
buildCmd.Flags().StringVarP(&tag, "tag", "t", "", "Tag to apply to the new image (optional)")
}
10 changes: 9 additions & 1 deletion pkg/minikube/cruntime/containerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,19 @@ func (r *Containerd) RemoveImage(name string) error {
// BuildImage builds an image into this runtime
func (r *Containerd) BuildImage(path string, tag string) error {
klog.Infof("Building image: %s", path)
opt := ""
if tag != "" {
// add default tag if missing
if !strings.Contains(tag, ":") {
tag += ":latest"
}
opt = fmt.Sprintf(",name=%s", tag)
}
c := exec.Command("sudo", "buildctl", "build",
"--frontend", "dockerfile.v0",
"--local", fmt.Sprintf("context=%s", path),
"--local", fmt.Sprintf("dockerfile=%s", path),
"--output", fmt.Sprintf("type=image,name=%s", tag))
"--output", fmt.Sprintf("type=image%s", opt))
if _, err := r.Runner.RunCmd(c); err != nil {
return errors.Wrap(err, "buildctl build.")
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/minikube/cruntime/crio.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,11 @@ func (r *CRIO) RemoveImage(name string) error {
// BuildImage builds an image into this runtime
func (r *CRIO) BuildImage(path string, tag string) error {
klog.Infof("Building image: %s", path)
c := exec.Command("sudo", "podman", "build", "-t", tag, path)
args := []string{"podman", "build"}
if tag != "" {
args = append(args, "-t", tag)
}
c := exec.Command("sudo", args...)
if _, err := r.Runner.RunCmd(c); err != nil {
return errors.Wrap(err, "crio build image")
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/minikube/cruntime/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,11 @@ func (r *Docker) RemoveImage(name string) error {
// BuildImage builds an image into this runtime
func (r *Docker) BuildImage(path string, tag string) error {
klog.Infof("Building image: %s", path)
c := exec.Command("docker", "build", "-t", tag, path)
args := []string{"build"}
if tag != "" {
args = append(args, "-t", tag)
}
c := exec.Command("docker", args...)
if _, err := r.Runner.RunCmd(c); err != nil {
return errors.Wrap(err, "buildimage docker.")
}
Expand Down