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: \
generate \
@ -6,16 +6,21 @@ default: \
reset-docs:
git checkout HEAD -- sig-list.md sig-*/README.md
build-image:
docker build -q -t $(IMAGE_NAME) -f generator/Dockerfile generator
generate:
go get ./...
go run ./generator/app.go
generate: build-image
docker run --rm -e WHAT -v $(shell pwd):/go/src/app/generated:Z $(IMAGE_NAME) app
generate-dockerized:
docker run --rm -e WHAT -v $(shell pwd):/go/src/app:Z $(IMAGE_NAME) make -C /go/src/app generate
verify:
@hack/verify.sh
test: build-image
docker run --rm $(IMAGE_NAME) go test -v ./...
test:
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
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
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:

View File

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

View File

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

View File

@ -1,38 +1,44 @@
#!/bin/bash
export CRTDIR=$(pwd)
export TMPDIR=/tmp/testgendocs
mkdir $TMPDIR
CRT_DIR=$(pwd)
VERIFY_TEMP=$(mktemp -d 2>/dev/null || mktemp -d -t k8s-community.XXXXXX)
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
mismatches=0
break=$(printf "=%.0s" $(seq 1 68))
for file in $(ls $CRTDIR/sig-*/README.md $CRTDIR/sig-list.md); do
real=${file#$CRTDIR/}
if ! diff -q $file $TMPDIR/$real &>/dev/null; then
echo "$file does not match $TMPDIR/$real";
for file in $(ls ${CRT_DIR}/sig-*/README.md ${CRT_DIR}/sig-list.md); do
real=${file#$CRT_DIR/}
if ! diff -q ${file} ${WORKING_DIR}/${real} &>/dev/null; then
echo "${file} does not match ${WORKING_DIR}/${real}";
mismatches=$((mismatches+1))
fi;
done
if [ $mismatches -gt "0" ]; then
if [ ${mismatches} -gt "0" ]; then
echo ""
echo $break
echo ${break}
noun="mismatch was"
if [ $mismatches -gt "0" ]; then
if [ ${mismatches} -gt "0" ]; then
noun="mismatches were"
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 "Instead make your changes to sigs.yaml and then run \`make\`.";
echo $break
echo ${break}
exit 1;
fi
rm -rf $TMPDIR
exit 0