Skip to content

Commit cec5201

Browse files
authored
Merge pull request docker#11600 from thaJeztah/prod_develop
Separate "development" and "production" configurations
2 parents 296ee4f + 5a1ae83 commit cec5201

File tree

8 files changed

+51
-139
lines changed

8 files changed

+51
-139
lines changed

.github/workflows/build-published.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
run: docker version && docker info
1818
- uses: actions/checkout@v2
1919
- name: build current docs
20-
run: docker build --target=deploy-source --output=./_site .
20+
run: docker build --build-arg JEKYLL_ENV=production --target=deploy-source --output=./_site .
2121
- name: upload files to S3 bucket
2222
run: aws s3 sync --acl public-read _site s3://docs.docker.com-us-east-1/ --delete
2323
env:

Dockerfile

+15-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#
1111
# When the image is run, it starts Nginx and serves the docs at port 4000
1212

13+
# Jekyll environment (development/production)
14+
ARG JEKYLL_ENV=development
1315

1416
# Engine
1517
ARG ENGINE_BRANCH="19.03"
@@ -53,9 +55,16 @@ COPY --from=upstream-resources /usr/src/app/md_source/. ./
5355
# substitute the "{site.latest_engine_api_version}" in the title for the latest
5456
# API docs, based on the latest_engine_api_version parameter in _config.yml
5557
RUN ./_scripts/update-api-toc.sh
56-
RUN jekyll build -d ${TARGET} \
57-
&& find ${TARGET} -type f -name '*.html' | while read i; do sed -i 's#\(<a[^>]* href="\)https://docs.docker.com/#\1/#g' "$i"; done \
58-
&& sed -i 's#<loc>/#<loc>https://docs.docker.com/#' "${TARGET}/sitemap.xml"
58+
ARG JEKYLL_ENV
59+
RUN echo "Building docs for ${JEKYLL_ENV} environment"
60+
RUN set -eux; \
61+
if [ "${JEKYLL_ENV}" = "production" ]; then \
62+
jekyll build -d ${TARGET} --config _config.yml,_config_production.yml; \
63+
else \
64+
jekyll build -d ${TARGET}; \
65+
fi; \
66+
find ${TARGET} -type f -name '*.html' | while read i; do sed -i 's#\(<a[^>]* href="\)https://docs.docker.com/#\1/#g' "$i"; done; \
67+
sed -i 's#<loc>/#<loc>https://docs.docker.com/#' "${TARGET}/sitemap.xml";
5968

6069

6170
# This stage only contains the generated files. It can be used to host the
@@ -79,4 +88,6 @@ COPY --from=current /usr/share/nginx/html .
7988

8089
# Configure NGINX
8190
COPY _deploy/nginx/default.conf /etc/nginx/conf.d/default.conf
82-
CMD echo -e "Docker docs are viewable at:\nhttp://0.0.0.0:4000"; exec nginx -g 'daemon off;'
91+
ARG JEKYLL_ENV
92+
ENV JEKYLL_ENV=${JEKYLL_ENV}
93+
CMD echo -e "Docker docs are viewable at:\nhttp://0.0.0.0:4000 (build target: ${JEKYLL_ENV})"; exec nginx -g 'daemon off;'

_config.yml

+3-9
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,7 @@ incremental: true
1111
permalink: pretty
1212
safe: false
1313
lsi: false
14-
exclude: ["_scripts", "tests", "apidocs/layouts", "Gemfile", "hooks", "index.html", "404.html"]
15-
16-
# Google Analytics, etc.
17-
# TODO these should only be set when building for production, or passed as an environment variable when building
18-
google_analytics: GTM-WL2QLG5
19-
polldaddy_id: 8453675
20-
14+
exclude: ["_samples", "_scripts", "404.html", "datacenter", "ee", "index.html"]
2115

2216
# Component versions -- address like site.docker_ce_version
2317
# You can't have - characters in these for non-YAML reasons
@@ -121,5 +115,5 @@ defaults:
121115
#
122116
# We specify the directory for Jekyll so we can use @imports.
123117
sass:
124-
sass_dir: _scss
125-
style: :compressed
118+
sass_dir: _scss
119+
style: expanded

_config_authoring.yml

-122
This file was deleted.

_config_production.yml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
# Include files that are excluded in "development" ("enterprise" stubs) for production
3+
exclude: ["_scripts", "404.html", "index.html"]
4+
5+
# Google Analytics, etc.
6+
google_analytics: GTM-WL2QLG5
7+
polldaddy_id: 8453675
8+
9+
# Assets
10+
sass:
11+
style: compressed

_includes/body.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,5 @@ <h1>{{ page.title }}</h1>
7373
{% include footer.html %}
7474
</footer>
7575
<script>const pageURL = "{{ page.url }}";</script>
76-
{%- include analytics/polldaddy.html -%}
76+
{%- if jekyll.environment == 'production' -%}{%- include analytics/polldaddy.html -%}{%- endif -%}
7777
</body>

_includes/head.html

+6-2
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,20 @@
2424
{%- assign page_description = content | strip_html | strip | truncatewords: 30 -%}
2525
{%- endif -%}
2626
{%- endif -%}
27+
{%- assign domain_name = 'https://docs.docker.com' -%}
28+
{%- if jekyll.environment == 'development' -%}
29+
{%- assign domain_name = 'https://localhost:4000' -%}
30+
{%- endif -%}
2731
<head>
2832
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
2933
{%- if page.sitemap == false or site.GH_ENV == "gh_pages" %}
3034
<meta name="robots" content="noindex"/>
3135
{%- endif %}
32-
{%- if site.google_analytics != '' -%}{%- include analytics/google_analytics.html GOOGLE_ID=site.google_analytics -%}{%- endif -%}
36+
{%- if jekyll.environment == 'production' and site.google_analytics != '' -%}{%- include analytics/google_analytics.html GOOGLE_ID=site.google_analytics -%}{%- endif -%}
3337
<title>{{ page.title | default: page_title }} | Docker Documentation</title>
3438
<meta name="description" content="{{ page.description | default: page_description | escape}}" />
3539
<meta name="keywords" content="{{ page.keywords | default: 'docker, docker open source, docker platform, distributed applications, microservices, containers, docker containers, docker software, docker virtualization' }}">
36-
<link rel="canonical" href="https://docs.docker.com{{ page.url }}" />
40+
<link rel="canonical" href="{{ domain_name }}{{ page.url }}" />
3741

3842
<!-- favicon -->
3943
<link rel="icon" type="image/x-icon" href="/favicons/[email protected]" sizes="129x128">

docker-compose.yml

+14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
version: "3.7"
22
services:
33
docs:
4+
# By default, docker-compose up --build builds docs for a development
5+
# environment (no Google Analytics, omitting some enterprise redirects,
6+
# etc.
7+
#
8+
# To test a "production" build, override the environment using:
9+
#
10+
# JEKYLL_ENV=production docker-compose up --build
411
build:
12+
args:
13+
# FIXME: docker-compose should behave the same as the docker CLI here
14+
# and if `JEKYLL_ENV` is not set in the current environment, ignore
15+
# the --build-arg, and use the default that's defined in the Dockerfile.
16+
# Setting a default here as a workaround.
17+
# - JEKYLL_ENV
18+
- JEKYLL_ENV=${JEKYLL_ENV:-development}
519
context: .
620
image: docs/docstage
721
ports:

0 commit comments

Comments
 (0)