Skip to content

Commit

Permalink
Merge pull request #7 from coherenceplatform/aa/promote-to-static
Browse files Browse the repository at this point in the history
Add environments deploy command
  • Loading branch information
zach-withcoherence authored Feb 2, 2024
2 parents 63b32d0 + 98d7597 commit 37e530b
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 3 deletions.
1 change: 1 addition & 0 deletions cmd/cocli/environments.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ var environmentCmd = &cobra.Command{
func init() {
environmentCmd.AddCommand(listEnvironmentsCmd)
environmentCmd.AddCommand(environmentImageOverrideCmd)
environmentCmd.AddCommand(promoteStaticEnvironmentCmd)
}
64 changes: 64 additions & 0 deletions cmd/cocli/promoteStaticEnvironment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package cocli

import (
"bytes"
"encoding/json"
"fmt"
"io"

"github.com/coherenceplatform/cocli/pkg/cocli"
"github.com/spf13/cobra"
)

var promoteStaticEnvId int
var promoteStaticEnvBranchName string
var promoteStaticEnvCommitSha string

var promoteStaticEnvironmentCmd = &cobra.Command{
Use: "deploy",
Short: "Deploy to a static coherence environment",
Run: func(cmd *cobra.Command, args []string) {
promoteEnvPayloadData := map[string]string{
"branch_name": promoteStaticEnvBranchName,
"commit_sha": promoteStaticEnvCommitSha,
}
payloadBytes, err := json.Marshal(promoteEnvPayloadData)
if err != nil {
panic(err)
}
payload := bytes.NewBuffer(payloadBytes)

promoteEnvUrl := fmt.Sprintf(
"https://%s%s/environments/%s/deploy",
cocli.GetCoherenceDomain(),
cocli.GetCoherenceApiPrefix(),
fmt.Sprint(promoteStaticEnvId),
)
res, err := cocli.CoherenceApiRequest(
"PUT",
promoteEnvUrl,
payload,
)
if err != nil {
panic(err)
}
defer res.Body.Close()
bodyBytes, err := io.ReadAll(res.Body)
if err != nil {
panic(err)
}

fmt.Println(cocli.FormatJSONOutput(bodyBytes))
},
}

func init() {
promoteStaticEnvironmentCmd.Flags().IntVarP(&promoteStaticEnvId, "environment_id", "e", 0, "Target static environment ID (required)")
promoteStaticEnvironmentCmd.MarkFlagRequired("environment_id")

promoteStaticEnvironmentCmd.Flags().StringVarP(&promoteStaticEnvBranchName, "branch_name", "b", "", "Branch name to deploy from (required)")
promoteStaticEnvironmentCmd.MarkFlagRequired("branch_name")

promoteStaticEnvironmentCmd.Flags().StringVarP(&promoteStaticEnvCommitSha, "commit_sha", "c", "", "Commit sha to deploy (required)")
promoteStaticEnvironmentCmd.MarkFlagRequired("commit_sha")
}
2 changes: 1 addition & 1 deletion cocli_version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.0
0.2.0
4 changes: 2 additions & 2 deletions pkg/cocli/cocli.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type CocliConfig struct {
var devConfig = &CocliConfig{
ClientID: "O5AkI9iHd4Okb3DCmu1P0em4YXFjAPr5",
AuthDomain: "dev-mkiob4vl.us.auth0.com",
CoherenceDomain: "7ddf4b8e-682e-433f-b93f-fd24f4dda1ce-web.coherencedev.com",
CoherenceDomain: "b0bf1309-a50e-413c-b244-977fdcf307ee-web.coherencedev.com",
}

// CoherenceDomain: "aa-external-cocli.control-plane-review.coherence.coherencesites.com",
Expand All @@ -37,7 +37,7 @@ var prodConfig = &CocliConfig{
}

const (
cliVersion = "0.1.0"
cliVersion = "0.2.0"
credsFilename = "~/.cocli/.authtoken"
)

Expand Down

0 comments on commit 37e530b

Please sign in to comment.