Skip to content

Commit

Permalink
Merge pull request #2427 from yankay/support-test-integration-docker-…
Browse files Browse the repository at this point in the history
…23-compatibility

Support Docker 23.0 compatibility
  • Loading branch information
AkihiroSuda authored Aug 14, 2023
2 parents 61b0fcf + 0844a51 commit b18c4a1
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 22 deletions.
15 changes: 2 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,26 +181,15 @@ jobs:
go-version: ${{ env.GO_VERSION }}
cache: true
check-latest: true
# Docker >= 23 is still unsupported: https://github.com/containerd/nerdctl/issues/2421
- name: "Install Docker 20.10"
- name: "Enable BuildKit"
run: |
set -eux -o pipefail
# Uninstall the preinstalled Docker (Moby)
sudo apt-get remove moby-*
# Enable BuildKit explicitly
sudo apt-get install -y moreutils
cat /etc/docker/daemon.json
jq '.features.buildkit = true' </etc/docker/daemon.json | sudo sponge /etc/docker/daemon.json
cat /etc/docker/daemon.json
# Download Docker packages
curl -OSL https://download.docker.com/linux/ubuntu/dists/jammy/pool/stable/amd64/containerd.io_1.6.22-1_amd64.deb
curl -OSL https://download.docker.com/linux/ubuntu/dists/jammy/pool/stable/amd64/docker-ce_20.10.24~3-0~ubuntu-jammy_amd64.deb
curl -OSL https://download.docker.com/linux/ubuntu/dists/jammy/pool/stable/amd64/docker-ce-cli_20.10.24~3-0~ubuntu-jammy_amd64.deb
curl -OSL https://download.docker.com/linux/ubuntu/dists/jammy/pool/stable/amd64/docker-buildx-plugin_0.11.2-1~ubuntu.22.04~jammy_amd64.deb
curl -OSL https://download.docker.com/linux/ubuntu/dists/jammy/pool/stable/amd64/docker-compose-plugin_2.20.2-1~ubuntu.22.04~jammy_amd64.deb
# Install Docker
sudo apt-get install -y ./*.deb
rm -f ./*.deb
sudo systemctl restart docker
# Print docker info
docker info
docker version
Expand Down
4 changes: 0 additions & 4 deletions cmd/nerdctl/builder_build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,6 @@ CMD echo $TEST_STRING
base.Cmd("run", "--rm", imageName).AssertOutExactly(tc.expected)
})
}

t.Run("InvalidBuildArgCausesError", func(t *testing.T) {
base.Cmd("build", buildCtx, "-t", imageName, "--build-arg", "=TEST_STRING").AssertFail()
})
}

func TestBuildWithIIDFile(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion cmd/nerdctl/compose_up_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ services:
Err: `exec: \"invalid\": executable file not found in $PATH`,
}
if base.Target == testutil.Docker {
expected.Err = `Unknown runtime specified invalid`
expected.Err = `unknown or invalid runtime name: invalid`
}
c.Assert(expected)
}
Expand Down
6 changes: 5 additions & 1 deletion cmd/nerdctl/system_prune_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ func TestSystemPrune(t *testing.T) {
base.Cmd("volume", "create", vID).AssertOK()
defer base.Cmd("volume", "rm", vID).Run()

vID2 := base.Cmd("volume", "create").Out()
defer base.Cmd("volume", "rm", vID2).Run()

tID := testutil.Identifier(t)
base.Cmd("run", "-v", fmt.Sprintf("%s:/volume", vID), "--net", nID,
"--name", tID, testutil.CommonImage).AssertOK()
Expand All @@ -55,7 +58,8 @@ func TestSystemPrune(t *testing.T) {
base.Cmd("images").AssertOutContains(testutil.ImageRepo(testutil.CommonImage))

base.Cmd("system", "prune", "-f", "--volumes", "--all").AssertOK()
base.Cmd("volume", "ls").AssertNoOut(vID)
base.Cmd("volume", "ls").AssertOutContains(vID) // docker system prune --all --volume does not prune named volume
base.Cmd("volume", "ls").AssertNoOut(vID2) // docker system prune --all --volume prune anonymous volume
base.Cmd("ps", "-a").AssertNoOut(tID)
base.Cmd("network", "ls").AssertNoOut(nID)
base.Cmd("images").AssertNoOut(testutil.ImageRepo(testutil.CommonImage))
Expand Down
7 changes: 7 additions & 0 deletions cmd/nerdctl/volume_prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func newVolumePruneCommand() *cobra.Command {
SilenceUsage: true,
SilenceErrors: true,
}
volumePruneCommand.Flags().BoolP("all", "a", false, "Remove all unused volumes, not just anonymous ones")
volumePruneCommand.Flags().BoolP("force", "f", false, "Do not prompt for confirmation")
return volumePruneCommand
}
Expand All @@ -45,13 +46,19 @@ func processVolumePruneOptions(cmd *cobra.Command) (types.VolumePruneOptions, er
return types.VolumePruneOptions{}, err
}

all, err := cmd.Flags().GetBool("all")
if err != nil {
return types.VolumePruneOptions{}, err
}

force, err := cmd.Flags().GetBool("force")
if err != nil {
return types.VolumePruneOptions{}, err
}

options := types.VolumePruneOptions{
GOptions: globalOptions,
All: all,
Force: force,
Stdout: cmd.OutOrStdout(),
}
Expand Down
8 changes: 5 additions & 3 deletions cmd/nerdctl/volume_prune_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,21 @@ import (
func TestVolumePrune(t *testing.T) {
base := testutil.NewBase(t)
tID := testutil.Identifier(t)
base.Cmd("volume", "prune", "-f").Run()
base.Cmd("volume", "prune", "-a", "-f").Run()

vID := base.Cmd("volume", "create").Out()
base.Cmd("volume", "create", tID+"-1").AssertOK()
base.Cmd("volume", "create", tID+"-2").AssertOK()

base.Cmd("run", "-v", fmt.Sprintf("%s:/volume", tID+"-1"), "--name", tID, testutil.CommonImage).AssertOK()
defer base.Cmd("rm", "-f", tID).Run()

base.Cmd("volume", "prune", "-f").AssertOutContains(tID + "-2")
base.Cmd("volume", "prune", "-f").AssertOutContains(vID)
base.Cmd("volume", "prune", "-a", "-f").AssertOutContains(tID + "-2")
base.Cmd("volume", "ls").AssertOutContains(tID + "-1")
base.Cmd("volume", "ls").AssertNoOut(tID + "-2")

base.Cmd("rm", "-f", tID).AssertOK()
base.Cmd("volume", "prune", "-f").AssertOK()
base.Cmd("volume", "prune", "-a", "-f").AssertOK()
base.Cmd("volume", "ls").AssertNoOut(tID + "-1")
}
2 changes: 2 additions & 0 deletions pkg/api/types/volume_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ type VolumeListOptions struct {
type VolumePruneOptions struct {
Stdout io.Writer
GOptions GlobalCommandOptions
//Remove all unused volumes, not just anonymous ones
All bool
// Do not prompt for confirmation
Force bool
}
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/system/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func Prune(ctx context.Context, client *containerd.Client, options types.SystemP
if options.Volumes {
if err := volume.Prune(ctx, client, types.VolumePruneOptions{
GOptions: options.GOptions,
All: false,
Force: true,
Stdout: options.Stdout,
}); err != nil {
Expand Down
8 changes: 8 additions & 0 deletions pkg/cmd/volume/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

"github.com/containerd/containerd"
"github.com/containerd/nerdctl/pkg/api/types"
"github.com/containerd/nerdctl/pkg/labels"
)

func Prune(ctx context.Context, client *containerd.Client, options types.VolumePruneOptions) error {
Expand All @@ -47,6 +48,13 @@ func Prune(ctx context.Context, client *containerd.Client, options types.VolumeP
if _, ok := usedVolumes[volume.Name]; ok {
continue
}
if !options.All {
val, ok := (*volume.Labels)[labels.AnonymousVolumes]
//skip the named volume and only remove the anonymous volume
if !ok || val != "" {
continue
}
}
removeNames = append(removeNames, volume.Name)
}
removedNames, err := volStore.Remove(removeNames)
Expand Down

0 comments on commit b18c4a1

Please sign in to comment.