From a7e7ca15e314e718175112f0f56b62758f327d1e Mon Sep 17 00:00:00 2001 From: frikky Date: Mon, 15 Jun 2020 17:55:37 +0200 Subject: [PATCH] #60: Bugfixes for production --- .env | 5 ++++- backend/go-app/main.go | 17 ++++++++------ backend/go-app/walkoff.go | 29 ++++++++++++++---------- docker-compose.yml | 3 ++- frontend/src/Apps.js | 47 +++++++++++++++++++++++++++++++++++++-- 5 files changed, 78 insertions(+), 23 deletions(-) diff --git a/.env b/.env index 7f864f6b..ec7651f2 100644 --- a/.env +++ b/.env @@ -3,10 +3,13 @@ ORG_ID=Shuffle ENVIRONMENT_NAME=Shuffle # Different locations etc -APP_DOWNLOAD_LOCATION=https://github.com/frikky/shuffle-apps +APP_DOWNLOAD_LOCATION=https://github.com/frikky/shuffle-apps # Remote location to download APP_DOWNLOAD_AUTH_USERNAME="" APP_DOWNLOAD_AUTH_PASSWORD="" +# Local location of your app directory. Can't use ~/ or ./ +APP_HOTLOAD_LOCATION="shuffle-apps" + # Other configs BACKEND_HOSTNAME=shuffle-backend BACKEND_PORT=5001 diff --git a/backend/go-app/main.go b/backend/go-app/main.go index 4e18c4e1..ef15e579 100644 --- a/backend/go-app/main.go +++ b/backend/go-app/main.go @@ -39,7 +39,6 @@ import ( "github.com/go-git/go-billy/v5" "github.com/go-git/go-billy/v5/memfs" - "github.com/go-git/go-billy/v5/osfs" "github.com/go-git/go-git/v5" "github.com/go-git/go-git/v5/storage/memory" @@ -5794,8 +5793,9 @@ func healthCheckHandler(resp http.ResponseWriter, request *http.Request) { // Creates osfs from folderpath with a basepath as directory base func createFs(basepath, pathname string) (billy.Filesystem, error) { - fs := osfs.New("") + log.Printf("base: %s, pathname: %s", basepath, pathname) + fs := memfs.New() err := filepath.Walk(pathname, func(path string, info os.FileInfo, err error) error { if err != nil { @@ -5806,7 +5806,10 @@ func createFs(basepath, pathname string) (billy.Filesystem, error) { return nil } - fullpath := fmt.Sprintf("%s%s", basepath, path) + // Fix the inner path here + newpath := strings.ReplaceAll(path, pathname, "") + fullpath := fmt.Sprintf("%s%s", basepath, newpath) + log.Printf("Fullpath: %s", fullpath) switch mode := info.Mode(); { case mode.IsDir(): err = fs.MkdirAll(fullpath, 0644) @@ -5845,23 +5848,23 @@ func createFs(basepath, pathname string) (billy.Filesystem, error) { } // Hotloads new apps from a folder -// FIXME: Not finished func handleAppHotload(location string) error { basepath := "base" fs, err := createFs(basepath, location) if err != nil { - log.Printf("Failed making files and stuff: %s", err) + log.Printf("Failed memfs creation - probably bad path: %s", err) return err } else { - log.Printf("Hotloading from %s finished", location) + log.Printf("Memfs creation from %s done", location) } - dir, err := fs.ReadDir(basepath) + dir, err := fs.ReadDir("") if err != nil { log.Printf("Failed reading folder: %s", err) return err } + log.Printf("Reading app folder: %#v", dir) err = iterateAppGithubFolders(fs, dir, "", "") if err != nil { log.Printf("Err: %s", err) diff --git a/backend/go-app/walkoff.go b/backend/go-app/walkoff.go index a7420d53..87041fa5 100644 --- a/backend/go-app/walkoff.go +++ b/backend/go-app/walkoff.go @@ -3444,6 +3444,7 @@ func handleAppHotloadRequest(resp http.ResponseWriter, request *http.Request) { return } + log.Printf("Hotloading from %s", location) err = handleAppHotload(location) if err != nil { resp.WriteHeader(500) @@ -3699,13 +3700,13 @@ func iterateWorkflowGithubFolders(fs billy.Filesystem, dir []os.FileInfo, extra dir, err := fs.ReadDir(tmpExtra) if err != nil { log.Printf("Failed to read dir: %s", err) - break + continue } // Go routine? Hmm, this can be super quick I guess err = iterateWorkflowGithubFolders(fs, dir, tmpExtra, "") if err != nil { - break + continue } case mode.IsRegular(): // Check the file @@ -3759,28 +3760,32 @@ func iterateAppGithubFolders(fs billy.Filesystem, dir []os.FileInfo, extra strin dir, err := fs.ReadDir(tmpExtra) if err != nil { log.Printf("Failed to read dir: %s", err) - break + continue } // Go routine? Hmm, this can be super quick I guess err = iterateAppGithubFolders(fs, dir, tmpExtra, "") if err != nil { - break + log.Printf("Error reading folder: %s", err) + continue } case mode.IsRegular(): // Check the file filename := file.Name() if filename == "Dockerfile" { - // Quick Dockerfile check - dockerdata, err := ioutil.ReadFile(fmt.Sprintf("%sDockerfile", extra)) - if err != nil { - continue - } + //dockerfile := fmt.Sprintf("%sDockerfile", extra) + //log.Printf("Handling Dockerfile %s", dockerfile) + //dockerdata, err := ioutil.ReadFile(dockerfile) + //if err != nil { + // log.Printf("Failed to read dockerfile") + // continue + //} - if len(dockerdata) == 0 { - continue - } + //if len(dockerdata) == 0 { + // log.Printf("Dockerfile is empty") + // continue + //} log.Printf("Handle Dockerfile in location %s", extra) diff --git a/docker-compose.yml b/docker-compose.yml index 77ee3a1a..c4d9c475 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: '3' services: frontend: - #build: ./frontend + build: ./frontend image: frikky/shuffle:frontend container_name: shuffle-frontend hostname: shuffle-frontend @@ -25,6 +25,7 @@ services: - shuffle volumes: - /var/run/docker.sock:/var/run/docker.sock + - ${APP_HOTLOAD_LOCATION}=/shuffle-apps # Local environment: - ORG_ID=${ORG_ID} - DATASTORE_EMULATOR_HOST=shuffle-database:8000 diff --git a/frontend/src/Apps.js b/frontend/src/Apps.js index cdacfecb..7325b27a 100644 --- a/frontend/src/Apps.js +++ b/frontend/src/Apps.js @@ -20,6 +20,7 @@ import YAML from 'yaml' import {Link} from 'react-router-dom'; import Breadcrumbs from '@material-ui/core/Breadcrumbs'; +import CachedIcon from '@material-ui/icons/Cached'; import CloudDownloadIcon from '@material-ui/icons/CloudDownload'; import PublishIcon from '@material-ui/icons/Publish'; import CloudDownload from '@material-ui/icons/CloudDownload'; @@ -348,7 +349,7 @@ const Apps = (props) => { Activate App : null - var deleteButton = ((selectedApp.private_id !== undefined && selectedApp.private_id.length > 0 && selectedApp.generated) || (selectedApp.downloaded != undefined && selectedApp.downloaded === true)) && activateButton === null ? + var deleteButton = ((selectedApp.private_id !== undefined && selectedApp.private_id.length > 0 && selectedApp.generated) || (selectedApp.downloaded != undefined && selectedApp.downloaded == true)) && activateButton === null ? +