-
Notifications
You must be signed in to change notification settings - Fork 118
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create website for maintainers and contributors
See website/content/about/contributing.md (or /about/contributing) for how to contribute to the website. This uses a fork of github.com/cncf/contribute until we have approved the POC and merged my branch with required changes to work with Hugo. Signed-off-by: Carolyn Van Slyck <me@carolynvanslyck.com>
- Loading branch information
Showing
57 changed files
with
15,627 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| * | ||
| !website | ||
| website/public | ||
| website/go.local.mod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| [submodule "website/themes/docsy"] | ||
| path = website/themes/docsy | ||
| url = https://github.com/google/docsy.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| module github.com/cncf/sig-contributor-strategy | ||
|
|
||
| go 1.15 | ||
|
|
||
| require ( | ||
| github.com/carolynvs/magex v0.4.0 | ||
| github.com/magefile/mage v1.11.0 | ||
| github.com/pkg/errors v0.9.1 | ||
| ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| github.com/carolynvs/magex v0.4.0 h1:BEcWFju5JNtfHcyvoENZzzPObpv0IHZnhxkOT4hKv4M= | ||
| github.com/carolynvs/magex v0.4.0/go.mod h1:2UQe/9ipQIsGcvwavGLv/c2IEJG32zu0iafZhUlk/Z4= | ||
| github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= | ||
| github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= | ||
| github.com/magefile/mage v1.11.0 h1:C/55Ywp9BpgVVclD3lRnSYCwXTYxmSppIgLeDYlNuls= | ||
| github.com/magefile/mage v1.11.0/go.mod h1:z5UZb/iS3GoOSn0JgWuiw7dxlurVYTu+/jHXqQg881A= | ||
| github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= | ||
| github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= | ||
| github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= | ||
| github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= | ||
| github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= | ||
| github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= | ||
| github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= | ||
| gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||
| gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
| gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= | ||
| gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // +build ignore | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "os" | ||
|
|
||
| "github.com/magefile/mage/mage" | ||
| ) | ||
|
|
||
| // This file allows someone to run mage commands without mage installed | ||
| // by running `go run mage.go TARGET`. | ||
| // See https://magefile.org/zeroinstall/ | ||
| func main() { os.Exit(mage.Main()) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,264 @@ | ||
| // +build mage | ||
|
|
||
| // This is a magefile, and is a "makefile for go". | ||
| // See https://magefile.org/ | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "io" | ||
| "log" | ||
| "os" | ||
| "path/filepath" | ||
| "runtime" | ||
| "strings" | ||
| "time" | ||
|
|
||
| "github.com/carolynvs/magex/pkg" | ||
| "github.com/carolynvs/magex/shx" | ||
| "github.com/carolynvs/magex/xplat" | ||
| "github.com/magefile/mage/mg" | ||
| "github.com/pkg/errors" | ||
| ) | ||
|
|
||
| // Default target to run when none is specified | ||
| // If not set, running mage will list available targets | ||
| var ( | ||
| Default = Preview | ||
| contributeRepo = "../contribute" | ||
| ) | ||
|
|
||
| const ( | ||
| containerName = "sig-contributor-strategy" | ||
| img = containerName | ||
| ) | ||
|
|
||
| // Ensure Mage is installed and on the PATH. | ||
| func EnsureMage() error { | ||
| return pkg.EnsureMage("") | ||
| } | ||
|
|
||
| // Compile the website to website/public. | ||
| func Build() error { | ||
| mg.Deps(clean, buildImage) | ||
|
|
||
| // Build the volume mount for a local contribute repo, if present | ||
| contribMount, goModMount, err := useLocalContributeModule() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| pwd, _ := os.Getwd() | ||
| return shx.Command("docker","run", "--rm", "-v", pwd+":/src", | ||
| contribMount, goModMount, containerName, "--debug", "--verbose").CollapseArgs().RunV() | ||
| } | ||
|
|
||
| // Run a local server to preview the website and watch for changes. | ||
| func Preview() error { | ||
| mg.Deps(clean, buildImage) | ||
|
|
||
| // Build the volume mount for a local contribute repo, if present | ||
| contribMount, goModMount, err := useLocalContributeModule() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| port := getPort() | ||
| pwd, _ := os.Getwd() | ||
| err = shx.Command("docker", "run", "-d", "-v", pwd+":/src", | ||
| contribMount, goModMount, "-p", port+":1313", | ||
| "--name", containerName, img, "server", "--debug", "--verbose", | ||
| "--buildDrafts", "--buildFuture", "--noHTTPCache", "--watch", "--bind=0.0.0.0").CollapseArgs().RunV() | ||
| if err != nil { | ||
| return errors.Wrap(err, "could not run website container") | ||
| } | ||
|
|
||
| err = awaitContainer(containerName, "Web Server is available") | ||
| if err != nil { | ||
| return errors.Wrap(err, "error waiting for the website to become ready") | ||
| } | ||
|
|
||
| url := "http://localhost:" + getPort() | ||
| return errors.Wrap(openURL(url), "could not open the website in a browser") | ||
| } | ||
|
|
||
| func Logs() error { | ||
| return shx.RunV("docker", "logs", "-f", img) | ||
| } | ||
|
|
||
| // Use hugo in a docker container. | ||
| func Hugo() error { | ||
| pwd, _ := os.Getwd() | ||
| cmd := shx.Command("docker", "run", "--rm", "-it", "-v", pwd+":/src", "-w", "/src/website", img, "shell"). | ||
| Stdout(os.Stdout) | ||
| cmd.Cmd.Stdin = os.Stdin | ||
| _, _, err := cmd.Exec() | ||
| return errors.Wrap(err, "could not start hugo in a container") | ||
| } | ||
|
|
||
| func Deploy() error { | ||
| mg.Deps(docsy, syncGoMod) | ||
|
|
||
| return shx.RunV("hugo", "-s", "website", "--debug", "--verbose") | ||
| } | ||
|
|
||
| func DeployPreview() error { | ||
| mg.Deps(docsy, syncGoMod) | ||
|
|
||
| return shx.RunV("hugo", "-s", "website", "--debug", "--verbose", "-b", getBaseUrl()) | ||
| } | ||
|
|
||
| func syncGoMod() error { | ||
| return shx.RunV("go", "mod", "download") | ||
| } | ||
|
|
||
| func getBaseUrl() string { | ||
| return os.Getenv("DEPLOY_PRIME_URL" + "/") | ||
| } | ||
|
|
||
| // Create go.local.mod with any appropriate replace statements, and | ||
| // returns the local contribute mount flag if present. | ||
| func useLocalContributeModule() (contribMount string, goModMount string, err error) { | ||
| // Edit a copy of website/go.mod so that it doesn't always show up as modified in git | ||
| pwd, _ := os.Getwd() | ||
| localGoMod := filepath.Join(pwd, "website/go.local.mod") | ||
| err = copyFile("website/go.mod", localGoMod) | ||
| if err != nil { | ||
| return "", "", err | ||
| } | ||
| goModMount = fmt.Sprintf("-v=%s:/src/website/go.mod", localGoMod) | ||
|
|
||
| err = shx.RunV("docker", "run", "--rm", "--entrypoint", "go", | ||
| "-v", pwd+":/src", goModMount, "-w", "/src/website", img, | ||
| "mod", "download") | ||
| if err != nil { | ||
| return "", "", errors.Wrap(err, "could not modify resolve go.mod") | ||
| } | ||
|
|
||
| // Only mount the local repo if it exists, otherwise use the one on github | ||
| if mg.Verbose() { | ||
| fmt.Println("Checking for a local copy of github.com/cncf/contribute at", contributeRepo) | ||
| } | ||
| if repo, ok := os.LookupEnv("CONTRIBUTE_REPO"); ok { | ||
| contributeRepo = repo | ||
| } | ||
| contributeRepo, _ := filepath.Abs(contributeRepo) | ||
| _, err = os.Stat(contributeRepo) | ||
| if err != nil { | ||
| return "", goModMount, nil | ||
| } | ||
|
|
||
| log.Println("Using your local copy of github.com/cncf/contribute ->", contributeRepo) | ||
| err = shx.RunV("docker", "run", "--rm", "--entrypoint", "go", | ||
| "-v", pwd+":/src", goModMount, "-w", "/src/website", img, | ||
| "mod", "edit", "-replace", "github.com/cncf/contribute=/src/contribute") | ||
| if err != nil { | ||
| return "", "", errors.Wrap(err, "could not modify go.mod to use your local copy of github.com/cncf/contribute") | ||
| } | ||
|
|
||
| contribMount = fmt.Sprintf("-v=%s:/src/contribute", contributeRepo) | ||
| return contribMount, goModMount, nil | ||
| } | ||
|
|
||
| func copyFile(src string, dest string) error { | ||
| s, err := os.Open(src) | ||
| if err != nil { | ||
| return errors.Wrapf(err, "could not open %s", src) | ||
| } | ||
|
|
||
| d, err := os.Create(dest) | ||
| if err != nil { | ||
| return errors.Wrapf(err, "could not create %s", dest) | ||
| } | ||
|
|
||
| _, err = io.Copy(d, s) | ||
| return errors.Wrapf(err, "could not copy %s to %s", src, dest) | ||
| } | ||
|
|
||
| func openURL(url string) error { | ||
| shell := xplat.DetectShell() | ||
| if shell == "msystem" { | ||
| return shx.RunE("cmd", "/C", "open "+url) | ||
| } | ||
| if runtime.GOOS == "windows" { | ||
| return shx.RunE("powershell", "Start-Process", url) | ||
| } | ||
| return shx.RunE(shell, "-c", "open "+url) | ||
| } | ||
|
|
||
| func getPort() string { | ||
| port := os.Getenv("PORT") | ||
| if port == "" { | ||
| port = "1313" | ||
| } | ||
| return port | ||
| } | ||
|
|
||
| func buildImage() error { | ||
| mg.Deps(docsy) | ||
| err := shx.RunE("docker", "build", "-t", img, | ||
| "-f", "website/Dockerfile", ".") | ||
| return errors.Wrap(err, "could not build website image") | ||
| } | ||
|
|
||
| func docsy() error { | ||
| _, err := os.Stat("website/themes/docsy") | ||
| if err != nil { | ||
| if os.IsNotExist(err) { | ||
| return shx.RunE("git", "submodule", "update", "--init", "--recursive", "--force") | ||
| } | ||
| return errors.Wrap(err, "could not clone the docsy theme") | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func containerExists(name string) bool { | ||
| output, err := shx.Output("docker", "ps", "--all", "--filter", "name="+name) | ||
| return err == nil && strings.Contains(output, name) | ||
| } | ||
|
|
||
| func removeContainer(name string) error { | ||
| return shx.RunV("docker", "rm", "-f", name) | ||
| } | ||
|
|
||
| func awaitContainer(name string, logSearch string) error { | ||
| cxt, cancel := context.WithTimeout(context.Background(), time.Minute) | ||
| defer cancel() | ||
|
|
||
| for { | ||
| select { | ||
| case <-cxt.Done(): | ||
| return errors.Errorf("timeout waiting for container %s to become ready", name) | ||
| default: | ||
| logs, err := shx.Output("docker", "logs", name) | ||
| if err != nil { | ||
| return errors.Wrapf(err, "could not get logs for container %s", name) | ||
| } | ||
|
|
||
| if strings.Contains(logs, logSearch) { | ||
| return nil | ||
| } | ||
|
|
||
| if mg.Verbose() { | ||
| fmt.Println(logs) | ||
| } | ||
|
|
||
| time.Sleep(time.Second) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func clean() error { | ||
| err := os.RemoveAll("website/public") | ||
| if err != nil { | ||
| return errors.Wrap(err, "could not remove website/public") | ||
| } | ||
|
|
||
| if containerExists(containerName) { | ||
| return removeContainer(containerName) | ||
| } | ||
|
|
||
| return nil | ||
| } |
Oops, something went wrong.