-
Notifications
You must be signed in to change notification settings - Fork 690
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into informermap
- Loading branch information
Showing
50 changed files
with
5,738 additions
and
266 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
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,60 @@ | ||
#! /usr/bin/env bash | ||
|
||
# make-release-tag.sh: This script assumes that you are on a branch and have | ||
# otherwise prepared the release. It rewrites the Docker image version in | ||
# the deployment YAML, then created a tag with a message containing the | ||
# shortlog from the previous versio. | ||
|
||
readonly PROGNAME=$(basename "$0") | ||
readonly OLDVERS="$1" | ||
readonly NEWVERS="$2" | ||
|
||
if [ -z "$OLDVERS" ] || [ -z "$NEWVERS" ]; then | ||
printf "Usage: %s OLDVERS NEWVERS\n" PROGNAME | ||
exit 1 | ||
fi | ||
|
||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
readonly IMG="docker.io/projectcontour/contour:$NEWVERS" | ||
|
||
|
||
if [ -n "$(git tag --list "$NEWVERS")" ]; then | ||
printf "%s: tag '%s' already exists\n" "$PROGNAME" "$NEWVERS" | ||
exit 1 | ||
fi | ||
|
||
# NOTE(jpeach): this will go away or change once we move to kustomize | ||
# since at that point the versioned image name will appear exactly once. | ||
for f in examples/contour/03-envoy.yaml examples/contour/03-contour.yaml ; do | ||
case $(uname -s) in | ||
Darwin) | ||
sed -i '' "-es|docker.io/projectcontour/contour:master|$IMG|" "$f" | ||
;; | ||
Linux) | ||
sed -i "-es|docker.io/projectcontour/contour:master|$IMG|" "$f" | ||
;; | ||
*) | ||
printf "Unsupported system '%s'" "$(uname -s)" | ||
exit 2 | ||
;; | ||
esac | ||
done | ||
|
||
make generate | ||
|
||
git commit -s -m "Update Contour Docker image to $NEWVERS." \ | ||
examples/contour/03-contour.yaml \ | ||
examples/contour/03-envoy.yaml \ | ||
examples/render/contour.yaml | ||
|
||
git tag -F - "$NEWVERS" <<EOF | ||
Tag $NEWVERS release. | ||
$(git shortlog "$OLDVERS..HEAD") | ||
EOF | ||
|
||
printf "Created tag '%s'\n" "$NEWVERS" | ||
printf "Run '%s' to push the tag if you are happy\n" "git push --tags" |
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,180 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
"os/exec" | ||
"path" | ||
"strings" | ||
|
||
"sigs.k8s.io/kustomize/kyaml/yaml" | ||
) | ||
|
||
func must(err error) { | ||
if err != nil { | ||
log.Fatalf("%s", err.Error()) | ||
} | ||
} | ||
|
||
func run(cmd []string) { | ||
c := exec.Command(cmd[0], cmd[1:]...) | ||
|
||
c.Stdin = os.Stdin | ||
c.Stdout = os.Stdout | ||
c.Stderr = os.Stderr | ||
|
||
if err := c.Run(); err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
func capture(cmd []string) string { | ||
out := bytes.Buffer{} | ||
c := exec.Command(cmd[0], cmd[1:]...) | ||
|
||
c.Stdin = nil | ||
c.Stdout = &out | ||
c.Stderr = &out | ||
|
||
if err := c.Run(); err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
return out.String() | ||
} | ||
|
||
func updateMappingForTOC(filePath string, vers string, toc string) error { | ||
data, err := ioutil.ReadFile(filePath) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
rn := yaml.MustParse(string(data)) | ||
|
||
if _, err := rn.Pipe( | ||
yaml.FieldSetter{Name: vers, StringValue: toc}); err != nil { | ||
return err | ||
} | ||
|
||
return ioutil.WriteFile(filePath, []byte(rn.MustString()), 0644) | ||
} | ||
|
||
// InsertAfter is like yaml.ElementAppender except it inserts after the named node. | ||
type InsertAfter struct { | ||
After string | ||
Node *yaml.Node | ||
} | ||
|
||
// Filter ... | ||
func (a InsertAfter) Filter(rn *yaml.RNode) (*yaml.RNode, error) { | ||
if err := yaml.ErrorIfInvalid(rn, yaml.SequenceNode); err != nil { | ||
return nil, err | ||
} | ||
|
||
content := make([]*yaml.Node, 0) | ||
|
||
for _, node := range rn.YNode().Content { | ||
content = append(content, node) | ||
if node.Value == a.After { | ||
content = append(content, a.Node) | ||
} | ||
} | ||
|
||
rn.YNode().Content = content | ||
return rn, nil | ||
} | ||
|
||
func updateConfigForSite(filePath string, vers string) error { | ||
data, err := ioutil.ReadFile(filePath) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
scopeNode := yaml.MustParse( | ||
fmt.Sprintf(` | ||
scope: | ||
path: docs/%s | ||
values: | ||
version: %s | ||
layout: "docs" | ||
`, vers, vers)) | ||
|
||
rn := yaml.MustParse(string(data)) | ||
|
||
// Append the new scope to the "defaults" array. | ||
if _, err := rn.Pipe( | ||
yaml.Lookup("defaults"), | ||
yaml.Append(scopeNode.YNode()), | ||
); err != nil { | ||
log.Fatalf("%s", err) | ||
} | ||
|
||
// Set this version to the "latest" value. | ||
if _, err := rn.Pipe( | ||
yaml.FieldSetter{Name: "latest", StringValue: vers}); err != nil { | ||
return err | ||
} | ||
|
||
versNode := yaml.Node{ | ||
Kind: yaml.ScalarNode, | ||
Value: vers, | ||
} | ||
|
||
// Insert the new scope to the "defaults" array. We insert | ||
// after the "master" element so that it stays in order. | ||
if _, err := rn.Pipe( | ||
yaml.Lookup("versions"), | ||
InsertAfter{After: "master", Node: &versNode}, | ||
); err != nil { | ||
log.Fatalf("%s", err) | ||
} | ||
|
||
return ioutil.WriteFile(filePath, []byte(rn.MustString()), 0644) | ||
} | ||
|
||
func main() { | ||
if len(os.Args) != 2 { | ||
fmt.Printf("Usage: %s NEWVERS\n", | ||
path.Base(os.Args[0])) | ||
os.Exit(1) | ||
} | ||
|
||
newVers := os.Args[1] | ||
|
||
log.Printf("Verifying repository state ...") | ||
|
||
status := capture([]string{"git", "status", "--short"}) | ||
for _, line := range strings.Split(status, "\n") { | ||
// See https://git-scm.com/docs/git-status#_short_format. | ||
if strings.ContainsAny(line, "MADRCU") { | ||
log.Fatal("uncommitted changes in repository") | ||
} | ||
} | ||
|
||
log.Printf("Cloning versioned documentation ...") | ||
|
||
// Jekyll hates it when the TOC file name contains a dot. | ||
tocName := strings.ReplaceAll(fmt.Sprintf("%s-toc", newVers), ".", "-") | ||
|
||
// Make a versioned copy of the amster docs. | ||
run([]string{"cp", "-r", "site/docs/master", fmt.Sprintf("site/docs/%s", newVers)}) | ||
run([]string{"git", "add", fmt.Sprintf("site/docs/%s", newVers)}) | ||
|
||
// Make a versioned TOC for the docs. | ||
run([]string{"cp", "-r", "site/_data/master-toc.yml", fmt.Sprintf("site/_data/%s.yml", tocName)}) | ||
run([]string{"git", "add", fmt.Sprintf("site/_data/%s.yml", tocName)}) | ||
|
||
// Insert the versioned TOC. | ||
must(updateMappingForTOC("site/_data/toc-mapping.yml", newVers, tocName)) | ||
run([]string{"git", "add", "site/_data/toc-mapping.yml"}) | ||
|
||
// Insert the versioned docs into the main site layout. | ||
must(updateConfigForSite("site/_config.yml", newVers)) | ||
run([]string{"git", "add", "site/_config.yml"}) | ||
|
||
// Now commit everything | ||
run([]string{"git", "commit", "-s", "-m", fmt.Sprintf("Prepare documentation site for %s release.", newVers)}) | ||
} |
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
Oops, something went wrong.