@@ -22,19 +22,22 @@ import (
22
22
23
23
type Profile struct {
24
24
name string
25
- Default bool `yaml:"default" mapstructure:"default"`
26
- Image string `yaml:"image" mapstructure:"image"`
27
- ImageAMD64 string `yaml:"image_amd64" mapstructure:"image_amd64"`
28
- ImageARM64 string `yaml:"image_arm64" mapstructure:"image_arm64"`
29
- Arch string `yaml:"arch" mapstructure:"arch"`
30
- MinimumDate time.Time `yaml:"minimum_date" mapstructure:"minimum_date"`
31
- UpdateInterval time.Duration `yaml:"update_interval" mapstructure:"update_interval"`
32
- Persistent bool `yaml:"persistent" mapstructure:"persistent"`
33
- SSH bool `yaml:"ssh" mapstructure:"ssh"`
34
- NetRC bool `yaml:"netrc" mapstructure:"netrc"`
35
- User string `yaml:"user" mapstructure:"user"`
36
- Group string `yaml:"group" mapstructure:"group"`
37
- Path string `yaml:"path" mapstructure:"path"`
25
+ Default bool `mapstructure:"default" yaml:"default"`
26
+ Image string `mapstructure:"image" yaml:"image"`
27
+ ImageAMD64 string `mapstructure:"image_amd64" yaml:"image_amd64"`
28
+ Image386 string `mapstructure:"image_386" yaml:"image_386"`
29
+ ImageARM64 string `mapstructure:"image_arm64" yaml:"image_arm64"`
30
+ ImageARM string `mapstructure:"image_arm" yaml:"image_arm"`
31
+ ImageARMv6 string `mapstructure:"image_arm_v6" yaml:"image_arm_v6"`
32
+ Arch string `mapstructure:"arch" yaml:"arch"`
33
+ MinimumDate time.Time `mapstructure:"minimum_date" yaml:"minimum_date"`
34
+ UpdateInterval time.Duration `mapstructure:"update_interval" yaml:"update_interval"`
35
+ Persistent bool `mapstructure:"persistent" yaml:"persistent"`
36
+ SSH bool `mapstructure:"ssh" yaml:"ssh"`
37
+ NetRC bool `mapstructure:"netrc" yaml:"netrc"`
38
+ User string `mapstructure:"user" yaml:"user"`
39
+ Group string `mapstructure:"group" yaml:"group"`
40
+ Path string `mapstructure:"path" yaml:"path"`
38
41
}
39
42
40
43
var activeProfile = & Profile {}
@@ -142,16 +145,17 @@ func parseConfigs() error {
142
145
flag .StringVar (& cfgPath , "config" , userCfgPath , "config file" )
143
146
flag .StringVar (& profileName , "profile" , defProfileName , "profile name" )
144
147
flag .StringVar (& activeProfile .Image , "image" , activeProfile .Image , "docker image name" )
145
- flag .StringVar (& activeProfile .Arch , "arch" , activeProfile .Arch , "architecture (\" amd64\" or \" arm64\" )" )
148
+ flag .StringVar (& activeProfile .Arch , "arch" , activeProfile .Arch , "architecture (\" amd64\" , \" arm64\" , \" 386 \" , \" arm \" , \" arm/v6 \" )" )
146
149
flag .StringVar (& activeProfile .User , "user" , activeProfile .User , "user to map to inside the canon environment" )
147
150
flag .StringVar (& activeProfile .Group , "group" , activeProfile .Group , "group to map to inside the canon environment" )
148
151
flag .BoolVar (& activeProfile .SSH , "ssh" , activeProfile .SSH , "mount ~/.ssh (read-only) and forward SSH_AUTH_SOCK to the canon environment" )
149
152
flag .BoolVar (& activeProfile .NetRC , "netrc" , activeProfile .NetRC , "mount ~/.netrc (read-only) in the canon environment" )
150
153
151
154
flag .Parse ()
155
+
152
156
// swap again in case a CLI arg would change arch
153
157
swapArchImage (activeProfile )
154
- return nil
158
+ return validateArch ( activeProfile . Arch )
155
159
}
156
160
157
161
func findProjectConfig () (string , error ) {
@@ -247,8 +251,11 @@ func mergeProfile(in interface{}, out *Profile) error {
247
251
if err := mapDecode (in , tempProf ); err != nil {
248
252
return err
249
253
}
250
- if tempProf .ImageAMD64 != "" || tempProf .ImageARM64 != "" {
251
- out .Image = ""
254
+ for _ , img := range []string {tempProf .ImageAMD64 , tempProf .ImageARM64 , tempProf .ImageARM , tempProf .ImageARMv6 , tempProf .Image386 } {
255
+ if img != "" {
256
+ out .Image = ""
257
+ break
258
+ }
252
259
}
253
260
return mapDecode (in , out )
254
261
}
@@ -380,15 +387,30 @@ func checkAll(args []string) bool {
380
387
381
388
func swapArchImage (profile * Profile ) {
382
389
// abort if image is overridden and not one of the swapable options
383
- if profile .Image != "" && profile .Image != profile .ImageAMD64 && profile .Image != profile .ImageARM64 {
390
+ var canSwap bool
391
+ for _ , img := range []string {profile .ImageAMD64 , profile .ImageARM64 , profile .ImageARM , profile .ImageARMv6 , profile .Image386 } {
392
+ if profile .Image == "" || img == profile .Image {
393
+ canSwap = true
394
+ break
395
+ }
396
+ }
397
+ if ! canSwap {
384
398
return
385
399
}
386
400
387
- if profile .Arch == "amd64" && profile .ImageAMD64 != "" {
401
+ switch profile .Arch {
402
+ case "amd64" :
388
403
profile .Image = profile .ImageAMD64
389
- }
390
- if profile .Arch == "arm64" && profile .ImageARM64 != "" {
404
+ case "arm64" :
391
405
profile .Image = profile .ImageARM64
406
+ case "arm" :
407
+ profile .Image = profile .ImageARM
408
+ case "arm/v6" :
409
+ profile .Image = profile .ImageARMv6
410
+ case "386" :
411
+ profile .Image = profile .Image386
412
+ default :
413
+ profile .Image = ""
392
414
}
393
415
}
394
416
@@ -412,3 +434,52 @@ func mapDecode(iface interface{}, p *Profile) error {
412
434
}
413
435
return dec .Decode (iface )
414
436
}
437
+
438
+ func validateArch (arch string ) error {
439
+ switch arch {
440
+ case "amd64" :
441
+ fallthrough
442
+ case "arm64" :
443
+ fallthrough
444
+ case "arm" :
445
+ fallthrough
446
+ case "arm/v6" :
447
+ fallthrough
448
+ case "386" :
449
+ return nil
450
+
451
+ case "armv7" :
452
+ fallthrough
453
+ case "armv7l" :
454
+ fallthrough
455
+ case "armhf" :
456
+ fallthrough
457
+ case "arm/v7" :
458
+ return errors .New ("Invalid architecture: " + arch + "; Use just \" arm\" " )
459
+
460
+ case "armv6" :
461
+ fallthrough
462
+ case "armv6l" :
463
+ fallthrough
464
+ case "armel" :
465
+ return errors .New ("Invalid architecture: " + arch + "; Use \" arm/v6\" " )
466
+
467
+ case "x86_64" :
468
+ return errors .New ("Invalid architecture: " + arch + "; Use \" amd64\" " )
469
+
470
+ case "arm/v8" :
471
+ fallthrough
472
+ case "aarch64" :
473
+ return errors .New ("Invalid architecture: " + arch + "; Use \" arm64\" " )
474
+
475
+ case "x86" :
476
+ fallthrough
477
+ case "i386" :
478
+ fallthrough
479
+ case "i686" :
480
+ return errors .New ("Invalid architecture: " + arch + "; Use \" 386\" " )
481
+
482
+ default :
483
+ return errors .New ("Invalid architecture: " + arch )
484
+ }
485
+ }
0 commit comments