Skip to content

Commit bf26cbd

Browse files
gloursndeloof
authored andcommitted
contenairized documetation generation
add docs validation (using same process a BuildX project) Signed-off-by: Guillaume Lours <[email protected]>
1 parent 35ba6f6 commit bf26cbd

File tree

5 files changed

+77
-7
lines changed

5 files changed

+77
-7
lines changed

.dockerignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
.git/
21
bin/
32
dist/

Makefile

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,19 @@ lint: ## run linter(s)
8282
--build-arg GIT_TAG=$(GIT_TAG) \
8383
--target lint
8484

85+
.PHONY: docs
86+
docs: ## generate documentation
87+
@docker build . \
88+
--output type=local,dest=./docs/ \
89+
-f ./docs/docs.Dockerfile \
90+
--target update
91+
92+
.PHONY: validate-docs
93+
validate-docs: ## validate the doc does not change
94+
@docker build . \
95+
-f ./docs/docs.Dockerfile \
96+
--target validate
97+
8598
.PHONY: check-dependencies
8699
check-dependencies: ## check dependency updates
87100
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
98111
validate-go-mod: ## Validate go.mod and go.sum are up-to-date
99112
@docker build . --target check-go-mod
100113

101-
validate: validate-go-mod validate-headers ## Validate sources
114+
validate: validate-go-mod validate-headers validate-docs ## Validate sources
102115

103116
pre-commit: validate check-dependencies lint compose-plugin test e2e-compose
104117

builder.Makefile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,3 @@ check-license-headers:
7070
.PHONY: check-go-mod
7171
check-go-mod:
7272
./scripts/validate/check-go-mod
73-
74-
.PHONY: yamldocs
75-
yamldocs:
76-
go run docs/yaml/main/generate.go

docs/docs.Dockerfile

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# syntax=docker/dockerfile:1.3-labs
2+
3+
4+
# Copyright 2020 Docker Compose CLI authors
5+
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
ARG GO_VERSION=1.17
19+
ARG FORMATS=md,yaml
20+
21+
FROM --platform=${BUILDPLATFORM} golang:${GO_VERSION}-alpine AS docsgen
22+
WORKDIR /src
23+
RUN --mount=target=. \
24+
--mount=target=/root/.cache,type=cache \
25+
go build -o /out/docsgen ./docs/yaml/main/generate.go
26+
27+
FROM --platform=${BUILDPLATFORM} alpine AS gen
28+
RUN apk add --no-cache rsync git
29+
WORKDIR /src
30+
COPY --from=docsgen /out/docsgen /usr/bin
31+
ARG FORMATS
32+
RUN --mount=target=/context \
33+
--mount=target=.,type=tmpfs <<EOT
34+
set -e
35+
rsync -a /context/. .
36+
docsgen --formats "$FORMATS" --source "docs/reference"
37+
mkdir /out
38+
cp -r docs/reference /out
39+
EOT
40+
41+
FROM scratch AS update
42+
COPY --from=gen /out /
43+
44+
FROM gen AS validate
45+
RUN --mount=target=/context \
46+
--mount=target=.,type=tmpfs <<EOT
47+
set -e
48+
rsync -a /context/. .
49+
git add -A
50+
rm -rf docs/reference/*
51+
cp -rf /out/* ./docs/
52+
if [ -n "$(git status --porcelain -- docs/reference)" ]; then
53+
echo >&2 'ERROR: Docs result differs. Please update with "make docs"'
54+
git status --porcelain -- docs/reference
55+
exit 1
56+
fi
57+
EOT

docs/yaml/main/generate.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,21 @@ import (
2222
"path/filepath"
2323

2424
clidocstool "github.com/docker/cli-docs-tool"
25+
"github.com/docker/cli/cli/command"
2526
"github.com/docker/compose/v2/cmd/compose"
2627
"github.com/spf13/cobra"
2728
)
2829

2930
func generateDocs(opts *options) error {
31+
dockerCLI, err := command.NewDockerCli()
32+
if err != nil {
33+
return err
34+
}
3035
cmd := &cobra.Command{
3136
Use: "docker",
3237
DisableAutoGenTag: true,
3338
}
34-
cmd.AddCommand(compose.RootCommand(nil, nil))
39+
cmd.AddCommand(compose.RootCommand(dockerCLI, nil))
3540
disableFlagsInUseLine(cmd)
3641

3742
tool, err := clidocstool.New(clidocstool.Options{

0 commit comments

Comments
 (0)