Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
* removes unused functions
* fmt
* remove commented out lines

Signed-off-by: Emily Casey <ecasey@pivotal.io>
  • Loading branch information
ekcasey committed Dec 11, 2018
1 parent 59c21fc commit 063415f
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 116 deletions.
11 changes: 6 additions & 5 deletions acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ import (
"time"

"github.com/BurntSushi/toml"
"github.com/buildpack/pack/docker"
h "github.com/buildpack/pack/testhelpers"
dockertypes "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/go-connections/nat"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"

"github.com/buildpack/pack/docker"
h "github.com/buildpack/pack/testhelpers"
)

var pack string
Expand Down Expand Up @@ -197,7 +198,7 @@ func testPack(t *testing.T, when spec.G, it spec.S) {
t.Fatalf("Expected to see image %s in %s", repo, contents)
}

h.AssertNil(t, dockerCli.PullImage(fmt.Sprintf("%s@%s", repoName, imgSHA)))
h.AssertNil(t, h.PullImage(dockerCli, fmt.Sprintf("%s@%s", repoName, imgSHA)))
defer h.DockerRmi(dockerCli, fmt.Sprintf("%s@%s", repoName, imgSHA))

ctrID := runDockerImageExposePort(t, containerName, fmt.Sprintf("%s@%s", repoName, imgSHA))
Expand Down Expand Up @@ -352,7 +353,7 @@ func testPack(t *testing.T, when spec.G, it spec.S) {
cmd.Env = append(os.Environ(), "PACK_HOME="+packHome)
h.Run(t, cmd)

h.AssertNil(t, dockerCli.PullImage(repoName))
h.AssertNil(t, h.PullImage(dockerCli, repoName))
h.AssertEq(t, rootContents1(), "contents-before-1\n")
h.AssertNil(t, h.DockerRmi(dockerCli, repoName))
})
Expand All @@ -364,7 +365,7 @@ func testPack(t *testing.T, when spec.G, it spec.S) {
cmd := exec.Command(pack, "rebase", repoName, "--publish")
cmd.Env = append(os.Environ(), "PACK_HOME="+packHome)
h.Run(t, cmd)
h.AssertNil(t, dockerCli.PullImage(repoName))
h.AssertNil(t, h.PullImage(dockerCli, repoName))

h.AssertEq(t, rootContents1(), "contents-after-1\n")
})
Expand Down
31 changes: 13 additions & 18 deletions build.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ type BuildConfig struct {
FS FS
Config *config.Config
// Above are copied from BuildFactory
//WorkspaceVolume string
CacheVolume string
}

Expand Down Expand Up @@ -129,19 +128,18 @@ func (bf *BuildFactory) BuildConfigFromFlags(f *BuildFlags) (*BuildConfig, error
}

b := &BuildConfig{
AppDir: appDir,
RepoName: f.RepoName,
Publish: f.Publish,
NoPull: f.NoPull,
Buildpacks: f.Buildpacks,
Cli: bf.Cli,
Stdout: bf.Stdout,
Stderr: bf.Stderr,
Log: bf.Log,
FS: bf.FS,
Config: bf.Config,
//WorkspaceVolume: fmt.Sprintf("pack-workspace-%x", uuid.New().String()),
CacheVolume: fmt.Sprintf("pack-cache-%x", md5.Sum([]byte(appDir))),
AppDir: appDir,
RepoName: f.RepoName,
Publish: f.Publish,
NoPull: f.NoPull,
Buildpacks: f.Buildpacks,
Cli: bf.Cli,
Stdout: bf.Stdout,
Stderr: bf.Stderr,
Log: bf.Log,
FS: bf.FS,
Config: bf.Config,
CacheVolume: fmt.Sprintf("pack-cache-%x", md5.Sum([]byte(appDir))),
}

