Commit 85982784 authored by Muhammad Umair Khan's avatar Muhammad Umair Khan
Browse files

meepctl: add --no-cache flag to dockerize command

parent 5a66e167
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ type DockerizeData struct {
	gitdir        string
	coreGoApps    []string
	sandboxGoApps []string
	noCache       bool
}

const dockerizeDesc = `Dockerize core components
@@ -82,6 +83,7 @@ func init() {

	// Set dockerize-specific flags
	dockerizeCmd.Flags().StringP("registry", "r", "", "Override registry from config file")
	dockerizeCmd.Flags().BoolVar(&dockerizeData.noCache, "no-cache", false, "Build Docker images without using the cache")

	// Add command
	rootCmd.AddCommand(dockerizeCmd)
@@ -216,22 +218,31 @@ func dockerize(targetName string, repo string, cobraCmd *cobra.Command) {

	// dockerize & push to private meep docker registry
	fmt.Println("   + dockerize " + targetName)

	buildArgs := []string{"build", "--rm", "--label", "MeepVersion=" + checksum[0]}
	if dockerizeData.noCache {
		buildArgs = append(buildArgs, "--no-cache")
	}
	buildArgs = append(buildArgs, "-t")

	if dockerizeData.registry != "" {
		tag := dockerizeData.registry + "/" + targetName
		cmd := exec.Command("docker", "build", "--no-cache", "--rm", "--label", "MeepVersion="+checksum[0], "-t", tag, bindir)
		buildArgs = append(buildArgs, tag, bindir)
		cmd := exec.Command("docker", buildArgs...)
		_, err = utils.ExecuteCmd(cmd, cobraCmd)
		if err != nil {
			fmt.Println("Error: Failed to dockerize ", tag, " with error: ", err)
			return
		}
		cmd = exec.Command("docker", "push", tag)
		_, err := utils.ExecuteCmd(cmd, cobraCmd)
		_, err = utils.ExecuteCmd(cmd, cobraCmd)
		if err != nil {
			fmt.Println("Error: Failed to push ", tag, " with error: ", err)
			return
		}
	} else {
		cmd := exec.Command("docker", "build", "--no-cache", "--rm", "--label", "MeepVersion="+checksum[0], "-t", targetName, bindir)
		buildArgs = append(buildArgs, targetName, bindir)
		cmd := exec.Command("docker", buildArgs...)
		_, _ = utils.ExecuteCmd(cmd, cobraCmd)
	}
}