Skip to content

Commit

Permalink
pkg/utils: Support Ubuntu distribution
Browse files Browse the repository at this point in the history
This allows using `--distro` and `--release` switches when creating
and entering containers.
This points to my personal repository on Docker Hub for the time being.

Signed-off-by: Ievgen Popovych <[email protected]>
  • Loading branch information
Jmennius committed Mar 21, 2021
1 parent 7a28e62 commit 475a1dd
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ var (
"ubi8",
false,
},
"ubuntu": {
"ubuntu-toolbox",
"ubuntu-toolbox",
parseReleaseUbuntu,
"docker.io",
"jmennius",
false,
},
}
)

Expand Down Expand Up @@ -633,6 +641,30 @@ func parseReleaseRHEL(str string) (string, error) {
return str, nil
}

func parseReleaseUbuntu(str string) (string, error) {
var releaseParts []string

if releaseParts = strings.Split(str, "."); len(releaseParts) != 2 {
return "", errors.New("release must contain a single dot")
}

releaseYear, err := strconv.Atoi(releaseParts[0])
if err != nil {
return "", err
}

releaseMonth, err := strconv.Atoi(releaseParts[1])
if err != nil {
return "", err
}

if releaseYear <= 0 || releaseMonth < 0 {
return "", errors.New("release must be composed of two positive integers")
}

return str, nil
}

// PathExists wraps around os.Stat providing a nice interface for checking an existence of a path.
func PathExists(path string) bool {
if _, err := os.Stat(path); !os.IsNotExist(err) {
Expand Down

0 comments on commit 475a1dd

Please sign in to comment.