فهرست منبع

contenairized documetation generation
add docs validation (using same process a BuildX project)

Signed-off-by: Guillaume Lours <[email protected]>

Guillaume Lours 3 سال پیش
والد
کامیت
bf26cbd498
5فایلهای تغییر یافته به همراه77 افزوده شده و 7 حذف شده
  1. 0 1
      .dockerignore
  2. 14 1
      Makefile
  3. 0 4
      builder.Makefile
  4. 57 0
      docs/docs.Dockerfile
  5. 6 1
      docs/yaml/main/generate.go

+ 0 - 1
.dockerignore

@@ -1,3 +1,2 @@
-.git/
 bin/
 dist/

+ 14 - 1
Makefile

@@ -82,6 +82,19 @@ lint: ## run linter(s)
 	--build-arg GIT_TAG=$(GIT_TAG) \
 	--target lint
 
+.PHONY: docs
+docs: ## generate documentation
+	@docker build . \
+	--output type=local,dest=./docs/ \
+	-f ./docs/docs.Dockerfile \
+	--target update
+
+.PHONY: validate-docs
+validate-docs: ## validate the doc does not change
+	@docker build . \
+	-f ./docs/docs.Dockerfile \
+	--target validate
+
 .PHONY: check-dependencies
 check-dependencies: ## check dependency updates
 	go list -u -m -f '{{if not .Indirect}}{{if .Update}}{{.}}{{end}}{{end}}' all
@@ -98,7 +111,7 @@ go-mod-tidy: ## Run go mod tidy in a container and output resulting go.mod and g
 validate-go-mod: ## Validate go.mod and go.sum are up-to-date
 	@docker build . --target check-go-mod
 
-validate: validate-go-mod validate-headers ## Validate sources
+validate: validate-go-mod validate-headers validate-docs ## Validate sources
 
 pre-commit: validate check-dependencies lint compose-plugin test e2e-compose
 

+ 0 - 4
builder.Makefile

@@ -70,7 +70,3 @@ check-license-headers:
 .PHONY: check-go-mod
 check-go-mod:
 	./scripts/validate/check-go-mod
-
-.PHONY: yamldocs
-yamldocs:
-	go run docs/yaml/main/generate.go

+ 57 - 0
docs/docs.Dockerfile

@@ -0,0 +1,57 @@
+# syntax=docker/dockerfile:1.3-labs
+
+
+#   Copyright 2020 Docker Compose CLI authors
+
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+
+#       http://www.apache.org/licenses/LICENSE-2.0
+
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+
+ARG GO_VERSION=1.17
+ARG FORMATS=md,yaml
+
+FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION}-alpine AS docsgen
+WORKDIR /src
+RUN --mount=target=. \
+  --mount=target=/root/.cache,type=cache \
+  go build -o /out/docsgen ./docs/yaml/main/generate.go
+
+FROM --platform=${BUILDPLATFORM} alpine AS gen
+RUN apk add --no-cache rsync git
+WORKDIR /src
+COPY --from=docsgen /out/docsgen /usr/bin
+ARG FORMATS
+RUN --mount=target=/context \
+  --mount=target=.,type=tmpfs <<EOT
+set -e
+rsync -a /context/. .
+docsgen --formats "$FORMATS" --source "docs/reference"
+mkdir /out
+cp -r docs/reference /out
+EOT
+
+FROM scratch AS update
+COPY --from=gen /out /
+
+FROM gen AS validate
+RUN --mount=target=/context \
+  --mount=target=.,type=tmpfs <<EOT
+set -e
+rsync -a /context/. .
+git add -A
+rm -rf docs/reference/*
+cp -rf /out/* ./docs/
+if [ -n "$(git status --porcelain -- docs/reference)" ]; then
+  echo >&2 'ERROR: Docs result differs. Please update with "make docs"'
+  git status --porcelain -- docs/reference
+  exit 1
+fi
+EOT

+ 6 - 1
docs/yaml/main/generate.go

@@ -22,16 +22,21 @@ import (
 	"path/filepath"
 
 	clidocstool "github.com/docker/cli-docs-tool"
+	"github.com/docker/cli/cli/command"
 	"github.com/docker/compose/v2/cmd/compose"
 	"github.com/spf13/cobra"
 )
 
 func generateDocs(opts *options) error {
+	dockerCLI, err := command.NewDockerCli()
+	if err != nil {
+		return err
+	}
 	cmd := &cobra.Command{
 		Use:               "docker",
 		DisableAutoGenTag: true,
 	}
-	cmd.AddCommand(compose.RootCommand(nil, nil))
+	cmd.AddCommand(compose.RootCommand(dockerCLI, nil))
 	disableFlagsInUseLine(cmd)
 
 	tool, err := clidocstool.New(clidocstool.Options{