Skip to content
This repository has been archived by the owner on Sep 13, 2024. It is now read-only.

Commit

Permalink
Updating docs, gitops repo renderer almost finished
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickLaabs committed Feb 28, 2024
1 parent a391027 commit 1c87d7b
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 32 deletions.
4 changes: 2 additions & 2 deletions cmd/frigg/bootstrap/capd/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ func runE(logger log.Logger, streams cmd.IOStreams, flags *flagpole) error {
fmt.Println("Found Github Username Environment variable. Continuing..")
}

if os.Getenv("GITHUB_USERNAME_EMAIL") == "" {
if os.Getenv("GITHUB_MAIL") == "" {
fmt.Println("Missing Github Username, please set it. Exiting now.")
os.Exit(1)
} else {
os.Getenv("GITHUB_USERNAME_EMAIL")
os.Getenv("GITHUB_MAIL")
fmt.Println("Found Github Username Environment variable. Continuing..")
}

Expand Down
28 changes: 15 additions & 13 deletions cmd/frigg/bootstrap/capd/reporender/reporender.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package reporender
import (
"fmt"
"github.com/PatrickLaabs/frigg/pkg/common/wait"
"github.com/fatih/color"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing/object"
"os"
Expand All @@ -17,11 +18,12 @@ import (
// This Repo contains some placeholder strings.
// To be more precise:
// - GITHUB_USER
// - GITHUB_USER_EMAIL
// - GITHUB_MAIL

// FullStage combines everything, that is needed, to fully prepare the gitops repo for the end-user
func FullStage() {
fmt.Println("Rendering the gitops template repo")
println(color.GreenString("Rendering the gitops template repo"))

username, err := retrieveGithubUserEnv()
if err != nil {
fmt.Printf("Error retrieving username: %v", err)
Expand Down Expand Up @@ -57,7 +59,7 @@ func retrieveGithubUserEnv() (string, error) {
var username string

if os.Getenv("GITHUB_USERNAME") == "" {
fmt.Println("Missing Github Username, please set it. Exiting now.")
println(color.RedString("Missing Github Username, please set it. Exiting now."))
os.Exit(1)
} else {
username = os.Getenv("GITHUB_USERNAME")
Expand All @@ -67,31 +69,31 @@ func retrieveGithubUserEnv() (string, error) {
}

// retrieveGithubUserMailEnv retrieves and reads the os.Env variables needed for further preperation
// GITHUB_USER_EMAIL
// GITHUB_MAIL
func retrieveGithubUserMailEnv() (string, error) {
var usermail string

if os.Getenv("GITHUB_USER_EMAIL") == "" {
fmt.Println("Missing Github User Email, please set it. Exiting now.")
if os.Getenv("GITHUB_MAIL") == "" {
println(color.RedString("Missing Github User Email, please set it. Exiting now."))
os.Exit(1)
} else {
usermail = os.Getenv("GITHUB_USER_EMAIL")
usermail = os.Getenv("GITHUB_MAIL")
}

return usermail, nil
}

// githubLogin logs in to github via github cli using the provided github token
func githubLogin() {
fmt.Println("Loggin in to Github with your provided Github Token")
println(color.GreenString("Loggin in to Github with your provided Github Token"))

cmd := exec.Command("gh", "auth", "login")

// Capture the output of the command
output, err := cmd.CombinedOutput()
if err != nil {
fmt.Printf("Error running clusterctl: %s\n", err)
fmt.Println(string(output))
println(color.RedString("Error: %v", err))
println(color.YellowString(string(output)))
return
}
fmt.Println(string(output))
Expand Down Expand Up @@ -167,10 +169,10 @@ func replaceStrings(dirPath string, username string, usermail string) error {
return err
}

reGhUser := regexp.MustCompile(`GITHUB_USER`)
reGhMail := regexp.MustCompile(`GITHUB_USER_EMAIL`)
reGhUser := regexp.MustCompile(`GITHUB_USERNAME`)
reGhMail := regexp.MustCompile(`GITHUB_MAIL`)

// Replace GITHUB_USER and GITHUB_USER_EMAIL
// Replace GITHUB_USER and GITHUB_MAIL
newdata := replaceInString(data, reGhUser, username)
newdata = replaceInString(newdata, reGhMail, usermail)

Expand Down
14 changes: 10 additions & 4 deletions docs/providers/capd/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
# CAPD (ClusterAPI Provider for Docker) Documentation

## Get started
## Get started

You will need to pass two Environment variables:
You will need to pass two Environment variables:
- GITHUB_TOKEN
- GITHUB_USERNAME
- GITHUB_USERNAME_EMAIL
- GITHUB_MAIL

Updated on: 27 Feb 2024
```
export GITHUB_TOKEN=
export GITHUB_USERNAME=
export GITHUB_MAIL
```

Updated on: 28 Feb 2024
18 changes: 13 additions & 5 deletions docs/providers/capd/capd_docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,20 @@ import (
func MakeReadme(filename string) {
date := time.Now().Format("2 Jan 2006")

newLine := "\n"
doubleNewLine := "\n\n"

header := "# CAPD (ClusterAPI Provider for Docker) Documentation"
body := "## Get started \n\n" +
"You will need to pass two Environment variables: \n" +
"- GITHUB_TOKEN\n" +
"- GITHUB_USERNAME\n" +
"- GITHUB_USERNAME_EMAIL"
body := "## Get started" + doubleNewLine +
"You will need to pass two Environment variables:" + newLine +
"- GITHUB_TOKEN" + newLine +
"- GITHUB_USERNAME" + newLine +
"- GITHUB_MAIL" + doubleNewLine +
"```" + newLine +
"export GITHUB_TOKEN=" + newLine +
"export GITHUB_USERNAME=" + newLine +
"export GITHUB_MAIL" + newLine +
"```"
footer := "Updated on: " + date
data := fmt.Sprintf("%s\n\n%s\n\n%s", header, body, footer)

Expand Down
27 changes: 23 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ require (
github.com/BurntSushi/toml v1.3.2
github.com/alessio/shellescape v1.4.2
github.com/evanphx/json-patch/v5 v5.9.0
github.com/fatih/color v1.16.0
github.com/go-git/go-git/v5 v5.11.0
github.com/google/safetext v0.0.0-20240104143208-7a7d9b3d812f
github.com/mattn/go-isatty v0.0.20
github.com/pelletier/go-toml v1.9.5
Expand All @@ -18,15 +20,32 @@ require (
)

require (
dario.cat/mergo v1.0.0 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/pborman/uuid v1.2.1 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/sergi/go-diff v1.1.0 // indirect
github.com/skeema/knownhosts v1.2.1 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
golang.org/x/crypto v0.16.0 // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sys v0.16.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
golang.org/x/tools v0.13.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
)
Loading

0 comments on commit 1c87d7b

Please sign in to comment.