docs.Dockerfile 1.6 KB

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