diff --git a/buildkitd.go b/buildkitd.go index a2e65cc..e4c233f 100644 --- a/buildkitd.go +++ b/buildkitd.go @@ -3,7 +3,6 @@ package task import ( "fmt" "io" - "io/ioutil" "net/url" "os" "os/exec" @@ -101,7 +100,7 @@ func SpawnBuildkitd(req Request, opts *BuildkitdOpts) (*Buildkitd, error) { } for { - err := buildctl(addr, ioutil.Discard, "debug", "workers") + err := buildctl(addr, io.Discard, "debug", "workers") if err == nil { break } @@ -149,8 +148,7 @@ func generateConfig(req Request, configPath string) error { var config BuildkitdConfig if len(req.Config.RegistryMirrors) > 0 { - var registryConfigs map[string]RegistryConfig - registryConfigs = make(map[string]RegistryConfig) + var registryConfigs = make(map[string]RegistryConfig) registryConfigs["docker.io"] = RegistryConfig{ Mirrors: req.Config.RegistryMirrors, } diff --git a/buildkitd_test.go b/buildkitd_test.go index 0d78f6c..ddded9b 100644 --- a/buildkitd_test.go +++ b/buildkitd_test.go @@ -1,7 +1,6 @@ package task_test import ( - "io/ioutil" "os" "path/filepath" "testing" @@ -30,7 +29,7 @@ func (s *BuildkitdSuite) TearDownSuite() { func (s *BuildkitdSuite) SetupTest() { var err error - s.outputsDir, err = ioutil.TempDir("", "oci-build-task-test") + s.outputsDir, err = os.MkdirTemp("", "oci-build-task-test") s.NoError(err) s.req = task.Request{ @@ -64,10 +63,10 @@ func (s *BuildkitdSuite) TestGenerateConfig() { }) s.NoError(err) - configContent, err := ioutil.ReadFile(s.configPath("mirrors.toml")) + configContent, err := os.ReadFile(s.configPath("mirrors.toml")) s.NoError(err) - expectedContent, err := ioutil.ReadFile("testdata/buildkitd-config/mirrors.toml") + expectedContent, err := os.ReadFile("testdata/buildkitd-config/mirrors.toml") s.NoError(err) s.Equal(expectedContent, configContent) diff --git a/task.go b/task.go index c5778b8..9de7e2a 100644 --- a/task.go +++ b/task.go @@ -4,7 +4,6 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -25,7 +24,7 @@ func StoreSecret(req *Request, name, value string) error { if err != nil { return fmt.Errorf("unable to create secret directory: %w", err) } - err = ioutil.WriteFile(secretFile, []byte(value), 0600) + err = os.WriteFile(secretFile, []byte(value), 0600) if err != nil { return fmt.Errorf("unable to write secret to file: %w", err) } @@ -296,7 +295,7 @@ func loadOciImages(imagePaths []string, req Request) error { func writeDigest(dest string, digest v1.Hash) error { digestPath := filepath.Join(dest, "digest") - err := ioutil.WriteFile(digestPath, []byte(digest.String()), 0644) + err := os.WriteFile(digestPath, []byte(digest.String()), 0644) if err != nil { return errors.Wrap(err, "write digest file") } @@ -360,7 +359,7 @@ func sanitize(cfg *Config) error { } if cfg.TargetFile != "" { - target, err := ioutil.ReadFile(cfg.TargetFile) + target, err := os.ReadFile(cfg.TargetFile) if err != nil { return errors.Wrap(err, "read target file") } @@ -369,7 +368,7 @@ func sanitize(cfg *Config) error { } if cfg.BuildArgsFile != "" { - buildArgs, err := ioutil.ReadFile(cfg.BuildArgsFile) + buildArgs, err := os.ReadFile(cfg.BuildArgsFile) if err != nil { return errors.Wrap(err, "read build args file") } @@ -385,7 +384,7 @@ func sanitize(cfg *Config) error { } if cfg.LabelsFile != "" { - Labels, err := ioutil.ReadFile(cfg.LabelsFile) + Labels, err := os.ReadFile(cfg.LabelsFile) if err != nil { return errors.Wrap(err, "read labels file") } diff --git a/task_test.go b/task_test.go index f498f14..2681bda 100644 --- a/task_test.go +++ b/task_test.go @@ -3,7 +3,6 @@ package task_test import ( "encoding/json" "fmt" - "io/ioutil" "net/http/httptest" "net/url" "os" @@ -46,7 +45,7 @@ func (s *TaskSuite) TearDownSuite() { func (s *TaskSuite) SetupTest() { var err error - s.outputsDir, err = ioutil.TempDir("", "oci-build-task-test") + s.outputsDir, err = os.MkdirTemp("", "oci-build-task-test") s.NoError(err) err = os.Mkdir(s.imagePath(), 0755) @@ -88,7 +87,7 @@ func (s *TaskSuite) TestDigestFile() { _, err := s.build() s.NoError(err) - digest, err := ioutil.ReadFile(s.imagePath("digest")) + digest, err := os.ReadFile(s.imagePath("digest")) s.NoError(err) image, err := tarball.ImageFromPath(s.imagePath("image.tar"), nil) @@ -240,10 +239,10 @@ func (s *TaskSuite) TestUnpackRootfs() { meta, err := s.imageMetadata("image") s.NoError(err) - rootfsContent, err := ioutil.ReadFile(s.imagePath("rootfs", "Dockerfile")) + rootfsContent, err := os.ReadFile(s.imagePath("rootfs", "Dockerfile")) s.NoError(err) - expectedContent, err := ioutil.ReadFile("testdata/unpack-rootfs/Dockerfile") + expectedContent, err := os.ReadFile("testdata/unpack-rootfs/Dockerfile") s.NoError(err) s.Equal(rootfsContent, expectedContent) @@ -287,7 +286,7 @@ func (s *TaskSuite) TestRegistryMirrors() { s.req.Config.ContextDir = "testdata/mirror" s.req.Config.RegistryMirrors = []string{mirrorURL.Host} - rootDir, err := ioutil.TempDir("", "mirrored-buildkitd") + rootDir, err := os.MkdirTemp("", "mirrored-buildkitd") s.NoError(err) defer os.RemoveAll(rootDir) @@ -324,7 +323,7 @@ func (s *TaskSuite) TestRegistryMirrors() { } func (s *TaskSuite) TestImageArgs() { - imagesDir, err := ioutil.TempDir("", "preload-images") + imagesDir, err := os.MkdirTemp("", "preload-images") s.NoError(err) defer os.RemoveAll(imagesDir) @@ -382,7 +381,7 @@ func (s *TaskSuite) TestImageArgs() { } func (s *TaskSuite) TestImageArgsWithUppercaseName() { - imagesDir, err := ioutil.TempDir("", "preload-images") + imagesDir, err := os.MkdirTemp("", "preload-images") s.NoError(err) defer os.RemoveAll(imagesDir) @@ -405,10 +404,10 @@ func (s *TaskSuite) TestImageArgsWithUppercaseName() { meta, err := s.imageMetadata("image") s.NoError(err) - rootfsContent, err := ioutil.ReadFile(s.imagePath("rootfs", "Dockerfile.second")) + rootfsContent, err := os.ReadFile(s.imagePath("rootfs", "Dockerfile.second")) s.NoError(err) - expectedContent, err := ioutil.ReadFile("testdata/image-args/Dockerfile.uppercase") + expectedContent, err := os.ReadFile("testdata/image-args/Dockerfile.uppercase") s.NoError(err) s.Equal(rootfsContent, expectedContent) @@ -418,7 +417,7 @@ func (s *TaskSuite) TestImageArgsWithUppercaseName() { } func (s *TaskSuite) TestImageArgsUnpack() { - imagesDir, err := ioutil.TempDir("", "preload-images") + imagesDir, err := os.MkdirTemp("", "preload-images") s.NoError(err) defer os.RemoveAll(imagesDir) @@ -442,10 +441,10 @@ func (s *TaskSuite) TestImageArgsUnpack() { meta, err := s.imageMetadata("image") s.NoError(err) - rootfsContent, err := ioutil.ReadFile(s.imagePath("rootfs", "Dockerfile.second")) + rootfsContent, err := os.ReadFile(s.imagePath("rootfs", "Dockerfile.second")) s.NoError(err) - expectedContent, err := ioutil.ReadFile("testdata/image-args/Dockerfile") + expectedContent, err := os.ReadFile("testdata/image-args/Dockerfile") s.NoError(err) s.Equal(rootfsContent, expectedContent) @@ -517,7 +516,7 @@ func (s *TaskSuite) TestMultiTargetDigest() { additionalImage, err := tarball.ImageFromPath(s.outputPath("additional-target", "image.tar"), nil) s.NoError(err) - digest, err := ioutil.ReadFile(s.outputPath("additional-target", "digest")) + digest, err := os.ReadFile(s.outputPath("additional-target", "digest")) s.NoError(err) additionalManifest, err := additionalImage.Manifest() s.NoError(err) @@ -525,7 +524,7 @@ func (s *TaskSuite) TestMultiTargetDigest() { finalImage, err := tarball.ImageFromPath(s.imagePath("image.tar"), nil) s.NoError(err) - digest, err = ioutil.ReadFile(s.outputPath("image", "digest")) + digest, err = os.ReadFile(s.outputPath("image", "digest")) s.NoError(err) finalManifest, err := finalImage.Manifest() s.NoError(err) @@ -543,9 +542,9 @@ func (s *TaskSuite) TestMultiTargetUnpack() { _, err = s.build() s.NoError(err) - rootfsContent, err := ioutil.ReadFile(s.outputPath("additional-target", "rootfs", "Dockerfile.banana")) + rootfsContent, err := os.ReadFile(s.outputPath("additional-target", "rootfs", "Dockerfile.banana")) s.NoError(err) - expectedContent, err := ioutil.ReadFile("testdata/multi-target/Dockerfile") + expectedContent, err := os.ReadFile("testdata/multi-target/Dockerfile") s.NoError(err) s.Equal(rootfsContent, expectedContent) @@ -554,9 +553,9 @@ func (s *TaskSuite) TestMultiTargetUnpack() { s.Equal(meta.User, "banana") s.Equal(meta.Env, []string{"PATH=/darkness", "BA=nana"}) - rootfsContent, err = ioutil.ReadFile(s.outputPath("image", "rootfs", "Dockerfile.orange")) + rootfsContent, err = os.ReadFile(s.outputPath("image", "rootfs", "Dockerfile.orange")) s.NoError(err) - expectedContent, err = ioutil.ReadFile("testdata/multi-target/Dockerfile") + expectedContent, err = os.ReadFile("testdata/multi-target/Dockerfile") s.NoError(err) s.Equal(rootfsContent, expectedContent) @@ -634,7 +633,7 @@ func (s *TaskSuite) outputPath(path ...string) string { } func (s *TaskSuite) imageMetadata(output string) (task.ImageMetadata, error) { - metadataPayload, err := ioutil.ReadFile(s.outputPath(output, "metadata.json")) + metadataPayload, err := os.ReadFile(s.outputPath(output, "metadata.json")) if err != nil { return task.ImageMetadata{}, err } diff --git a/unpack.go b/unpack.go index 18cecf5..3d08148 100644 --- a/unpack.go +++ b/unpack.go @@ -6,7 +6,6 @@ import ( "archive/tar" "fmt" "io" - "io/ioutil" "os" "path/filepath" "strings" @@ -31,7 +30,7 @@ func unpackImage(dest string, img v1.Image, debug bool) error { var out io.Writer if debug { - out = ioutil.Discard + out = io.Discard } else { out = os.Stderr }