Merge pull request #10331 from thaJeztah/archives_and_source_only

Dockerfile: allow building without archives, and exporting HTML source
This commit is contained in:
Usha Mandya 2020-02-24 12:24:02 +00:00 committed by GitHub
commit f56f1476ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 45 additions and 20 deletions

View File

@ -18,6 +18,8 @@ ARG ENGINE_BRANCH="19.03.x"
# Distribution
ARG DISTRIBUTION_BRANCH="release/2.7"
# Set to "false" to build the documentation without archives
ARG ENABLE_ARCHIVES=true
###
# Set up base stages for building and deploying
@ -52,17 +54,23 @@ COPY --from=docs/docker.github.io:nginx-onbuild /etc/nginx/conf.d/default.conf /
CMD echo -e "Docker docs are viewable at:\nhttp://0.0.0.0:4000"; exec nginx -g 'daemon off;'
# Build the archived docs
# these docs barely change, so can be cached
FROM deploybase AS archives
# Get all the archive static HTML and put it into place. To add a new archive,
# add it here, and ALSO edit _data/docsarchives/archives.yaml to add it to the drop-down
COPY --from=docs/docker.github.io:v17.03 ${TARGET} ${TARGET}
COPY --from=docs/docker.github.io:v17.06 ${TARGET} ${TARGET}
COPY --from=docs/docker.github.io:v17.09 ${TARGET} ${TARGET}
COPY --from=docs/docker.github.io:v17.12 ${TARGET} ${TARGET}
COPY --from=docs/docker.github.io:v18.03 ${TARGET} ${TARGET}
COPY --from=docs/docker.github.io:v18.09 ${TARGET} ${TARGET}
# Empty stage if archives are disabled (ENABLE_ARCHIVES=false)
FROM scratch AS archives-false
# Stage with static HTML for all archives (ENABLE_ARCHIVES=true)
FROM scratch AS archives-true
ENV TARGET=/usr/share/nginx/html
# To add a new archive, add it here and ALSO edit _data/docsarchive/archives.yaml
# to add it to the drop-down
COPY --from=docs/docker.github.io:v17.03 ${TARGET} /
COPY --from=docs/docker.github.io:v17.06 ${TARGET} /
COPY --from=docs/docker.github.io:v17.09 ${TARGET} /
COPY --from=docs/docker.github.io:v17.12 ${TARGET} /
COPY --from=docs/docker.github.io:v18.03 ${TARGET} /
COPY --from=docs/docker.github.io:v18.09 ${TARGET} /
# Stage either with, or without archives, depending on ENABLE_ARCHIVES
FROM archives-${ENABLE_ARCHIVES} AS archives
# Fetch upstream resources (reference documentation)
# Only add the files that are needed to build these reference docs, so that
@ -74,20 +82,37 @@ COPY ./_data/toc.yaml ./_data/
RUN bash ./_scripts/fetch-upstream-resources.sh .
# Build the current docs from the checked out branch
# Build the static HTML for the current docs.
# After building with jekyll, fix up some links, but don't touch the archives
FROM builderbase AS current
COPY . .
COPY --from=upstream-resources /usr/src/app/md_source/. ./
# Build the static HTML, now that everything is in place
RUN jekyll build -d ${TARGET}
# Fix up some links, don't touch the archives
RUN find ${TARGET} -type f -name '*.html' | grep -vE "v[0-9]+\." | while read i; do sed -i 's#href="https://docs.docker.com/#href="/#g' "$i"; done
# Docs with archives (for deploy)
FROM archives AS deploy
# This stage only contains the generated files. It can be used to host the
# documentation on a non-containerised service (e.g. to deploy to an s3 bucket).
# When using BuildKit, use the '--output' option to build the files and to copy
# them to your local filesystem.
#
# To build current docs, including archives:
# DOCKER_BUILDKIT=1 docker build --target=deploy-source --output=./_site .
#
# To build without archives:
# DOCKER_BUILDKIT=1 docker build --target=deploy-source --build-arg ENABLE_ARCHIVES=false --output=./_site .
FROM archives AS deploy-source
COPY --from=current /usr/share/nginx/html /
# Add the current version of the docs
COPY --from=current ${TARGET} ${TARGET}
# Final stage, which includes nginx, and, depending on ENABLE_ARCHIVES, either
# current docs and archived versions (ENABLE_ARCHIVES=true), or only the current
# docs (ENABLE_ARCHIVES=false).
#
# To build current docs, including archives:
# DOCKER_BUILDKIT=1 docker build -t docs .
#
# To build without archives:
# DOCKER_BUILDKIT=1 docker build -t docs --build-arg ENABLE_ARCHIVES=false .
FROM deploybase AS deploy
WORKDIR $TARGET
COPY --from=deploy-source / .