Skip to content

Commit

Permalink
chore(RunConfig): rename Imagename -> ImageName (#1433)
Browse files Browse the repository at this point in the history
  • Loading branch information
rinor authored Feb 21, 2023
1 parent 83c1f21 commit 080fae7
Show file tree
Hide file tree
Showing 27 changed files with 51 additions and 51 deletions.
6 changes: 3 additions & 3 deletions cmd/cmd_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ func envBuild(cmd *cobra.Command, args []string) {
if c.Program == "" {
exitForCmd(cmd, "When creating an image, program must be specified in config file")
}
if c.RunConfig.Imagename == "" {
c.RunConfig.Imagename = c.Program
if c.RunConfig.ImageName == "" {
c.RunConfig.ImageName = c.Program
}
}
tmpRoot := false
Expand Down Expand Up @@ -139,7 +139,7 @@ func envBuild(cmd *cobra.Command, args []string) {
if err != nil {
log.Errorf("Failed to build image: %v", err)
} else {
fmt.Printf("On-prem image '%s' created...\n", c.RunConfig.Imagename)
fmt.Printf("On-prem image '%s' created...\n", c.RunConfig.ImageName)
}
}
cleanup:
Expand Down
2 changes: 1 addition & 1 deletion cmd/cmd_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func imageCreateCommandHandler(cmd *cobra.Command, args []string) {

imageName := c.CloudConfig.ImageName
if c.CloudConfig.Platform == onprem.ProviderName {
imageName = c.RunConfig.Imagename
imageName = c.RunConfig.ImageName
}

fmt.Printf("%s image '%s' created...\n", c.CloudConfig.Platform, imageName)
Expand Down
12 changes: 6 additions & 6 deletions cmd/flags_build_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@ func (flags *BuildImageCommandFlags) MergeToConfig(c *types.Config) (err error)
}

if flags.ImageName != "" {
c.RunConfig.Imagename = flags.ImageName
c.RunConfig.ImageName = flags.ImageName
}

setNanosBaseImage(c)

if c.RunConfig.Imagename == "" && c.Program != "" {
c.RunConfig.Imagename = c.Program
if c.RunConfig.ImageName == "" && c.Program != "" {
c.RunConfig.ImageName = c.Program
}

if c.RunConfig.Imagename != "" {
imageName := strings.Split(path.Base(c.RunConfig.Imagename), ".")[0]
if c.RunConfig.ImageName != "" {
imageName := strings.Split(path.Base(c.RunConfig.ImageName), ".")[0]
if imageName == "" {
imageName = lepton.GenerateImageName(filepath.Base(c.Program))
c.CloudConfig.ImageName = fmt.Sprintf("%v-image", filepath.Base(c.Program))
Expand All @@ -71,7 +71,7 @@ func (flags *BuildImageCommandFlags) MergeToConfig(c *types.Config) (err error)
images := path.Join(lepton.GetOpsHome(), "images")
imageName = path.Join(images, filepath.Base(imageName))
}
c.RunConfig.Imagename = imageName
c.RunConfig.ImageName = imageName
}

if c.Args != nil {
Expand Down
2 changes: 1 addition & 1 deletion cmd/flags_build_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestBuildImageFlagsMergeToConfig(t *testing.T) {
ImageName: "test-image",
},
RunConfig: types.RunConfig{
Imagename: imagesPath + "/test-image",
ImageName: imagesPath + "/test-image",
NetMask: "255.255.255.0",
},
Args: []string{"MyTestApp", "a b c d"},
Expand Down
4 changes: 2 additions & 2 deletions cmd/flags_pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ func (flags *PkgCommandFlags) MergeToConfig(c *types.Config) (err error) {
c.TargetRoot = pkgConfig.TargetRoot
}

imageName := c.RunConfig.Imagename
imageName := c.RunConfig.ImageName
images := path.Join(lepton.GetOpsHome(), "images")
if imageName == "" {
c.RunConfig.Imagename = path.Join(images, filepath.Base(pkgConfig.Program))
c.RunConfig.ImageName = path.Join(images, filepath.Base(pkgConfig.Program))
c.CloudConfig.ImageName = fmt.Sprintf("%v-image", filepath.Base(pkgConfig.Program))
} else if c.CloudConfig.ImageName == "" {
imageName = path.Join(images, filepath.Base(imageName))
Expand Down
2 changes: 1 addition & 1 deletion cmd/flags_pkg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func TestPkgFlagsMergeToConfig(t *testing.T) {
},
RunConfig: types.RunConfig{
Memory: "2G",
Imagename: lepton.GetOpsHome() + "/images/ops",
ImageName: lepton.GetOpsHome() + "/images/ops",
},
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func TestMergeMultipleFlags(t *testing.T) {

configFile := &types.Config{
RunConfig: types.RunConfig{
Imagename: "config-image-name",
ImageName: "config-image-name",
},
}

Expand All @@ -43,7 +43,7 @@ func TestMergeMultipleFlags(t *testing.T) {
err := container.Merge(config)

assert.Nil(t, err)
assert.Equal(t, config.RunConfig.Imagename, imagesPath+"/build-image")
assert.Equal(t, config.RunConfig.ImageName, imagesPath+"/build-image")
})

t.Run("if build image flags are placed before the config image flags imagename overrides the value", func(t *testing.T) {
Expand All @@ -55,6 +55,6 @@ func TestMergeMultipleFlags(t *testing.T) {

assert.Nil(t, err)

assert.Equal(t, config.RunConfig.Imagename, "config-image-name")
assert.Equal(t, config.RunConfig.ImageName, "config-image-name")
})
}
2 changes: 1 addition & 1 deletion cmd/run_local_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func RunLocalInstance(c *types.Config) (err error) {
}
}

fmt.Printf("booting %s ...\n", c.RunConfig.Imagename)
fmt.Printf("booting %s ...\n", c.RunConfig.ImageName)
hypervisor.Start(&c.RunConfig)

if tapDeviceName != "" {
Expand Down
2 changes: 1 addition & 1 deletion crossbuild/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (env *Environment) Boot() error {
}
cmd := hypervisor.Command(&types.RunConfig{
Accel: true,
Imagename: filepath.Join(EnvironmentImageDirPath, env.ID+EnvironmentImageFileExtension),
ImageName: filepath.Join(EnvironmentImageDirPath, env.ID+EnvironmentImageFileExtension),
Vga: true,
Memory: "2G",
Ports: []string{
Expand Down
4 changes: 2 additions & 2 deletions lepton/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ func addMappedFiles(src string, dest string, m *fs.Manifest) error {

func createImageFile(c *types.Config, m *fs.Manifest) error {
// produce final image, boot + kernel + elf
fd, err := createFile(c.RunConfig.Imagename)
fd, err := createFile(c.RunConfig.ImageName)
defer func() {
fd.Close()
}()
Expand Down Expand Up @@ -463,7 +463,7 @@ func createImageFile(c *types.Config, m *fs.Manifest) error {

mkfsCommand.SetUefi(c.UefiBoot)
}
mkfsCommand.SetFileSystemPath(c.RunConfig.Imagename)
mkfsCommand.SetFileSystemPath(c.RunConfig.ImageName)

err = mkfsCommand.Execute()
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions provider/aws/aws_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -754,13 +754,13 @@ func (p *AWS) SyncImage(config *types.Config, target lepton.Provider, image stri

// CustomizeImage returns image path with adaptations needed by cloud provider
func (p *AWS) CustomizeImage(ctx *lepton.Context) (string, error) {
imagePath := ctx.Config().RunConfig.Imagename
imagePath := ctx.Config().RunConfig.ImageName
return imagePath, nil
}

// not an archive - just raw disk image
func (p *AWS) getArchiveName(ctx *lepton.Context) string {
imagePath := ctx.Config().RunConfig.Imagename
imagePath := ctx.Config().RunConfig.ImageName
return imagePath
}

Expand Down
2 changes: 1 addition & 1 deletion provider/azure/azure_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (a *Azure) getArchiveName(ctx *lepton.Context) string {

// CustomizeImage returns image path with adaptations needed by cloud provider
func (a *Azure) CustomizeImage(ctx *lepton.Context) (string, error) {
imagePath := ctx.Config().RunConfig.Imagename
imagePath := ctx.Config().RunConfig.ImageName
symlink := filepath.Join(filepath.Dir(imagePath), "disk.raw")

if _, err := os.Lstat(symlink); err == nil {
Expand Down
2 changes: 1 addition & 1 deletion provider/digitalocean/digital_ocean_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (do *DigitalOcean) ResizeImage(ctx *lepton.Context, imagename string, hbyte

// CustomizeImage returns image path with adaptations needed by cloud provider
func (do *DigitalOcean) CustomizeImage(ctx *lepton.Context) (string, error) {
imagePath := ctx.Config().RunConfig.Imagename
imagePath := ctx.Config().RunConfig.ImageName
return imagePath, nil
}

Expand Down
2 changes: 1 addition & 1 deletion provider/gcp/gcp_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (p *GCloud) getArchiveName(ctx *lepton.Context) string {

// CustomizeImage returns image path with adaptations needed by cloud provider
func (p *GCloud) CustomizeImage(ctx *lepton.Context) (string, error) {
imagePath := ctx.Config().RunConfig.Imagename
imagePath := ctx.Config().RunConfig.ImageName
symlink := filepath.Join(filepath.Dir(imagePath), "disk.raw")

if _, err := os.Lstat(symlink); err == nil {
Expand Down
6 changes: 3 additions & 3 deletions provider/hyperv/hyperv_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (p *Provider) BuildImage(ctx *lepton.Context) (string, error) {
return "", err
}

err = os.Remove(c.RunConfig.Imagename)
err = os.Remove(c.RunConfig.ImageName)
if err != nil {
return "", err
}
Expand All @@ -61,7 +61,7 @@ func (p *Provider) BuildImageWithPackage(ctx *lepton.Context, pkgpath string) (s
return "", err
}

err = os.Remove(c.RunConfig.Imagename)
err = os.Remove(c.RunConfig.ImageName)
if err != nil {
return "", err
}
Expand All @@ -81,7 +81,7 @@ func (p *Provider) createVhdxImage(c *types.Config) (imagePath string, err error
args := []string{
"convert",
"-O", "vhdx",
c.RunConfig.Imagename, vhdxPath,
c.RunConfig.ImageName, vhdxPath,
}

cmd := exec.Command("qemu-img", args...)
Expand Down
6 changes: 3 additions & 3 deletions provider/oci/oci_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (p *Provider) BuildImage(ctx *lepton.Context) (string, error) {
return "", err
}

err = os.Remove(c.RunConfig.Imagename)
err = os.Remove(c.RunConfig.ImageName)
if err != nil {
return "", err
}
Expand All @@ -54,7 +54,7 @@ func (p *Provider) createQcow2Image(c *types.Config) (imagePath string, err erro
args := []string{
"convert",
"-O", "qcow2",
c.RunConfig.Imagename, imagePath,
c.RunConfig.ImageName, imagePath,
}

cmd := exec.Command("qemu-img", args...)
Expand Down Expand Up @@ -89,7 +89,7 @@ func (p *Provider) BuildImageWithPackage(ctx *lepton.Context, pkgpath string) (s
return "", err
}

err = os.Remove(c.RunConfig.Imagename)
err = os.Remove(c.RunConfig.ImageName)
if err != nil {
return "", err
}
Expand Down
2 changes: 1 addition & 1 deletion provider/oci/oci_image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func TestBuildImage(t *testing.T) {
imageName := "oci-build-image-test"

ctx.Config().CloudConfig.ImageName = imageName
ctx.Config().RunConfig.Imagename = imageName
ctx.Config().RunConfig.ImageName = imageName
ctx.Config().Program = testutils.BuildBasicProgram()
defer os.Remove(ctx.Config().Program)

Expand Down
6 changes: 3 additions & 3 deletions provider/onprem/onprem_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
func (p *OnPrem) BuildImage(ctx *lepton.Context) (string, error) {
c := ctx.Config()
err := lepton.BuildImage(*c)
return c.RunConfig.Imagename, err
return c.RunConfig.ImageName, err
}

// BuildImageWithPackage for onprem
Expand All @@ -24,7 +24,7 @@ func (p *OnPrem) BuildImageWithPackage(ctx *lepton.Context, pkgpath string) (str
if err != nil {
return "", err
}
return c.RunConfig.Imagename, nil
return c.RunConfig.ImageName, nil
}

// CreateImage on prem
Expand Down Expand Up @@ -122,7 +122,7 @@ func (p *OnPrem) SyncImage(config *types.Config, target lepton.Provider, image s
if err != nil {
return nil
}
config.RunConfig.Imagename = imagePath
config.RunConfig.ImageName = imagePath
config.CloudConfig.ImageName = image

// customizes image for target
Expand Down
4 changes: 2 additions & 2 deletions provider/onprem/onprem_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (p *OnPrem) CreateInstance(ctx *lepton.Context) error {
opshome := lepton.GetOpsHome()
imgpath := path.Join(opshome, "images", c.CloudConfig.ImageName)

c.RunConfig.Imagename = imgpath
c.RunConfig.ImageName = imgpath
c.RunConfig.Background = true

err := hypervisor.Start(&c.RunConfig)
Expand All @@ -71,7 +71,7 @@ func (p *OnPrem) CreateInstance(ctx *lepton.Context) error {

i := instance{
Instance: c.RunConfig.InstanceName,
Image: c.RunConfig.Imagename,
Image: c.RunConfig.ImageName,
Ports: c.RunConfig.Ports,
}

Expand Down
2 changes: 1 addition & 1 deletion provider/openstack/openstack_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,6 @@ func (o *OpenStack) SyncImage(config *types.Config, target lepton.Provider, imag

// CustomizeImage returns image path with adaptations needed by cloud provider
func (o *OpenStack) CustomizeImage(ctx *lepton.Context) (string, error) {
imagePath := ctx.Config().RunConfig.Imagename
imagePath := ctx.Config().RunConfig.ImageName
return imagePath, nil
}
2 changes: 1 addition & 1 deletion provider/proxmox/proxmox_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,6 @@ func (p *ProxMox) ResizeImage(ctx *lepton.Context, imagename string, hbytes stri

// CustomizeImage returns image path with adaptations needed by cloud provider
func (p *ProxMox) CustomizeImage(ctx *lepton.Context) (string, error) {
imagePath := ctx.Config().RunConfig.Imagename
imagePath := ctx.Config().RunConfig.ImageName
return imagePath, nil
}
4 changes: 2 additions & 2 deletions provider/upcloud/upcloud_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (p *Provider) BuildImage(ctx *lepton.Context) (string, error) {
return "", err
}

return c.RunConfig.Imagename, nil
return c.RunConfig.ImageName, nil
}

// BuildImageWithPackage creates local image using package image
Expand All @@ -32,7 +32,7 @@ func (p *Provider) BuildImageWithPackage(ctx *lepton.Context, pkgpath string) (s
return "", err
}

return ctx.Config().RunConfig.Imagename, nil
return ctx.Config().RunConfig.ImageName, nil
}

// CreateImage creates a storage object and upload image
Expand Down
6 changes: 3 additions & 3 deletions provider/vbox/vbox_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (p *Provider) BuildImage(ctx *lepton.Context) (string, error) {
return "", err
}

err = os.Remove(c.RunConfig.Imagename)
err = os.Remove(c.RunConfig.ImageName)
if err != nil {
return "", err
}
Expand All @@ -53,7 +53,7 @@ func (p *Provider) BuildImageWithPackage(ctx *lepton.Context, pkgpath string) (s
return "", err
}

err = os.Remove(c.RunConfig.Imagename)
err = os.Remove(c.RunConfig.ImageName)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -177,7 +177,7 @@ func (p *Provider) createVdiImage(c *types.Config) (imagePath string, err error)
args := []string{
"convert",
"-O", "vdi",
c.RunConfig.Imagename, imagePath,
c.RunConfig.ImageName, imagePath,
}

cmd := exec.Command("qemu-img", args...)
Expand Down
2 changes: 1 addition & 1 deletion provider/vsphere/vsphere_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,6 @@ func (v *Vsphere) SyncImage(config *types.Config, target lepton.Provider, image

// CustomizeImage returns image path with adaptations needed by cloud provider
func (v *Vsphere) CustomizeImage(ctx *lepton.Context) (string, error) {
imagePath := ctx.Config().RunConfig.Imagename
imagePath := ctx.Config().RunConfig.ImageName
return imagePath, nil
}
2 changes: 1 addition & 1 deletion provider/vultr/vultr_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,6 @@ func (v *Vultr) ResizeImage(ctx *lepton.Context, imagename string, hbytes string

// CustomizeImage returns image path with adaptations needed by cloud provider
func (v *Vultr) CustomizeImage(ctx *lepton.Context) (string, error) {
imagePath := ctx.Config().RunConfig.Imagename
imagePath := ctx.Config().RunConfig.ImageName
return imagePath, nil
}
2 changes: 1 addition & 1 deletion qemu/qemu_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ func (q *qemu) addAccel() (bool, error) {

func (q *qemu) setConfig(rconfig *types.RunConfig) {
// add virtio drive
q.addDrive("hd0", rconfig.Imagename, "none")
q.addDrive("hd0", rconfig.ImageName, "none")

pciBus := ""
if isx86() {
Expand Down
Loading

0 comments on commit 080fae7

Please sign in to comment.