Don't use docker by default for sig docs generator

This commit is contained in:
Christoph Blecker 2017-10-24 17:54:29 -07:00
parent 762e5d4e5a
commit c08c4ae2f9
No known key found for this signature in database
GPG Key ID: B34A59A9D39F838B
7 changed files with 74 additions and 53 deletions

View File

@ -1,4 +1,4 @@
IMAGE_NAME=kube-communitydocs IMAGE_NAME=golang:1.9
default: \ default: \
generate \ generate \
@ -6,16 +6,21 @@ default: \
reset-docs: reset-docs:
git checkout HEAD -- sig-list.md sig-*/README.md git checkout HEAD -- sig-list.md sig-*/README.md
build-image: generate:
docker build -q -t $(IMAGE_NAME) -f generator/Dockerfile generator go get ./...
go run ./generator/app.go
generate: build-image generate-dockerized:
docker run --rm -e WHAT -v $(shell pwd):/go/src/app/generated:Z $(IMAGE_NAME) app docker run --rm -e WHAT -v $(shell pwd):/go/src/app:Z $(IMAGE_NAME) make -C /go/src/app generate
verify: verify:
@hack/verify.sh @hack/verify.sh
test: build-image test:
docker run --rm $(IMAGE_NAME) go test -v ./... go get ./...
go test -v ./generator/...
.PHONY: default reset-docs build-image generate verify test test-dockerized:
docker run --rm -v $(shell pwd):/go/src/app:Z $(IMAGE_NAME) make -C /go/src/app test
.PHONY: default reset-docs generate generate-dockerized verify test test-dockerized

View File

@ -1,7 +0,0 @@
FROM golang:1.8
WORKDIR /go/src/app
COPY . .
RUN go-wrapper download
RUN go-wrapper install

View File

@ -24,15 +24,15 @@ sig-list.md
## How to use ## How to use
To (re)build documentation for all the SIGs, run these commands: To (re)build documentation for all the SIGs in a go environment, run:
```bash
make
```
or
```bash ```bash
make generate make generate
``` ```
or to run this inside a docker container:
```bash
make generate-dockerized
```
To build docs for one SIG, run one of these commands: To build docs for one SIG, run one of these commands:

View File

