From: Ricardo Noriega Date: Tue, 4 Jun 2019 16:18:36 +0000 (+0200) Subject: Fix make binary to place it on bin X-Git-Tag: akraino_r1~1 X-Git-Url: https://gerrit.akraino.org/r/gitweb?a=commitdiff_plain;h=28edb919e35e6948a96c2d03758170fd7246770c;p=kni%2Finstaller.git Fix make binary to place it on bin make binary places openshift-install binary on the same build path that gets cleaned up at deployment time. Now it will be located under bin. Signed-off-by: Ricardo Noriega Change-Id: Ie4e3ad8218d8091f28c679b9eeeacbd2565bed7e --- diff --git a/Makefile b/Makefile index fb822fb..068524a 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ GOFILES=$(wildcard *.go) GONAME="kni-edge-installer" BUILDDIR = $(shell pwd)/build +BINDIR = $(shell pwd)/bin INSTALLER_GIT_REPO = github.com/openshift/installer RHCOS_VERSION = "maipo" export PATH:=${HOME}/go/bin:${PATH} @@ -37,7 +38,7 @@ all: watch binary: @echo @echo "Building installer binary" - @./bin/$(GONAME) binary --build_path ${BUILDDIR} --installer_repository ${INSTALLER_GIT_REPO} --installer_tag ${INSTALLER_GIT_TAG} + @./bin/$(GONAME) binary --bin_path ${BINDIR} --installer_repository ${INSTALLER_GIT_REPO} --installer_tag ${INSTALLER_GIT_TAG} build: @echo "Building kni-edge-installer with $(GOPATH) to ./bin" diff --git a/cmd/binary.go b/cmd/binary.go index 1a83d31..9d00f09 100644 --- a/cmd/binary.go +++ b/cmd/binary.go @@ -18,7 +18,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "log" "os" "os/exec" @@ -28,7 +27,7 @@ import ( ) // BuildBinary is downloading the installer repo and building it -func BuildBinary(buildPath string, installerRepo string, installerTag string) { +func BuildBinary(binPath string, installerRepo string, installerTag string) { repoURL := installerRepo if installerTag != "" { repoURL = fmt.Sprintf("%s?ref=%s", repoURL, installerTag) @@ -67,13 +66,13 @@ func BuildBinary(buildPath string, installerRepo string, installerTag string) { log.Println(stdBuffer.String()) // copy the generated binary to the build directory - cmd = exec.Command("cp", fmt.Sprintf("%s/bin/openshift-install", installerPath), buildPath) + cmd = exec.Command("cp", fmt.Sprintf("%s/bin/openshift-install", installerPath), binPath) err = cmd.Run() if err != nil { log.Fatal(fmt.Sprintf("Error copying installer to buid path: %s", err)) os.Exit(1) } - log.Println(fmt.Sprintf("Installer is available on %s/openshift-install", buildPath)) + log.Println(fmt.Sprintf("Installer is available on %s/openshift-install", binPath)) } @@ -88,19 +87,10 @@ var binaryCmd = &cobra.Command{ installerRepo, _ := cmd.Flags().GetString("installer_repository") installerTag, _ := cmd.Flags().GetString("installer_tag") - // Check if build path exists, create if not - buildPath, _ := cmd.Flags().GetString("build_path") - if len(buildPath) == 0 { - // will generate a temporary directory - buildPath, _ = ioutil.TempDir("/tmp", "kni") - } else { - // remove if exists, recreate - os.RemoveAll(buildPath) - os.MkdirAll(buildPath, 0775) - } - - BuildBinary(buildPath, installerRepo, installerTag) - + // bin path should exist, because "make build" should have been executed previously. + binPath, _ := cmd.Flags().GetString("bin_path") + os.Remove(binPath + "/openshift-install") + BuildBinary(binPath, installerRepo, installerTag) }, } @@ -111,6 +101,6 @@ func init() { binaryCmd.MarkFlagRequired("installer_repository") binaryCmd.Flags().StringP("installer_tag", "", "master", "Specific tag for the openshift installer repository") binaryCmd.MarkFlagRequired("installer_tag") - binaryCmd.Flags().StringP("build_path", "", "", "Directory to use as build path. If that not exists, the installer will generate a default directory") + binaryCmd.Flags().StringP("bin_path", "", "", "Directory to use as build path.") }