Пример #1
0
func main() {
	fmt.Printf("Drone Capistrano Plugin built at %s\n", buildDate)

	workspace := drone.Workspace{}
	vargs := Params{}

	dw := DeployWorkspace{workspace}

	plugin.Param("workspace", &workspace)
	plugin.Param("vargs", &vargs)
	plugin.MustParse()

	log("Installing Drone's ssh key")
	if err := repo.WriteKey(&workspace); err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	os.Setenv("BUILD_PATH", workspace.Path)
	os.Setenv("GIT_SSH_KEY", privateKeyPath)

	tasks := strings.Fields(vargs.Tasks)

	if len(tasks) == 0 {
		fmt.Println("Please provide Capistrano tasks to execute")
		os.Exit(1)
		return
	}

	log("Running Bundler")
	bundle := dw.bundle(bundlerArgs(vargs)...)
	if err := bundle.Run(); err != nil {
		fmt.Println(err)
		os.Exit(1)
		return
	}

	log("Running Capistrano")
	capistrano := dw.cap(tasks...)
	if err := capistrano.Run(); err != nil {
		fmt.Println(err)
		os.Exit(1)
		return
	}
}
Пример #2
0
func run(workspace *drone.Workspace, build *drone.Build, vargs *Params) error {
	repo.GlobalName(build).Run()
	repo.GlobalUser(build).Run()

	if err := repo.WriteKey(workspace); err != nil {
		return err
	}

	defer func() {
		execute(
			repo.RemoteRemove(
				"deploy"),
			workspace)
	}()

	cmd := repo.RemoteAdd(
		"deploy",
		remote(vargs))

	if err := execute(cmd, workspace); err != nil {
		return err
	}

	if vargs.Commit {
		if err := execute(repo.ForceAdd(), workspace); err != nil {
			return err
		}

		if err := execute(repo.ForceCommit(), workspace); err != nil {
			return err
		}
	}

	cmd = repo.RemotePush(
		"deploy",
		"master",
		vargs.Force)

	if err := execute(cmd, workspace); err != nil {
		return err
	}

	return nil
}
Пример #3
0
func run(workspace *drone.Workspace, build *drone.Build, vargs *Params) error {
	repo.GlobalName(build).Run()
	repo.GlobalUser(build).Run()

	api := cclib.NewAPI()
	api.SetUrl("https://api.cloudcontrolled.com")

	if err := api.CreateToken(vargs.Email, vargs.Password); err != nil {
		return errors.New("Failed to authenticate with email/password")
	}

	if _, err := api.ReadApplication(vargs.Application); err != nil {
		return errors.New("Failed to find the requested application")
	}

	if workspace.Keys != nil && len(workspace.Keys.Public) > 0 {
		publicKey, err := api.CreateUserKey(
			vargs.Email,
			workspace.Keys.Public)

		if err != nil {
			return errors.New("Failed to create a deployment key")
		}

		defer func() {
			api.DeleteUserKey(
				vargs.Email,
				publicKey.Id)
		}()
	}

	if err := repo.WriteKey(workspace); err != nil {
		return err
	}

	defer func() {
		execute(
			repo.RemoteRemove(
				"deploy"),
			workspace)
	}()

	cmd := repo.RemoteAdd(
		"deploy",
		remote(vargs))

	if err := execute(cmd, workspace); err != nil {
		return err
	}

	if vargs.Commit {
		if err := execute(repo.ForceAdd(), workspace); err != nil {
			return err
		}

		if err := execute(repo.ForceCommit(), workspace); err != nil {
			return err
		}
	}

	cmd = repo.RemotePush(
		"deploy",
		vargs.Deployment,
		vargs.Force)

	if err := execute(cmd, workspace); err != nil {
		return err
	}

	if _, err := api.UpdateDeployment(vargs.Application, vargs.Deployment, "", "", "", 0, 0); err != nil {
		return errors.New("Failed to trigger the final deployment")
	}

	return nil
}