Skip to content

Commit

Permalink
Deprecation + lint fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Pedro Nuno Santos <[email protected]>
  • Loading branch information
pn-santos committed Nov 27, 2024
1 parent 21f1ff9 commit 73ebe2b
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 36 deletions.
6 changes: 2 additions & 4 deletions buildkitd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package task
import (
"fmt"
"io"
"io/ioutil"
"net/url"
"os"
"os/exec"
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
}
Expand Down
7 changes: 3 additions & 4 deletions buildkitd_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package task_test

import (
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 5 additions & 6 deletions task.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand All @@ -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)
}
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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")
}
Expand All @@ -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")
}
Expand All @@ -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")
}
Expand Down
39 changes: 19 additions & 20 deletions task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package task_test
import (
"encoding/json"
"fmt"
"io/ioutil"
"net/http/httptest"
"net/url"
"os"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -517,15 +516,15 @@ 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)
s.Equal(string(digest), additionalManifest.Config.Digest.String())

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)
Expand All @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions unpack.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"archive/tar"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand All @@ -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
}
Expand Down

0 comments on commit 73ebe2b

Please sign in to comment.