diff --git a/.dockerignore b/.dockerignore index 67f315881..a5d8f7237 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,3 +1,2 @@ -.git/ bin/ dist/ diff --git a/Makefile b/Makefile index a70730d87..64e15ddf8 100644 --- a/Makefile +++ b/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 diff --git a/builder.Makefile b/builder.Makefile index bd610a0c1..3509e61f1 100644 --- a/builder.Makefile +++ b/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 \ No newline at end of file diff --git a/docs/docs.Dockerfile b/docs/docs.Dockerfile new file mode 100644 index 000000000..780a9736e --- /dev/null +++ b/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 <&2 'ERROR: Docs result differs. Please update with "make docs"' + git status --porcelain -- docs/reference + exit 1 +fi +EOT diff --git a/docs/yaml/main/generate.go b/docs/yaml/main/generate.go index 7a86dcdae..90ac25cf1 100644 --- a/docs/yaml/main/generate.go +++ b/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{