示例#1
0
文件: push.go 项目: tomologic/wrench
func push(registry string, additional_tags string) error {
	tags := strings.Split(additional_tags, ",")
	tags = append(tags, config.GetProjectVersion())
	tags = utils.RemoveEmptyStrings(tags)

	for _, tag := range tags {
		image_name := fmt.Sprintf("%s/%s:%s",
			config.GetProjectOrganization(),
			config.GetProjectName(),
			config.GetProjectVersion())

		registry = strings.Trim(registry, "/")

		tmp_image_name := fmt.Sprintf("%s/%s/%s:%s",
			registry,
			config.GetProjectOrganization(),
			config.GetProjectName(),
			tag)

		// prefix image name with registry
		if err := tag_image(image_name, tmp_image_name); err != nil {
			return err
		}

		// push prefixed image
		push_err := push_image(tmp_image_name)

		// cleanup prefixed images
		cleanup_err := remove_image(tmp_image_name)

		if push_err != nil {
			return push_err
		}

		if cleanup_err != nil {
			return cleanup_err
		}
	}

	return nil
}
示例#2
0
文件: build.go 项目: tomologic/wrench
func buildBuilder() {
	image_name := config.GetProjectImage()

	builder_image_name := fmt.Sprintf("%s-builder", image_name)

	fmt.Printf("INFO: %s %s\n\n",
		"Found Dockerfile.builder, building image builder",
		builder_image_name)

	// Build builder image
	cmd_string := fmt.Sprintf("docker build -f Dockerfile.builder -t '%s' .", builder_image_name)
	cmd := exec.Command("sh", "-c", cmd_string)
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	err := cmd.Run()

	version := strings.TrimLeft(config.GetProjectVersion(), "v")
	fmt.Printf("INFO: Adding env variable VERSION=%s\n\n", version)
	utils.DockerImageAddEnv(builder_image_name, "VERSION", version)

	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	fmt.Printf("\nINFO: %s %s\n\n",
		"Building image with builder",
		image_name)

	// Build image
	cmd_string = fmt.Sprintf("docker run --rm '%s' | docker build -t '%s' -", builder_image_name, image_name)
	cmd = exec.Command("sh", "-c", cmd_string)
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	err = cmd.Run()

	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	fmt.Printf("INFO: Adding env variable VERSION=%s\n\n", version)
	utils.DockerImageAddEnv(image_name, "VERSION", version)
}
示例#3
0
文件: build.go 项目: tomologic/wrench
func buildSimple() {
	image_name := config.GetProjectImage()

	fmt.Printf("INFO: %s %s\n\n",
		"Found Dockerfile, building image",
		image_name)

	cmd_string := fmt.Sprintf("docker build -t '%s' .", image_name)
	cmd := exec.Command("sh", "-c", cmd_string)
	cmd.Stdout = os.Stdout
	cmd.Stderr = os.Stderr
	err := cmd.Run()

	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	version := strings.TrimLeft(config.GetProjectVersion(), "v")
	fmt.Printf("INFO: Adding env variable VERSION=%s\n\n", version)
	utils.DockerImageAddEnv(image_name, "VERSION", version)
}