Skip to content
Snippets Groups Projects
Select Git revision
  • 1123f3b1172de6eea66ef5f6154c26f4fc601b03
  • main default protected
  • 1-mage-run-does-not-stop-containers
  • v0.26.0
  • v0.25.0
  • v0.24.0
  • v0.23.0
  • v0.22.0
  • v0.21.0
  • v0.20.0
  • v0.19.0
  • v0.18.0
  • v0.17.0
  • v0.16.0
  • v0.15.0
  • v0.14.0
  • v0.13.0
  • v0.12.0
  • v0.11.0
  • v0.10.0
  • v0.9.0
  • v0.8.0
  • v0.7.0
23 results

build.go

Blame
  • build.go 3.57 KiB
    package mage_helpers
    
    import (
    	"fmt"
    	"os"
    	"os/exec"
    	"path"
    	"runtime"
    	"strings"
    
    	"github.com/magefile/mage/sh"
    )
    
    func Clean(path string) error {
    
    	cmd := exec.Command("rm", "-rf", "build")
    	cmd.Stdout = os.Stdout
    	cmd.Stderr = os.Stderr
    	cmd.Dir = path
    	err := cmd.Run()
    	if err != nil {
    		return err
    	}
    
    	cmd = exec.Command("mkdir", "-p", "build")
    	cmd.Stdout = os.Stdout
    	cmd.Stderr = os.Stderr
    	cmd.Dir = path
    	err = cmd.Run()
    	if err != nil {
    		return err
    	}
    	return nil
    }
    
    func Build(dir string, module string, isDebug bool) error {
    	currentDir, _ := os.Getwd()
    	fullPath := currentDir + "/core/" + dir
    
    	if err := Clean(fullPath); err != nil {
    		return err
    	}
    
    	handler := path.Base(fullPath)
    	fmt.Println(fmt.Sprintf("Building %v", handler))
    
    	outputFileName := handler
    	fmt.Println("Checking to use bootstrap")
    	if os.Getenv("ENVIRONMENT") == "playground" {
    		outputFileName = "bootstrap"
    	}
    
    	outputDir := fmt.Sprintf(currentDir+`/core/build/handlers/%v`, handler)
    	outputFile := fmt.Sprintf(`%v/%v`, outputDir, outputFileName)
    	appPath := fmt.Sprintf(`%v/core/%v`, module, handler)
    	err := BuildGolangApp(outputFile, appPath, module, isDebug)
    	if err != nil {
    		return err
    	}
    
    	// Copy files in handler folder
    	err = copyFilesToBuildDir(fullPath, outputDir)
    	if err != nil {
    		return err
    	}
    
    	// Copy shared files
    	sharedDir := currentDir + "/core/utils"
    	_, err = os.Stat(sharedDir)
    	if err == nil {