Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add s3 backend replace #608

Merged
merged 5 commits into from
Oct 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 11 additions & 20 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,20 +250,15 @@ cluster provisioning process spinning up the services, and validates the livenes
}
}()

/*
// todo: wire it up in the architecture / files / folder

this is atlantis temporary code

*/
// 1
err = replaceS3Backend()
// update terraform s3 backend to internal k8s dns (s3/minio bucket)
err = pkg.ReplaceS3Backend()
if err != nil {
return err
}
//
// 2 git push to new repo
////ref := plumbing.NewHashReference("refs/heads/update-s3-backend", headRef.Hash())
//

// create a new branch and push changes
githubHost := viper.GetString("github.host")
githubOwner := viper.GetString("github.owner")
remoteName := "github"
Expand All @@ -282,26 +277,22 @@ cluster provisioning process spinning up the services, and validates the livenes
fmt.Println("sleeping after commit...")
time.Sleep(3 * time.Second)

// 3
// create a PR, atlantis will identify it's a terraform change/file update and,
// trigger atlantis plan
g := githubWrapper.New()
err = g.CreatePR(branchName)
if err != nil {
fmt.Println(err)
}
fmt.Println("sleeping after create PR...")
log.Println("sleeping after create PR...")
time.Sleep(5 * time.Second)
log.Println("sleeping... atlantis plan should be running")
time.Sleep(5 * time.Second)
//
//// 4
err = g.CommentPR(3, "atlantis plan")
if err != nil {
fmt.Println(err)
}

fmt.Println("sleeping before apply...")
time.Sleep(120 * time.Second)

// 5
// call atlantis apply
// after 120 seconds, it will comment in the PR with atlantis plan
err = g.CommentPR(1, "atlantis apply")
if err != nil {
fmt.Println(err)
Expand Down
4 changes: 2 additions & 2 deletions internal/gitClient/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,12 +446,12 @@ func UpdateLocalTFFilesAndPush(githubHost, githubOwner, localRepo, remoteName st
// }
//}

kubefirstGitHubFile := fmt.Sprintf("%s/gitops/terraform/users/kubefirst-github.tf", cfg.K1FolderPath)
kubefirstGitHubFile := "terraform/users/kubefirst-github.tf"
_, err = w.Add(kubefirstGitHubFile)
if err != nil {
log.Println(err)
}
vaultMainFile := fmt.Sprintf("%s/gitops/terraform/vault/main.tf", cfg.K1FolderPath)
vaultMainFile := "terraform/vault/main.tf"
_, err = w.Add(vaultMainFile)
if err != nil {
log.Println(err)
Expand Down
33 changes: 33 additions & 0 deletions pkg/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,3 +444,36 @@ func AwaitHostNTimes(url string, times int, gracePeriod time.Duration) {
// fmt.Println(ngrokOutput.Tunnels[0].PublicURL)
// return ngrokOutput.Tunnels[0].PublicURL
// }

// this is temporary code
func ReplaceS3Backend() error {

config := configs.ReadConfig()

vaultMainFile := fmt.Sprintf("%s/gitops/terraform/vault/main.tf", config.K1FolderPath)

file, err := os.ReadFile(vaultMainFile)
if err != nil {
return err
}
newContents := strings.Replace(string(file), "http://127.0.0.1:9000", "http://minio.minio.svc.cluster.local:9000", -1)

err = os.WriteFile(vaultMainFile, []byte(newContents), 0)
if err != nil {
return err
}

kubefirstGitHubFile := fmt.Sprintf("%s/gitops/terraform/users/kubefirst-github.tf", config.K1FolderPath)
file2, err := os.ReadFile(kubefirstGitHubFile)
if err != nil {
return err
}
newContents2 := strings.Replace(string(file2), "http://127.0.0.1:9000", "http://minio.minio.svc.cluster.local:9000", -1)

err = os.WriteFile(kubefirstGitHubFile, []byte(newContents2), 0)
if err != nil {
return err
}

return nil
}