Skip to content

Commit

Permalink
add gcloud ignore files
Browse files Browse the repository at this point in the history
  • Loading branch information
asim committed Mar 16, 2022
1 parent 139ccfc commit 8ee80a6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
20 changes: 20 additions & 0 deletions app/handler/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"path/filepath"
"math/rand"
"os/exec"
"strings"
Expand Down Expand Up @@ -46,6 +47,14 @@ var (

// hardcoded list of valid repos
GitRepos = []string{"github.com", "gitlab.org", "bitbucket.org"}

GitIgnore = []string{
".git",
"dist",
"node_modules",
"vendor",
"*.jar",
}
)

var (
Expand Down Expand Up @@ -155,6 +164,11 @@ func New() *GoogleApp {
}
}

func (e *GoogleApp) WriteGcloudIgnore(dir string) error {
data := []byte(strings.Join(GitIgnore, "\n"))
return ioutil.WriteFile(filepath.Join(dir, ".gcloudignore"), data, 0644)
}

func (e *GoogleApp) Regions(ctx context.Context, req *pb.RegionsRequest, rsp *pb.RegionsResponse) error {
rsp.Regions = GoogleRegions
return nil
Expand Down Expand Up @@ -370,6 +384,9 @@ func (e *GoogleApp) Run(ctx context.Context, req *pb.RunRequest, rsp *pb.RunResp
// set the command dir
cmd.Dir = gitter.RepoDir()

// write the gloudignore file
e.WriteGcloudIgnore(cmd.Dir)

// execute the command
outp, err := cmd.CombinedOutput()

Expand Down Expand Up @@ -522,6 +539,9 @@ func (e *GoogleApp) Update(ctx context.Context, req *pb.UpdateRequest, rsp *pb.U
// set the command dir
cmd.Dir = gitter.RepoDir()

// write the gloudignore file
e.WriteGcloudIgnore(cmd.Dir)

// execute the command
outp, err := cmd.CombinedOutput()

Expand Down
21 changes: 21 additions & 0 deletions function/handler/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ var (
"ruby26": "app.rb",
"php74": "index.php",
}

GitIgnore = []string{
".git",
"dist",
"node_modules",
"vendor",
"*.jar",
}
)

var (
Expand Down Expand Up @@ -180,6 +188,11 @@ func NewFunction() *GoogleFunction {
}
}

func (e *GoogleFunction) WriteGcloudIgnore(dir string) error {
data := []byte(strings.Join(GitIgnore, "\n"))
return ioutil.WriteFile(filepath.Join(dir, ".gcloudignore"), data, 0644)
}

func (e *GoogleFunction) Deploy(ctx context.Context, req *function.DeployRequest, rsp *function.DeployResponse) error {
log.Info("Received Function.Deploy request")

Expand Down Expand Up @@ -377,6 +390,10 @@ func (e *GoogleFunction) Deploy(ctx context.Context, req *function.DeployRequest
}

cmd.Dir = sourceDir

// write gloud ignore file
e.WriteGcloudIgnore(cmd.Dir)

outp, err := cmd.CombinedOutput()
if err != nil {
log.Error(fmt.Errorf(string(outp)))
Expand Down Expand Up @@ -535,6 +552,10 @@ func (e *GoogleFunction) Update(ctx context.Context, req *function.UpdateRequest
}

cmd.Dir = sourceDir

// write gloud ignore file
e.WriteGcloudIgnore(cmd.Dir)

outp, err := cmd.CombinedOutput()
if err != nil {
log.Error(fmt.Errorf(string(outp)))
Expand Down

0 comments on commit 8ee80a6

Please sign in to comment.