if f.EnvFile != "" {
Expand Down Expand Up @@ -200,7 +198,7 @@ func (bf *BuildFactory) BuildConfigFromFlags(f *BuildFlags) (*BuildConfig, error
if err != nil {
return nil, err
}
}else {
} else {
if !f.NoPull {
bf.Log.Printf("Pulling run image '%s' (use --no-pull flag to skip this step)", b.RunImage)
}
Expand Down Expand Up @@ -240,8 +238,6 @@ func Build(appDir, buildImage, runImage, repoName string, publish bool) error {
}

func (b *BuildConfig) Run() error {
//defer b.Cli.VolumeRemove(context.Background(), b.WorkspaceVolume, true)

if err := b.Detect(); err != nil {
return err
}
Expand Down Expand Up @@ -602,7 +598,6 @@ func (b *BuildConfig) Export() error {
return errors.Wrap(err, "chown launch dir")
}


if err := b.Cli.RunContainer(ctx, ctr.ID, b.Stdout, b.Stderr); err != nil {
return errors.Wrap(err, "run lifecycle/exporter")
}
Expand Down
33 changes: 17 additions & 16 deletions build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,20 @@ import (
"time"

"github.com/buildpack/lifecycle"
"github.com/buildpack/pack"
"github.com/buildpack/pack/config"
"github.com/buildpack/pack/docker"
"github.com/buildpack/pack/fs"
"github.com/buildpack/pack/mocks"
h "github.com/buildpack/pack/testhelpers"
dockertypes "github.com/docker/docker/api/types"
dockercontainer "github.com/docker/docker/api/types/container"
"github.com/golang/mock/gomock"
"github.com/google/uuid"
"github.com/pkg/errors"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"

"github.com/buildpack/pack"
"github.com/buildpack/pack/config"
"github.com/buildpack/pack/docker"
"github.com/buildpack/pack/fs"
"github.com/buildpack/pack/mocks"
h "github.com/buildpack/pack/testhelpers"
)

var registryPort string
Expand All @@ -55,11 +56,11 @@ func testBuild(t *testing.T, when spec.G, it spec.S) {
it.Before(func() {
var err error
subject = &pack.BuildConfig{
AppDir: "acceptance/testdata/node_app",
Builder: h.DefaultBuilderImage(t, registryPort),
RunImage: h.DefaultRunImage(t, registryPort),
RepoName: "pack.build." + h.RandString(10),
Publish: false,
AppDir: "acceptance/testdata/node_app",
Builder: h.DefaultBuilderImage(t, registryPort),
RunImage: h.DefaultRunImage(t, registryPort),
RepoName: "pack.build." + h.RandString(10),
Publish: false,
CacheVolume: fmt.Sprintf("pack-cache-%x", uuid.New().String()),
Stdout: &buf,
Stderr: &buf,
Expand Down Expand Up @@ -564,8 +565,8 @@ cache = false

when("#Export", func() {
var (
runSHA string
runTopLayer string
runSHA string
runTopLayer string
setupLayersDir func()
)
it.Before(func() {
Expand Down Expand Up @@ -616,7 +617,7 @@ cache = false
it("puts the files on the image", func() {
h.AssertNil(t, subject.Export())

h.AssertNil(t, dockerCli.PullImage(subject.RepoName))
h.AssertNil(t, h.PullImage(dockerCli, subject.RepoName))
defer h.DockerRmi(dockerCli, subject.RepoName)
txt, err := h.CopySingleFileFromImage(dockerCli, subject.RepoName, "workspace/app/file.txt")
h.AssertNil(t, err)
Expand All @@ -630,7 +631,7 @@ cache = false
it("sets the metadata on the image", func() {
h.AssertNil(t, subject.Export())

h.AssertNil(t, dockerCli.PullImage(subject.RepoName))
h.AssertNil(t, h.PullImage(dockerCli, subject.RepoName))
defer h.DockerRmi(dockerCli, subject.RepoName)
var metadata lifecycle.AppImageMetadata
metadataJSON := imageLabel(t, dockerCli, subject.RepoName, "io.buildpacks.lifecycle.metadata")
Expand Down Expand Up @@ -712,7 +713,7 @@ cache = false
})

when("previous image exists", func() {
it.Before(func(){
it.Before(func() {
t.Log("create image and h.Assert add new layer")
h.AssertNil(t, subject.Export())
setupLayersDir()
Expand Down
4 changes: 2 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ func upgradeStack(config *Config, stack Stack) {
for _, stk := range config.Stacks {
if stk.ID == stack.ID {
for index, value := range stk.BuildImages {
if value == "packs/build"{
if value == "packs/build" {
stk.BuildImages[index] = stack.BuildImages[0]
}
}

for index, value := range stk.RunImages {
if value == "packs/run"{
if value == "packs/run" {
stk.RunImages[index] = stack.RunImages[0]
}
}
Expand Down
9 changes: 5 additions & 4 deletions create_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ import (
"compress/gzip"
"crypto/sha256"
"fmt"
"github.com/BurntSushi/toml"
"github.com/buildpack/lifecycle"
"github.com/buildpack/lifecycle/image"
"github.com/pkg/errors"
"io"
"io/ioutil"
"log"
Expand All @@ -16,6 +12,11 @@ import (
"os"
"path/filepath"

"github.com/BurntSushi/toml"
"github.com/buildpack/lifecycle"
"github.com/buildpack/lifecycle/image"
"github.com/pkg/errors"

"github.com/buildpack/pack/config"
)

Expand Down
16 changes: 0 additions & 16 deletions docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"io"
"io/ioutil"

dockertypes "github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
Expand Down Expand Up @@ -57,18 +56,3 @@ func (d *Client) RunContainer(ctx context.Context, id string, stdout io.Writer,
}
return <-copyErr
}

func (d *Client) PullImage(ref string) error {
rc, err := d.ImagePull(context.Background(), ref, dockertypes.ImagePullOptions{})
if err != nil {
// Retry
rc, err = d.ImagePull(context.Background(), ref, dockertypes.ImagePullOptions{})
if err != nil {
return err
}
}
if _, err := io.Copy(ioutil.Discard, rc); err != nil {
return err
}
return rc.Close()
}
3 changes: 2 additions & 1 deletion fs/tar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ import (
"testing"
"time"

"github.com/buildpack/pack/fs"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"

"github.com/buildpack/pack/fs"
)

func TestFS(t *testing.T) {
Expand Down
1 change: 0 additions & 1 deletion interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

//go:generate mockgen -package mocks -destination mocks/docker.go github.com/buildpack/pack Docker
type Docker interface {
PullImage(ref string) error
RunContainer(ctx context.Context, id string, stdout io.Writer, stderr io.Writer) error
VolumeRemove(ctx context.Context, volumeID string, force bool) error
ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, containerName string) (container.ContainerCreateCreatedBody, error)
Expand Down
7 changes: 4 additions & 3 deletions rebase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import (
"testing"

"github.com/buildpack/lifecycle"
"github.com/golang/mock/gomock"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"

"github.com/buildpack/pack"
"github.com/buildpack/pack/config"
"github.com/buildpack/pack/mocks"
h "github.com/buildpack/pack/testhelpers"
"github.com/golang/mock/gomock"
"github.com/sclevine/spec"
"github.com/sclevine/spec/report"
)

func TestRebase(t *testing.T) {
Expand Down
10 changes: 5 additions & 5 deletions run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ func testRun(t *testing.T, when spec.G, it spec.S) {
mockController = gomock.NewController(t)
mockImageFactory = mocks.NewMockImageFactory(mockController)
factory = &pack.BuildFactory{
Cli: mockDocker,
Stdout: &buf,
Stderr: &buf,
Log: log.New(&buf, "", log.LstdFlags|log.Lshortfile),
FS: &fs.FS{},
Cli: mockDocker,
Stdout: &buf,
Stderr: &buf,
Log: log.New(&buf, "", log.LstdFlags|log.Lshortfile),
FS: &fs.FS{},
ImageFactory: mockImageFactory,
Config: &config.Config{
Stacks: []config.Stack{
Expand Down
Loading

0 comments on commit 063415f

Please sign in to comment.