Skip to content

Commit 6051302

Browse files
author
Misty Stanley-Jones
authored
Use multistage build for master (docker#5369)
1 parent 5428939 commit 6051302

File tree

6 files changed

+206
-70
lines changed

6 files changed

+206
-70
lines changed

Dockerfile

+73-21
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,87 @@
1-
FROM docs/docker.github.io:docs-base
1+
# This Dockerfile builds the docs for https://docs.docker.com/
2+
# from the master branch of https://github.com/docker/docker.github.io
3+
#
4+
# Here is the sequence:
5+
# 1. Set up the build
6+
# 2. Fetch upstream resources
7+
# 3. Build master
8+
# 4. Copy static HTML from already-built archive images
9+
# 5. Copy Nginx config
10+
#
11+
# When the image is run, it starts Nginx and serves the docs at port 4000
212

3-
# docs-base contains: GitHub Pages, nginx, wget, svn, and the docs archives,
4-
# running on Alpine. See the contents of docs-base at:
5-
# https://github.com/docker/docker.github.io/tree/docs-base
13+
# Get basic configs and Jekyll env
14+
FROM docs/docker.github.io:docs-builder AS builder
615

7-
# First, build non-edge (all of this is duplicated later -- that is on purpose)
16+
# Set the target again
17+
ENV TARGET=/usr/share/nginx/html
818

9-
# Copy master into target directory (skipping files / folders in .dockerignore)
10-
# These files represent the current docs
11-
COPY . md_source
19+
# Set the source directory to md_source
20+
ENV SOURCE=md_source
1221

13-
# Move built html into md_source directory so we can reuse the target directory
14-
# to hold the static output.
15-
# Pull reference docs from upstream locations, then build the master docs
16-
# into static HTML in the "target" directory using Jekyll
17-
# then nuke the md_source directory.
22+
# Get the current docs from the checked out branch
23+
# ${SOURCE} will contain a directory for each archive
24+
COPY . ${SOURCE}
1825

26+
####### START UPSTREAM RESOURCES ########
27+
# Set vars used by fetch-upstream-resources.sh script
1928
## Branch to pull from, per ref doc
2029
## To get master from svn the svn branch needs to be 'trunk'. To get a branch from svn it needs to be 'branches/branchname'
2130

2231
# Engine
23-
ENV ENGINE_SVN_BRANCH="branches/17.06.x"
24-
ENV ENGINE_BRANCH="17.06.x"
32+
ENV ENGINE_SVN_BRANCH="branches/17.09.x"
33+
ENV ENGINE_BRANCH="17.09.x"
2534

2635
# Distribution
2736
ENV DISTRIBUTION_SVN_BRANCH="branches/release/2.6"
2837
ENV DISTRIBUTION_BRANCH="release/2.6"
2938

30-
RUN /sbin/apk --update add bash \
31-
&& bash ./md_source/_scripts/fetch-upstream-resources.sh \
32-
&& jekyll build -s md_source -d target --config md_source/_config.yml \
33-
&& rm -rf target/apidocs/layouts \
34-
&& find target -type f -name '*.html' -print0 | xargs -0 sed -i 's#href="https://docs.docker.com/#href="/#g' \
35-
&& rm -rf md_source
39+
# Fetch upstream resources
40+
RUN bash ./${SOURCE}/_scripts/fetch-upstream-resources.sh ${SOURCE}
41+
####### END UPSTREAM RESOURCES ########
42+
43+
44+
# Build the static HTML, now that everything is in place
45+
46+
RUN jekyll build -s ${SOURCE} -d ${TARGET} --config ${SOURCE}/_config.yml
47+
48+
# Fix up some links, don't touch the archives
49+
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
50+
51+
# BUILD OF MASTER DOCS IS NOW DONE!
52+
# Reset to alpine so we don't get any docs source or extra apps
53+
FROM nginx:alpine
54+
55+
# Set the target again
56+
ENV TARGET=/usr/share/nginx/html
57+
58+
# Get the built docs output from the previous step
59+
COPY --from=builder ${TARGET} ${TARGET}
60+
61+
# Get all the archive static HTML and put it into place
62+
# To add a new archive, add it here
63+
# AND ALSO edit _data/docsarchives/archives.yaml to add it to the drop-down
64+
COPY --from=docs/docker.github.io:v1.4 ${TARGET} ${TARGET}
65+
COPY --from=docs/docker.github.io:v1.5 ${TARGET} ${TARGET}
66+
COPY --from=docs/docker.github.io:v1.6 ${TARGET} ${TARGET}
67+
COPY --from=docs/docker.github.io:v1.7 ${TARGET} ${TARGET}
68+
COPY --from=docs/docker.github.io:v1.8 ${TARGET} ${TARGET}
69+
COPY --from=docs/docker.github.io:v1.9 ${TARGET} ${TARGET}
70+
COPY --from=docs/docker.github.io:v1.10 ${TARGET} ${TARGET}
71+
COPY --from=docs/docker.github.io:v1.11 ${TARGET} ${TARGET}
72+
COPY --from=docs/docker.github.io:v1.12 ${TARGET} ${TARGET}
73+
COPY --from=docs/docker.github.io:v1.13 ${TARGET} ${TARGET}
74+
COPY --from=docs/docker.github.io:v17.03 ${TARGET} ${TARGET}
75+
COPY --from=docs/docker.github.io:v17.06 ${TARGET} ${TARGET}
76+
77+
# The archives are self-browseable and each come with an index.html. This creates
78+
# a conflict with the index.html and 404.html from the master build. The easiest
79+
# solution is to just overwrite them again here.
80+
COPY --from=builder ${TARGET}/index.html ${TARGET}/index.html
81+
COPY --from=builder ${TARGET}/404.html ${TARGET}/404.html
82+
83+
# Get the nginx config from the nginx-onbuild image
84+
COPY --from=docs/docker.github.io:nginx-onbuild /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf
85+
86+
# Serve the site (target), which is now all static HTML
87+
CMD echo -e "Docker docs are viewable at:\nhttp://0.0.0.0:4000"; exec nginx -g 'daemon off;'

Dockerfile.archive

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Set to the version for this archive
2+
ARG VER=vXX
3+
4+
# This image comes from the Dockerfile.onbuild file in the docs-builder branch
5+
# https://github.com/docker/docker.github.io/blob/docs-builder/Dockerfile.onbuild
6+
FROM docs/docker.github.io:docs-builder-onbuild AS builder
7+
8+
# Reset the docs:onbuild image, which is based on nginx:alpine
9+
# This image comes from the Dockerfile in the nginx-onbuild branch
10+
# https://github.com/docker/docker.github.io/blob/nginx-onbuild/Dockerfile
11+
FROM docs/docker.github.io:nginx-onbuild

README.md

+78-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ To read the docs offline, you can use either a standalone container or a swarm s
175175
To see all available tags, go to
176176
[Docker Cloud](https://cloud.docker.com/app/docs/repository/docker/docs/docker.github.io/tags).
177177
The following examples use the `latest` tag:
178-
178+
179179
- Run a single container:
180180
181181
```bash
@@ -278,6 +278,83 @@ Bootstrap JS are loaded.
278278
279279
> **Note**: In general, this is a bad idea.
280280
281+
## Building archives and the live published docs
282+
283+
All the images described below are automatically built using Docker Cloud. To
284+
build the site manually, from scratch, including all utility and archive
285+
images, see the [README in the publish-tools branch](https://github.com/docker/docker.github.io/blob/publish-tools/README.md).
286+
287+
- Some utility images are built from Dockerfiles in the `publish-tools` branch.
288+
See its [README](https://github.com/docker/docker.github.io/blob/publish-tools/README.md)
289+
for details.
290+
- Each archive branch automatically builds an image tagged
291+
`docs/docker.github.io:v<VERSION>` when a change is merged into that branch.
292+
- The `master` branch has a Dockerfile which uses the static HTML from each
293+
archive image, in combination with the Markdown
294+
files in `master` and some upstream resources which are fetched at build-time,
295+
to create the full site at https://docs.docker.com/. All
296+
of the long-running branches, such as `vnext-engine`, `vnext-compose`, etc,
297+
use the same logic.
298+
299+
## Creating a new archive
300+
301+
When a new Docker CE Stable version is released, the previous state of `master`
302+
is archived into a version-specific branch like `v17.09`, by doing the following:
303+
304+
1. Create branch based off the commit hash before the new version was released.
305+
306+
```bash
307+
$ git checkout <HASH>
308+
$ git checkout -b v17.09
309+
```
310+
311+
2. Run the `_scripts/fetch-upstream-resources.sh` script. This puts static
312+
copies of the files in place that the `master` build typically fetches
313+
each build.
314+
315+
```bash
316+
$ _scripts/fetch-upstream/resources.sh
317+
```
318+
319+
3. Overwrite the `Dockerfile` with the `Dockerfile.archive` (use `cp` rather
320+
than `mv` so you don't inadvertently remove either file). Edit the resulting
321+
`Dockerfile` and set the `VER` build argument to the appropriate value, like
322+
`v17.09`.
323+
324+
```bash
325+
$ mv Dockerfile.archive Dockerfile
326+
$ vi Dockerfile
327+
328+
< edit the variable and save >
329+
```
330+
331+
4. Do `git status` and add all changes, being careful not to add anything extra
332+
by accident. Commit your work.
333+
334+
```bash
335+
$ git status
336+
$ git add <filename>
337+
$ git add <filename> (etc etc etc)
338+
$ git commit -m "Creating archive for 17.09 docs"
339+
```
340+
341+
5. Make sure the archive builds.
342+
343+
```bash
344+
$ docker build -t docker build -t docker.github.io/docs:v17.09 .
345+
$ docker run --rm -it -p 4000:4000 docker.github.io/docs:v17.09
346+
```
347+
348+
After the `docker run` command, browse to `http://localhost:4000/` and
349+
verify that the archive is self-browseable.
350+
351+
6. Push the branch to the upstream repository. Do not create a pull request
352+
as there is no reference branch to compare against.
353+
354+
```bash
355+
$ git push upstream v17.09
356+
```
357+
281358
## Copyright and license
282359

283360
Code and documentation copyright 2017 Docker, inc, released under the Apache 2.0 license.

_config.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ permalink: pretty
1111
safe: false
1212
lsi: false
1313
url: https://docs.docker.com
14+
# This needs to have all the directories you expect to be in the archives (delivered by docs-base in the Dockerfile)
1415
keep_files: ["v1.4", "v1.5", "v1.6", "v1.7", "v1.8", "v1.9", "v1.10", "v1.11", "v1.12", "v1.13", "v17.03", "v17.06"]
16+
exclude: ["_scripts", "apidocs/layouts", "Gemfile", "hooks"]
1517

1618
# Component versions -- address like site.docker_ce_stable_version
1719
# You can't have - characters in these for non-YAML reasons
1820

1921
docker_ce_stable_version: "17.09"
20-
latest_stable_docker_engine_api_version: "1.32"
22+
latest_stable_docker_engine_api_version: "1.33"
2123
docker_ce_edge_version: "17.11"
2224
docker_ee_version: "17.06"
2325
compose_version: "1.18.0"

0 commit comments

Comments
 (0)