Skip to content

Commit

Permalink
Updated to add ALL files
Browse files Browse the repository at this point in the history
  • Loading branch information
frikky committed Mar 25, 2021
1 parent a46af20 commit 844742d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 23 deletions.
48 changes: 38 additions & 10 deletions app_upload/stitcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,24 +269,51 @@ func stitcher(appname string, appversion string) string {
}

stitched := []byte(string(baseline) + strings.Join(appBase, "\n") + string(appfile) + string(runner))
err = ioutil.WriteFile(fmt.Sprintf("%s/main.py", foldername), stitched, os.ModePerm)
err = Copy(fmt.Sprintf("%s/%s/%s/requirements.txt", appfolder, appname, appversion), fmt.Sprintf("%s/requirements.txt", foldername))
if err != nil {
log.Println("Failed writing to stitched: %s", err)
log.Println("Failed writing to requirement: %s", err)
return ""
}

err = Copy(fmt.Sprintf("%s/%s/%s/requirements.txt", appfolder, appname, appversion), fmt.Sprintf("%s/requirements.txt", foldername))
err = ioutil.WriteFile(fmt.Sprintf("%s/main.py", foldername), stitched, os.ModePerm)
if err != nil {
log.Println("Failed writing to requirement: %s", err)
log.Println("Failed writing to stitched: %s", err)
return ""
}

log.Printf("Successfully stitched files in %s/main.py", foldername)
// Zip the folder
files := []string{
fmt.Sprintf("%s/main.py", foldername),
fmt.Sprintf("%s/requirements.txt", foldername),
fmt.Sprintf("%s/main.py", foldername),
}

folderPath := fmt.Sprintf("%s/%s/%s/src", appfolder, appname, appversion)
log.Printf("CHECKING FOLDER %s", folderPath)
allFiles, err := ioutil.ReadDir(folderPath)
if err != nil {
log.Printf("Failed getting src files")
return ""
}

for _, f := range allFiles {
if f.IsDir() {
continue
}

if f.Name() == "app.py" {
continue
}

err = Copy(fmt.Sprintf("%s/%s/%s/src/%s", appfolder, appname, appversion, f.Name()), fmt.Sprintf("%s/%s", foldername, f.Name()))
if err != nil {
log.Println("Failed writing to %s: %s", f.Name(), err)
continue
}

files = append(files, fmt.Sprintf("%s/%s", foldername, f.Name()))
}

//os.Exit(3)
log.Printf("Successfully stitched files in %s/main.py", foldername)
outputfile := fmt.Sprintf("%s.zip", foldername)

err = ZipFiles(outputfile, files)
Expand Down Expand Up @@ -710,10 +737,10 @@ func deployAll() {
}

func main() {
deployAll()
return
//deployAll()
//return

appname := "testing"
appname := "Microsoft-Teams"
appversion := "1.0.0"

err := deployConfigToBackend(appfolder, appname, appversion)
Expand All @@ -722,5 +749,6 @@ func main() {
os.Exit(1)
}

log.Printf("Starting cloud function deploy")
deployAppCloudFunc(appname, appversion)
}
15 changes: 2 additions & 13 deletions codegen.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,36 +169,25 @@ func GetAppbaseGCP(ctx context.Context, client *storage.Client, bucketName strin
// 1. Have baseline in bucket/generated_apps/baseline
// 2. Copy the baseline to a new folder with identifier name
basePath := "generated_apps/baseline"
static, err := client.Bucket(bucketName).Object(fmt.Sprintf("%s/static_baseline.py", basePath)).NewReader(ctx)
if err != nil {
return []byte{}, []byte{}, err
}

appbase, err := client.Bucket(bucketName).Object(fmt.Sprintf("%s/app_base.py", basePath)).NewReader(ctx)
if err != nil {
return []byte{}, []byte{}, err
}

defer static.Close()
defer appbase.Close()

staticData, err := ioutil.ReadAll(static)
if err != nil {
return []byte{}, []byte{}, err
}
staticData = []byte{}

appbaseData, err := ioutil.ReadAll(appbase)
if err != nil {
return []byte{}, []byte{}, err
}

return appbaseData, staticData, nil
return appbaseData, []byte{}, nil
}

func FixAppbase(appbase []byte) []string {
record := true
validLines := []string{}
// Used to use static_baseline + app_base. Now it's only appbase :O
for _, line := range strings.Split(string(appbase), "\n") {
//if strings.Contains(line, "#STOPCOPY") {
// //log.Println("Stopping copy")
Expand Down

0 comments on commit 844742d

Please sign in to comment.