Skip to content
This repository has been archived by the owner on Jan 28, 2022. It is now read-only.

Commit

Permalink
Add .cfignore file support
Browse files Browse the repository at this point in the history
  • Loading branch information
sclevine committed May 15, 2017
1 parent e7b95a5 commit 66e4de7
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 38 deletions.
6 changes: 3 additions & 3 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ install:
- 7z x -y cf-cli.zip
- choco install virtualbox
- choco install docker-machine
- docker-machine create -d virtualbox --virtualbox-no-vtx-check --virtualbox-nat-nictype "Am79C973" --virtualbox-hostonly-nictype "Am79C973" default
- docker-machine env --shell powershell default | iex
- docker run -it --rm cloudfoundry/cflinuxfs2 ls
#- docker-machine create -d virtualbox --virtualbox-no-vtx-check --virtualbox-nat-nictype "Am79C973" --virtualbox-hostonly-nictype "Am79C973" default
#- docker-machine env --shell powershell default | iex
#- docker run -it --rm cloudfoundry/cflinuxfs2 ls
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ OK
Plugin cflocal successfully uninstalled.
```

## Known Issues

* JAR files currently must be unzipped to push

## Security Notes

* Service forwarding tunnels are not active during staging
Expand All @@ -171,14 +175,8 @@ Plugin cflocal successfully uninstalled.
* CF Local should not be used to download untrusted CF applications
* CF Local is not intended for production use and is offered without warranty

# Major Issues

* No support for .cfignore files
* JAR files must be unzipped to push

## TODO

* Respect .cfignore
* Issue #4
* Allow local buildpacks to be specified
* Permit specification of cflinuxfs2 version
Expand Down
4 changes: 2 additions & 2 deletions cf/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ type Runner interface {

//go:generate mockgen -package mocks -destination mocks/fs.go github.com/sclevine/cflocal/cf/cmd FS
type FS interface {
Tar(path string) (io.ReadCloser, error)
OpenFile(path string) (fs.ReadResetWriteCloser, int64, error)
TarApp(path string) (io.ReadCloser, error)
ReadFile(path string) (io.ReadCloser, int64, error)
WriteFile(path string) (io.WriteCloser, error)
OpenFile(path string) (fs.ReadResetWriteCloser, int64, error)
MakeDirAll(path string) error
IsDirEmpty(path string) (bool, error)
Abs(path string) (string, error)
Expand Down
8 changes: 4 additions & 4 deletions cf/cmd/mocks/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ func (_mr *_MockFSRecorder) ReadFile(arg0 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "ReadFile", arg0)
}

func (_m *MockFS) Tar(_param0 string) (io.ReadCloser, error) {
ret := _m.ctrl.Call(_m, "Tar", _param0)
func (_m *MockFS) TarApp(_param0 string) (io.ReadCloser, error) {
ret := _m.ctrl.Call(_m, "TarApp", _param0)
ret0, _ := ret[0].(io.ReadCloser)
ret1, _ := ret[1].(error)
return ret0, ret1
}

func (_mr *_MockFSRecorder) Tar(arg0 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "Tar", arg0)
func (_mr *_MockFSRecorder) TarApp(arg0 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "TarApp", arg0)
}

func (_m *MockFS) WriteFile(_param0 string) (io.WriteCloser, error) {
Expand Down
2 changes: 1 addition & 1 deletion cf/cmd/stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (s *Stage) Run(args []string) error {
if err != nil {
return err
}
appTar, err := s.FS.Tar(".")
appTar, err := s.FS.TarApp(".")
if err != nil {
return err
}
Expand Down
2 changes: 2 additions & 0 deletions fixtures/go-app/.cfignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/broken.go
!main.go
3 changes: 3 additions & 0 deletions fixtures/go-app/broken.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package main

const broken = valueNotPresent
54 changes: 32 additions & 22 deletions fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,50 @@ import (
"io"
"os"
"path/filepath"
"regexp"

"code.cloudfoundry.org/cli/cf/appfiles"
"github.com/docker/docker/pkg/archive"
)

type FS struct{}

func (f *FS) Tar(path string) (io.ReadCloser, error) {
func (f *FS) TarApp(path string) (io.ReadCloser, error) {
absPath, err := filepath.Abs(path)
if err != nil {
return nil, err
}
// TODO: ignore these files in subdirs + obey .cfignore
files, err := appFiles(absPath)
if err != nil {
return nil, err
}
return archive.TarWithOptions(absPath, &archive.TarOptions{
ExcludePatterns: []string{
"*.droplet",
".*.cache",
".cfignore",
"manifest.yml",
".gitignore",
".git",
".hg",
".svn",
"_darcs",
".DS_Store",
},
IncludeFiles: files,
})
}

func appFiles(path string) ([]string, error) {
var files []string
err := appfiles.ApplicationFiles{}.WalkAppFiles(path, func(relpath string, fullpath string) error {
filename := filepath.Base(relpath)
switch {
case
regexp.MustCompile(`^.+\.droplet$`).MatchString(filename),
regexp.MustCompile(`^\..+\.cache$`).MatchString(filename):
return nil
}
files = append(files, relpath)
return nil
})
return files, err
}

func (f *FS) ReadFile(path string) (io.ReadCloser, int64, error) {
return f.openFile(path, os.O_RDONLY, 0)
}

func (f *FS) WriteFile(path string) (io.WriteCloser, error) {
return os.Create(path)
}

type ReadResetWriteCloser interface {
Expand All @@ -53,10 +71,6 @@ func (r resetFile) Reset() error {
return r.Truncate(0)
}

func (f *FS) ReadFile(path string) (io.ReadCloser, int64, error) {
return f.openFile(path, os.O_RDONLY, 0)
}

func (f *FS) openFile(path string, flag int, perm os.FileMode) (*os.File, int64, error) {
file, err := os.OpenFile(path, flag, perm)
if err != nil {
Expand All @@ -69,10 +83,6 @@ func (f *FS) openFile(path string, flag int, perm os.FileMode) (*os.File, int64,
return file, fileInfo.Size(), nil
}

func (f *FS) WriteFile(path string) (io.WriteCloser, error) {
return os.Create(path)
}

func (f *FS) MakeDirAll(path string) error {
return os.MkdirAll(path, 0777)
}
Expand Down

0 comments on commit 66e4de7

Please sign in to comment.