@ -29,7 +29,7 @@ import (
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
) )
var ( const (
readmeTemplate = "readme.tmpl" readmeTemplate = "readme.tmpl"
listTemplate = "list.tmpl" listTemplate = "list.tmpl"
headerTemplate = "header.tmpl" headerTemplate = "header.tmpl"
@ -37,13 +37,18 @@ var (
sigsYamlFile = "sigs.yaml" sigsYamlFile = "sigs.yaml"
sigListOutput = "sig-list.md" sigListOutput = "sig-list.md"
indexFilename = "README.md" indexFilename = "README.md"
baseOutputDir = "generated"
githubTeamNames = []string{"misc", "test-failures", "bugs", "feature-requests", "proposals", "pr-reviews", "api-reviews"}
beginMarker = "<!-- BEGIN CUSTOM CONTENT -->" beginMarker = "<!-- BEGIN CUSTOM CONTENT -->"
endMarker = "<!-- END CUSTOM CONTENT -->" endMarker = "<!-- END CUSTOM CONTENT -->"
) )
var (
baseGeneratorDir = ""
templateDir = "generator"
githubTeamNames = []string{"misc", "test-failures", "bugs", "feature-requests", "proposals", "pr-reviews", "api-reviews"}
)
// Lead represents a lead engineer for a particular group. There are usually // Lead represents a lead engineer for a particular group. There are usually
// 2 per group. // 2 per group.
type Lead struct { type Lead struct {
@ -150,7 +155,7 @@ func getExistingContent(path string) (string, error) {
func writeTemplate(templatePath, outputPath string, data interface{}) error { func writeTemplate(templatePath, outputPath string, data interface{}) error {
// set up template // set up template
t, err := template.ParseFiles(templatePath, headerTemplate) t, err := template.ParseFiles(templatePath, filepath.Join(baseGeneratorDir, templateDir, headerTemplate))
if err != nil { if err != nil {
return err return err
} }
@ -215,7 +220,7 @@ func createGroupReadme(groups []Group, prefix string) error {
fmt.Printf("Generating %s/README.md\n", group.Dir) fmt.Printf("Generating %s/README.md\n", group.Dir)
outputDir := filepath.Join(baseOutputDir, group.Dir) outputDir := filepath.Join(baseGeneratorDir, group.Dir)
if err := createDirIfNotExists(outputDir); err != nil { if err := createDirIfNotExists(outputDir); err != nil {
return err return err
} }
@ -223,7 +228,7 @@ func createGroupReadme(groups []Group, prefix string) error {
group.SetupGitHubTeams(prefix) group.SetupGitHubTeams(prefix)
outputPath := filepath.Join(outputDir, indexFilename) outputPath := filepath.Join(outputDir, indexFilename)
readmePath := fmt.Sprintf("%s_%s", prefix, readmeTemplate) readmePath := filepath.Join(baseGeneratorDir, templateDir, fmt.Sprintf("%s_%s", prefix, readmeTemplate))
if err := writeTemplate(readmePath, outputPath, group); err != nil { if err := writeTemplate(readmePath, outputPath, group); err != nil {
return err return err
} }
@ -233,7 +238,7 @@ func createGroupReadme(groups []Group, prefix string) error {
} }
func main() { func main() {
yamlData, err := ioutil.ReadFile(filepath.Join(baseOutputDir, sigsYamlFile)) yamlData, err := ioutil.ReadFile(filepath.Join(baseGeneratorDir, sigsYamlFile))
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }
@ -263,8 +268,8 @@ func main() {
} }
fmt.Println("Generating sig-list.md") fmt.Println("Generating sig-list.md")
outputPath := filepath.Join(baseOutputDir, sigListOutput) outputPath := filepath.Join(baseGeneratorDir, sigListOutput)
err = writeTemplate(listTemplate, outputPath, ctx) err = writeTemplate(filepath.Join(baseGeneratorDir, templateDir, listTemplate), outputPath, ctx)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
} }

View File

@ -83,6 +83,9 @@ func TestGetExistingData(t *testing.T) {
} }
func TestWriteTemplate(t *testing.T) { func TestWriteTemplate(t *testing.T) {
baseGeneratorDir = "generated"
templateDir = "../../generator"
customContent := ` customContent := `
<!-- BEGIN CUSTOM CONTENT --> <!-- BEGIN CUSTOM CONTENT -->
Example Example
@ -176,9 +179,12 @@ func TestCustomPrefixSetupGithubTeams(t *testing.T) {
} }
func TestCreateGroupReadmes(t *testing.T) { func TestCreateGroupReadmes(t *testing.T) {
baseGeneratorDir = "generated"
templateDir = "../../generator"
groups := []Group{ groups := []Group{
Group{Name: "Foo"}, {Name: "Foo"},
Group{Name: "Bar"}, {Name: "Bar"},
} }
err := createGroupReadme(groups, "sig") err := createGroupReadme(groups, "sig")
@ -187,7 +193,7 @@ func TestCreateGroupReadmes(t *testing.T) {
} }
for _, group := range groups { for _, group := range groups {
path := filepath.Join(baseOutputDir, group.DirName("sig"), "README.md") path := filepath.Join(baseGeneratorDir, group.DirName("sig"), "README.md")
if !pathExists(path) { if !pathExists(path) {
t.Fatalf("%s should exist", path) t.Fatalf("%s should exist", path)
} }
@ -195,11 +201,14 @@ func TestCreateGroupReadmes(t *testing.T) {
} }
func TestReadmesAreSkipped(t *testing.T) { func TestReadmesAreSkipped(t *testing.T) {
baseGeneratorDir = "generated"
templateDir = "../../generator"
os.Setenv("SIG", "sig-foo") os.Setenv("SIG", "sig-foo")
groups := []Group{ groups := []Group{
Group{Name: "Foo"}, {Name: "Foo"},
Group{Name: "Bar"}, {Name: "Bar"},
} }
err := createGroupReadme(groups, "sig") err := createGroupReadme(groups, "sig")
@ -208,7 +217,7 @@ func TestReadmesAreSkipped(t *testing.T) {
} }
for _, group := range groups[1:] { for _, group := range groups[1:] {
path := filepath.Join(baseOutputDir, group.DirName("sig"), "README.md") path := filepath.Join(baseGeneratorDir, group.DirName("sig"), "README.md")
if !pathExists(path) { if !pathExists(path) {
t.Fatalf("%s should exist", path) t.Fatalf("%s should exist", path)
} }
@ -232,6 +241,9 @@ func copyFile(src, dst string) error {
} }
func TestFullGeneration(t *testing.T) { func TestFullGeneration(t *testing.T) {
baseGeneratorDir = "generated"
templateDir = "../../generator"
err := copyFile("testdata/sigs.yaml", "generated/sigs.yaml") err := copyFile("testdata/sigs.yaml", "generated/sigs.yaml")
if err != nil { if err != nil {
t.Fatalf("Error received: %v", err) t.Fatalf("Error received: %v", err)
@ -241,7 +253,7 @@ func TestFullGeneration(t *testing.T) {
expectedDirs := []string{"sig-foo", "sig-bar", "wg-baz"} expectedDirs := []string{"sig-foo", "sig-bar", "wg-baz"}
for _, ed := range expectedDirs { for _, ed := range expectedDirs {
path := filepath.Join(baseOutputDir, ed, "README.md") path := filepath.Join(baseGeneratorDir, ed, "README.md")
if !pathExists(path) { if !pathExists(path) {
t.Fatalf("%s should exist", path) t.Fatalf("%s should exist", path)
} }

View File

@ -5,6 +5,6 @@ This is an autogenerated file!
Please do not edit this file directly, but instead make changes to the Please do not edit this file directly, but instead make changes to the
sigs.yaml file in the project root. sigs.yaml file in the project root.
To understand how this file is generated, see generator/README.md. To understand how this file is generated, see https://git.k8s.io/community/generator/README.md
--> -->
{{- end -}} {{- end -}}

View File

@ -1,38 +1,44 @@
#!/bin/bash #!/bin/bash
export CRTDIR=$(pwd) CRT_DIR=$(pwd)
export TMPDIR=/tmp/testgendocs VERIFY_TEMP=$(mktemp -d 2>/dev/null || mktemp -d -t k8s-community.XXXXXX)
mkdir $TMPDIR WORKING_DIR=${VERIFY_TEMP}/src/testgendocs
GOPATH=${VERIFY_TEMP}
mkdir -p ${WORKING_DIR}
cp -r sig* Makefile generator $TMPDIR function cleanup {
rm -rf "${VERIFY_TEMP}"
}
trap cleanup EXIT
cd $TMPDIR cp -r sig* Makefile generator ${WORKING_DIR}
cd ${WORKING_DIR}
make 1>/dev/null make 1>/dev/null
mismatches=0 mismatches=0
break=$(printf "=%.0s" $(seq 1 68)) break=$(printf "=%.0s" $(seq 1 68))
for file in $(ls $CRTDIR/sig-*/README.md $CRTDIR/sig-list.md); do for file in $(ls ${CRT_DIR}/sig-*/README.md ${CRT_DIR}/sig-list.md); do
real=${file#$CRTDIR/} real=${file#$CRT_DIR/}
if ! diff -q $file $TMPDIR/$real &>/dev/null; then if ! diff -q ${file} ${WORKING_DIR}/${real} &>/dev/null; then
echo "$file does not match $TMPDIR/$real"; echo "${file} does not match ${WORKING_DIR}/${real}";
mismatches=$((mismatches+1)) mismatches=$((mismatches+1))
fi; fi;
done done
if [ $mismatches -gt "0" ]; then if [ ${mismatches} -gt "0" ]; then
echo "" echo ""
echo $break echo ${break}
noun="mismatch was" noun="mismatch was"
if [ $mismatches -gt "0" ]; then if [ ${mismatches} -gt "0" ]; then
noun="mismatches were" noun="mismatches were"
fi fi
echo "$mismatches $noun detected." echo "${mismatches} ${noun} detected."
echo "Do not manually edit sig-list.md or README.md files inside the sig folders." echo "Do not manually edit sig-list.md or README.md files inside the sig folders."
echo "Instead make your changes to sigs.yaml and then run \`make\`."; echo "Instead make your changes to sigs.yaml and then run \`make\`.";
echo $break echo ${break}
exit 1; exit 1;
fi fi
rm -rf $TMPDIR
exit 0 exit 0