Skip to content

Commit

Permalink
pkg/utils: Offer built-in support for Arch Linux
Browse files Browse the repository at this point in the history
This allows using the 'distro' option to create and enter Arch Linux
containers.  Due to Arch's rolling-release model, the 'release' option
isn't required.  If 'release' is used, the accepted values are 'latest'
and 'rolling'.

containers#1311
  • Loading branch information
debarshiray committed Jun 12, 2023
1 parent ed76734 commit 2ee82af
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 1 deletion.
25 changes: 25 additions & 0 deletions src/pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ var (
releaseDefault string

supportedDistros = map[string]Distro{
"arch": {
"arch-toolbox",
"arch-toolbox",
false,
getDefaultReleaseArch,
getFullyQualifiedImageArch,
parseReleaseArch,
},
"fedora": {
"fedora-toolbox",
"fedora-toolbox",
Expand Down Expand Up @@ -309,6 +317,10 @@ func getDefaultReleaseForDistro(distro string) (string, error) {
return release, nil
}

func getDefaultReleaseArch() (string, error) {
return "latest", nil
}

func getDefaultReleaseFedora() (string, error) {
release, err := getHostVersionID()
if err != nil {
Expand Down Expand Up @@ -396,6 +408,11 @@ func GetFullyQualifiedImageFromDistros(image, release string) (string, error) {
return "", fmt.Errorf("failed to resolve image %s", image)
}

func getFullyQualifiedImageArch(image, release string) string {
imageFull := "quay.io/toolbx/" + image
return imageFull
}

func getFullyQualifiedImageFedora(image, release string) string {
imageFull := "registry.fedoraproject.org/" + image
return imageFull
Expand Down Expand Up @@ -711,6 +728,14 @@ func parseRelease(distro, release string) (string, error) {
return release, err
}

func parseReleaseArch(release string) (string, error) {
if release != "latest" && release != "rolling" && release != "" {
return "", &ParseReleaseError{"The release must be 'latest'."}
}

return "latest", nil
}

func parseReleaseFedora(release string) (string, error) {
if strings.HasPrefix(release, "F") || strings.HasPrefix(release, "f") {
release = release[1:]
Expand Down
20 changes: 20 additions & 0 deletions src/pkg/utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,26 @@ func TestParseRelease(t *testing.T) {
output string
errMsg string
}{
{
inputDistro: "arch",
inputRelease: "",
output: "latest",
},
{
inputDistro: "arch",
inputRelease: "latest",
output: "latest",
},
{
inputDistro: "arch",
inputRelease: "rolling",
output: "latest",
},
{
inputDistro: "arch",
inputRelease: "foo",
errMsg: "The release must be 'latest'.",
},
{
inputDistro: "fedora",
inputRelease: "f34",
Expand Down
1 change: 1 addition & 0 deletions test/system/000-setup.bats
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ load 'libs/helpers'
# Cache the default image for the system
_pull_and_cache_distro_image "$system_id" "$system_version" || false
# Cache all images that will be needed during the tests
_pull_and_cache_distro_image arch latest || false
_pull_and_cache_distro_image fedora 34 || false
_pull_and_cache_distro_image rhel 8.7 || false
_pull_and_cache_distro_image ubuntu 16.04 || false
Expand Down
52 changes: 52 additions & 0 deletions test/system/101-create.bats
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,48 @@ teardown() {
assert [ ${#lines[@]} -eq 4 ]
}

@test "create: Arch Linux" {
pull_distro_image arch latest

run $TOOLBOX --assumeyes create --distro arch

assert_success
assert_output --partial "Created container: arch-toolbox-latest"
assert_output --partial "Enter with: toolbox enter arch-toolbox-latest"

run podman ps -a

assert_output --regexp "Created[[:blank:]]+arch-toolbox-latest"
}

@test "create: Arch Linux ('--release latest')" {
pull_distro_image arch latest

run $TOOLBOX --assumeyes create --distro arch --release latest

assert_success
assert_output --partial "Created container: arch-toolbox-latest"
assert_output --partial "Enter with: toolbox enter arch-toolbox-latest"

run podman ps -a

assert_output --regexp "Created[[:blank:]]+arch-toolbox-latest"
}

@test "create: Arch Linux ('--release rolling')" {
pull_distro_image arch latest

run $TOOLBOX --assumeyes create --distro arch --release rolling

assert_success
assert_output --partial "Created container: arch-toolbox-latest"
assert_output --partial "Enter with: toolbox enter arch-toolbox-latest"

run podman ps -a

assert_output --regexp "Created[[:blank:]]+arch-toolbox-latest"
}

@test "create: Fedora 34" {
pull_distro_image fedora 34

Expand Down Expand Up @@ -178,6 +220,16 @@ teardown() {
assert_line --index 2 "Use 'toolbox --verbose ...' for further details."
}

@test "create: Try Arch Linux with an invalid release ('--release foo')" {
run $TOOLBOX --assumeyes create --distro arch --release foo

assert_failure
assert_line --index 0 "Error: invalid argument for '--release'"
assert_line --index 1 "The release must be 'latest'."
assert_line --index 2 "Run 'toolbox --help' for usage."
assert [ ${#lines[@]} -eq 3 ]
}

@test "create: Try Fedora with an invalid release ('--release -3')" {
run $TOOLBOX --assumeyes create --distro fedora --release -3

Expand Down
30 changes: 30 additions & 0 deletions test/system/102-list.bats
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,36 @@ teardown() {
assert [ ${#stderr_lines[@]} -eq 0 ]
}

@test "list: Arch Linux image" {
pull_distro_image arch latest

local num_of_images
num_of_images="$(list_images)"
assert_equal "$num_of_images" 1

run --keep-empty-lines --separate-stderr "$TOOLBOX" list

assert_success
assert_line --index 1 --partial "quay.io/toolbx/arch-toolbox:latest"
assert [ ${#lines[@]} -eq 3 ]
assert [ ${#stderr_lines[@]} -eq 0 ]
}

@test "list: Arch Linux image (using --images)" {
pull_distro_image arch latest

local num_of_images
num_of_images="$(list_images)"
assert_equal "$num_of_images" 1

run --keep-empty-lines --separate-stderr "$TOOLBOX" list --images

assert_success
assert_line --index 1 --partial "quay.io/toolbx/arch-toolbox:latest"
assert [ ${#lines[@]} -eq 3 ]
assert [ ${#stderr_lines[@]} -eq 0 ]
}

@test "list: Fedora 34 image" {
pull_distro_image fedora 34

Expand Down
30 changes: 30 additions & 0 deletions test/system/104-run.bats
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,36 @@ teardown() {
assert_output ""
}

@test "run: Smoke test with Arch Linux" {
create_distro_container arch latest arch-toolbox-latest

run --separate-stderr $TOOLBOX run --distro arch true

assert_success
assert [ ${#lines[@]} -eq 0 ]
assert [ ${#stderr_lines[@]} -eq 0 ]
}

@test "run: Smoke test with Arch Linux ('--release latest')" {
create_distro_container arch latest arch-toolbox-latest

run --separate-stderr $TOOLBOX run --distro arch --release latest true

assert_success
assert [ ${#lines[@]} -eq 0 ]
assert [ ${#stderr_lines[@]} -eq 0 ]
}

@test "run: Smoke test with Arch Linux ('--release rolling')" {
create_distro_container arch latest arch-toolbox-latest

run --separate-stderr $TOOLBOX run --distro arch --release rolling true

assert_success
assert [ ${#lines[@]} -eq 0 ]
assert [ ${#stderr_lines[@]} -eq 0 ]
}

@test "run: Smoke test with Fedora 34" {
create_distro_container fedora 34 fedora-toolbox-34

Expand Down
3 changes: 2 additions & 1 deletion test/system/libs/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ readonly TOOLBOX=${TOOLBOX:-$(command -v toolbox)}
readonly SKOPEO=${SKOPEO:-$(command -v skopeo)}

# Images
declare -Ag IMAGES=([busybox]="quay.io/toolbox_tests/busybox" \
declare -Ag IMAGES=([arch]="quay.io/toolbx/arch-toolbox" \
[busybox]="quay.io/toolbox_tests/busybox" \
[docker-reg]="quay.io/toolbox_tests/registry" \
[fedora]="registry.fedoraproject.org/fedora-toolbox" \
[rhel]="registry.access.redhat.com/ubi8/toolbox" \
Expand Down

0 comments on commit 2ee82af

Please sign in to comment.