forked from docker/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use multistage build for master (docker#5369)
- Loading branch information
Misty Stanley-Jones
authored
Dec 27, 2017
1 parent
5428939
commit 6051302
Showing
6 changed files
with
206 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,87 @@ | ||
FROM docs/docker.github.io:docs-base | ||
# This Dockerfile builds the docs for https://docs.docker.com/ | ||
# from the master branch of https://github.com/docker/docker.github.io | ||
# | ||
# Here is the sequence: | ||
# 1. Set up the build | ||
# 2. Fetch upstream resources | ||
# 3. Build master | ||
# 4. Copy static HTML from already-built archive images | ||
# 5. Copy Nginx config | ||
# | ||
# When the image is run, it starts Nginx and serves the docs at port 4000 | ||
|
||
# docs-base contains: GitHub Pages, nginx, wget, svn, and the docs archives, | ||
# running on Alpine. See the contents of docs-base at: | ||
# https://github.com/docker/docker.github.io/tree/docs-base | ||
# Get basic configs and Jekyll env | ||
FROM docs/docker.github.io:docs-builder AS builder | ||
|
||
# First, build non-edge (all of this is duplicated later -- that is on purpose) | ||
# Set the target again | ||
ENV TARGET=/usr/share/nginx/html | ||
|
||
# Copy master into target directory (skipping files / folders in .dockerignore) | ||
# These files represent the current docs | ||
COPY . md_source | ||
# Set the source directory to md_source | ||
ENV SOURCE=md_source | ||
|
||
# Move built html into md_source directory so we can reuse the target directory | ||
# to hold the static output. | ||
# Pull reference docs from upstream locations, then build the master docs | ||
# into static HTML in the "target" directory using Jekyll | ||
# then nuke the md_source directory. | ||
# Get the current docs from the checked out branch | ||
# ${SOURCE} will contain a directory for each archive | ||
COPY . ${SOURCE} | ||
|
||
####### START UPSTREAM RESOURCES ######## | ||
# Set vars used by fetch-upstream-resources.sh script | ||
## Branch to pull from, per ref doc | ||
## To get master from svn the svn branch needs to be 'trunk'. To get a branch from svn it needs to be 'branches/branchname' | ||
|
||
# Engine | ||
ENV ENGINE_SVN_BRANCH="branches/17.06.x" | ||
ENV ENGINE_BRANCH="17.06.x" | ||
ENV ENGINE_SVN_BRANCH="branches/17.09.x" | ||
ENV ENGINE_BRANCH="17.09.x" | ||
|
||
# Distribution | ||
ENV DISTRIBUTION_SVN_BRANCH="branches/release/2.6" | ||
ENV DISTRIBUTION_BRANCH="release/2.6" | ||
|
||
RUN /sbin/apk --update add bash \ | ||
&& bash ./md_source/_scripts/fetch-upstream-resources.sh \ | ||
&& jekyll build -s md_source -d target --config md_source/_config.yml \ | ||
&& rm -rf target/apidocs/layouts \ | ||
&& find target -type f -name '*.html' -print0 | xargs -0 sed -i 's#href="https://docs.docker.com/#href="/#g' \ | ||
&& rm -rf md_source | ||
# Fetch upstream resources | ||
RUN bash ./${SOURCE}/_scripts/fetch-upstream-resources.sh ${SOURCE} | ||
####### END UPSTREAM RESOURCES ######## | ||
|
||
|
||
# Build the static HTML, now that everything is in place | ||
|
||
RUN jekyll build -s ${SOURCE} -d ${TARGET} --config ${SOURCE}/_config.yml | ||
|
||
# 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 | ||
|
||
# BUILD OF MASTER DOCS IS NOW DONE! | ||
# Reset to alpine so we don't get any docs source or extra apps | ||
FROM nginx:alpine | ||
|
||
# Set the target again | ||
ENV TARGET=/usr/share/nginx/html | ||
|
||
# Get the built docs output from the previous step | ||
COPY --from=builder ${TARGET} ${TARGET} | ||
|
||
# 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:v1.4 ${TARGET} ${TARGET} | ||
COPY --from=docs/docker.github.io:v1.5 ${TARGET} ${TARGET} | ||
COPY --from=docs/docker.github.io:v1.6 ${TARGET} ${TARGET} | ||
COPY --from=docs/docker.github.io:v1.7 ${TARGET} ${TARGET} | ||
COPY --from=docs/docker.github.io:v1.8 ${TARGET} ${TARGET} | ||
COPY --from=docs/docker.github.io:v1.9 ${TARGET} ${TARGET} | ||
COPY --from=docs/docker.github.io:v1.10 ${TARGET} ${TARGET} | ||
COPY --from=docs/docker.github.io:v1.11 ${TARGET} ${TARGET} | ||
COPY --from=docs/docker.github.io:v1.12 ${TARGET} ${TARGET} | ||
COPY --from=docs/docker.github.io:v1.13 ${TARGET} ${TARGET} | ||
COPY --from=docs/docker.github.io:v17.03 ${TARGET} ${TARGET} | ||
COPY --from=docs/docker.github.io:v17.06 ${TARGET} ${TARGET} | ||
|
||
# The archives are self-browseable and each come with an index.html. This creates | ||
# a conflict with the index.html and 404.html from the master build. The easiest | ||
# solution is to just overwrite them again here. | ||
COPY --from=builder ${TARGET}/index.html ${TARGET}/index.html | ||
COPY --from=builder ${TARGET}/404.html ${TARGET}/404.html | ||
|
||
# Get the nginx config from the nginx-onbuild image | ||
COPY --from=docs/docker.github.io:nginx-onbuild /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf | ||
|
||
# Serve the site (target), which is now all static HTML | ||
CMD echo -e "Docker docs are viewable at:\nhttp://0.0.0.0:4000"; exec nginx -g 'daemon off;' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Set to the version for this archive | ||
ARG VER=vXX | ||
|
||
# This image comes from the Dockerfile.onbuild file in the docs-builder branch | ||
# https://github.com/docker/docker.github.io/blob/docs-builder/Dockerfile.onbuild | ||
FROM docs/docker.github.io:docs-builder-onbuild AS builder | ||
|
||
# Reset the docs:onbuild image, which is based on nginx:alpine | ||
# This image comes from the Dockerfile in the nginx-onbuild branch | ||
# https://github.com/docker/docker.github.io/blob/nginx-onbuild/Dockerfile | ||
FROM docs/docker.github.io:nginx-onbuild |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.