Skip to content

Commit 4b8061d

Browse files
committed
Move cmd/image & cmd/builder to subpackages
Signed-off-by: apostasie <[email protected]>
1 parent 3ea64eb commit 4b8061d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+258
-196
lines changed

cmd/nerdctl/builder.go renamed to cmd/nerdctl/builder/builder.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
limitations under the License.
1515
*/
1616

17-
package main
17+
package builder
1818

1919
import (
2020
"fmt"
@@ -30,7 +30,7 @@ import (
3030
"github.com/containerd/nerdctl/v2/pkg/cmd/builder"
3131
)
3232

33-
func newBuilderCommand() *cobra.Command {
33+
func NewBuilderCommand() *cobra.Command {
3434
var builderCommand = &cobra.Command{
3535
Annotations: map[string]string{helpers.Category: helpers.Management},
3636
Use: "builder",
@@ -40,7 +40,7 @@ func newBuilderCommand() *cobra.Command {
4040
SilenceErrors: true,
4141
}
4242
builderCommand.AddCommand(
43-
newBuildCommand(),
43+
NewBuildCommand(),
4444
newBuilderPruneCommand(),
4545
newBuilderDebugCommand(),
4646
)
@@ -107,7 +107,7 @@ func processBuilderPruneOptions(cmd *cobra.Command) (types.BuilderPruneOptions,
107107
return types.BuilderPruneOptions{}, err
108108
}
109109

110-
buildkitHost, err := getBuildkitHost(cmd, globalOptions.Namespace)
110+
buildkitHost, err := GetBuildkitHost(cmd, globalOptions.Namespace)
111111
if err != nil {
112112
return types.BuilderPruneOptions{}, err
113113
}

cmd/nerdctl/builder_build.go renamed to cmd/nerdctl/builder/builder_build.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
limitations under the License.
1515
*/
1616

17-
package main
17+
package builder
1818

1919
import (
2020
"errors"
@@ -34,7 +34,7 @@ import (
3434
"github.com/containerd/nerdctl/v2/pkg/strutil"
3535
)
3636

37-
func newBuildCommand() *cobra.Command {
37+
func NewBuildCommand() *cobra.Command {
3838
var buildCommand = &cobra.Command{
3939
Use: "build [flags] PATH",
4040
Short: "Build an image from a Dockerfile. Needs buildkitd to be running.",
@@ -88,7 +88,7 @@ func processBuildCommandFlag(cmd *cobra.Command, args []string) (types.BuilderBu
8888
if err != nil {
8989
return types.BuilderBuildOptions{}, err
9090
}
91-
buildKitHost, err := getBuildkitHost(cmd, globalOptions.Namespace)
91+
buildKitHost, err := GetBuildkitHost(cmd, globalOptions.Namespace)
9292
if err != nil {
9393
return types.BuilderBuildOptions{}, err
9494
}
@@ -235,7 +235,7 @@ func processBuildCommandFlag(cmd *cobra.Command, args []string) (types.BuilderBu
235235
}, nil
236236
}
237237

238-
func getBuildkitHost(cmd *cobra.Command, namespace string) (string, error) {
238+
func GetBuildkitHost(cmd *cobra.Command, namespace string) (string, error) {
239239
if cmd.Flags().Changed("buildkit-host") || os.Getenv("BUILDKIT_HOST") != "" {
240240
// If address is explicitly specified, use it.
241241
buildkitHost, err := cmd.Flags().GetString("buildkit-host")

cmd/nerdctl/builder_build_linux_test.go renamed to cmd/nerdctl/builder/builder_build_linux_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
limitations under the License.
1515
*/
1616

17-
package main
17+
package builder
1818

1919
import (
2020
"fmt"
@@ -62,7 +62,7 @@ CMD ["echo", "test-nerdctl-build-context-oci-layout-parent"]`, testutil.CommonIm
6262

6363
// Unpack OCI archive into OCI layout directory.
6464
ociLayoutDir := t.TempDir()
65-
err := extractTarFile(ociLayoutDir, tarPath)
65+
err := helpers.ExtractTarFile(ociLayoutDir, tarPath)
6666
assert.NilError(t, err)
6767

6868
dockerfile = fmt.Sprintf(`FROM %s

cmd/nerdctl/builder_build_test.go renamed to cmd/nerdctl/builder/builder_build_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
limitations under the License.
1515
*/
1616

17-
package main
17+
package builder
1818

1919
import (
2020
"fmt"

cmd/nerdctl/builder_linux_test.go renamed to cmd/nerdctl/builder/builder_linux_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
limitations under the License.
1515
*/
1616

17-
package main
17+
package builder
1818

1919
import (
2020
"bytes"

cmd/nerdctl/builder/builder_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
Copyright The containerd Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package builder
18+
19+
import (
20+
"testing"
21+
22+
"github.com/containerd/nerdctl/v2/pkg/testutil"
23+
)
24+
25+
func TestMain(m *testing.M) {
26+
testutil.M(m)
27+
}

cmd/nerdctl/compose_run_linux_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727

2828
"github.com/containerd/log"
2929

30+
"github.com/containerd/nerdctl/v2/cmd/nerdctl/helpers"
3031
"github.com/containerd/nerdctl/v2/pkg/testutil"
3132
"github.com/containerd/nerdctl/v2/pkg/testutil/nettestutil"
3233
"github.com/containerd/nerdctl/v2/pkg/testutil/testregistry"
@@ -432,10 +433,10 @@ func TestComposePushAndPullWithCosignVerify(t *testing.T) {
432433
base := testutil.NewBase(t)
433434
base.Env = append(base.Env, "COSIGN_PASSWORD=1")
434435

435-
keyPair := newCosignKeyPair(t, "cosign-key-pair", "1")
436+
keyPair := helpers.NewCosignKeyPair(t, "cosign-key-pair", "1")
436437
reg := testregistry.NewWithNoAuth(base, 0, false)
437438
t.Cleanup(func() {
438-
keyPair.cleanup()
439+
keyPair.Cleanup()
439440
reg.Cleanup(nil)
440441
})
441442

@@ -475,8 +476,8 @@ services:
475476
x-nerdctl-sign: none
476477
entrypoint:
477478
- stty
478-
`, imageSvc0, keyPair.publicKey, keyPair.privateKey,
479-
imageSvc1, keyPair.privateKey, imageSvc2)
479+
`, imageSvc0, keyPair.PublicKey, keyPair.PrivateKey,
480+
imageSvc1, keyPair.PrivateKey, imageSvc2)
480481

481482
dockerfile := fmt.Sprintf(`FROM %s`, testutil.AlpineImage)
482483

cmd/nerdctl/container_run_linux_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"gotest.tools/v3/assert"
3636
"gotest.tools/v3/icmd"
3737

38+
"github.com/containerd/nerdctl/v2/cmd/nerdctl/helpers"
3839
"github.com/containerd/nerdctl/v2/pkg/rootlessutil"
3940
"github.com/containerd/nerdctl/v2/pkg/strutil"
4041
"github.com/containerd/nerdctl/v2/pkg/testutil"
@@ -70,7 +71,7 @@ func prepareCustomRootfs(base *testutil.Base, imageName string) string {
7071
base.Cmd("save", "-o", archiveTarPath, imageName).AssertOK()
7172
rootfs, err := os.MkdirTemp(base.T.TempDir(), "rootfs")
7273
assert.NilError(base.T, err)
73-
err = extractDockerArchive(archiveTarPath, rootfs)
74+
err = helpers.ExtractDockerArchive(archiveTarPath, rootfs)
7475
assert.NilError(base.T, err)
7576
return rootfs
7677
}

cmd/nerdctl/container_run_soci_linux_test.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"strings"
2222
"testing"
2323

24+
"github.com/containerd/nerdctl/v2/cmd/nerdctl/helpers"
2425
"github.com/containerd/nerdctl/v2/pkg/testutil"
2526
)
2627

@@ -41,7 +42,7 @@ func TestRunSoci(t *testing.T) {
4142
for _, tt := range tests {
4243
t.Run(tt.name, func(t *testing.T) {
4344
base := testutil.NewBase(t)
44-
requiresSoci(base)
45+
helpers.RequiresSoci(base)
4546

4647
//counting initial snapshot mounts
4748
initialMounts, err := exec.Command("mount").Output()
@@ -73,13 +74,3 @@ func TestRunSoci(t *testing.T) {
7374
})
7475
}
7576
}
76-
77-
func requiresSoci(base *testutil.Base) {
78-
info := base.Info()
79-
for _, p := range info.Plugins.Storage {
80-
if p == "soci" {
81-
return
82-
}
83-
}
84-
base.T.Skip("test requires soci")
85-
}

cmd/nerdctl/container_run_verify_linux_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ func TestRunVerifyCosign(t *testing.T) {
3535
base := testutil.NewBase(t)
3636
base.Env = append(base.Env, "COSIGN_PASSWORD=1")
3737

38-
keyPair := newCosignKeyPair(t, "cosign-key-pair", "1")
38+
keyPair := helpers.NewCosignKeyPair(t, "cosign-key-pair", "1")
3939
reg := testregistry.NewWithNoAuth(base, 0, false)
4040
t.Cleanup(func() {
41-
keyPair.cleanup()
41+
keyPair.Cleanup()
4242
reg.Cleanup(nil)
4343
})
4444

@@ -51,7 +51,7 @@ CMD ["echo", "nerdctl-build-test-string"]
5151
buildCtx := helpers.CreateBuildContext(t, dockerfile)
5252

5353
base.Cmd("build", "-t", testImageRef, buildCtx).AssertOK()
54-
base.Cmd("push", testImageRef, "--sign=cosign", "--cosign-key="+keyPair.privateKey).AssertOK()
55-
base.Cmd("run", "--rm", "--verify=cosign", "--cosign-key="+keyPair.publicKey, testImageRef).AssertOK()
54+
base.Cmd("push", testImageRef, "--sign=cosign", "--cosign-key="+keyPair.PrivateKey).AssertOK()
55+
base.Cmd("run", "--rm", "--verify=cosign", "--cosign-key="+keyPair.PublicKey, testImageRef).AssertOK()
5656
base.Cmd("run", "--rm", "--verify=cosign", "--cosign-key=dummy", testImageRef).AssertFail()
5757
}

0 commit comments

Comments
 (0)