mirror of https://github.com/docker/docs.git
dockerfile: enhanced to match netlify pipeline
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
This commit is contained in:
parent
1e1fdfce1c
commit
ebd36f7081
149
Dockerfile
149
Dockerfile
|
@ -1,58 +1,55 @@
|
||||||
|
# syntax=docker/dockerfile:1
|
||||||
|
|
||||||
# This Dockerfile builds the docs for https://docs.docker.com/
|
# This Dockerfile builds the docs for https://docs.docker.com/
|
||||||
# from the master branch of https://github.com/docker/docker.github.io
|
# from the master branch of https://github.com/docker/docker.github.io
|
||||||
#
|
|
||||||
# Here is the sequence:
|
|
||||||
# 1. Set up base stages for building and deploying
|
|
||||||
# 2. Collect and build the reference documentation (from upstream resources)
|
|
||||||
# 3. Build static HTML from the current branch
|
|
||||||
# 4. Build the final image, combining the reference docs and current version
|
|
||||||
# of the documentation
|
|
||||||
#
|
|
||||||
# When the image is run, it starts Nginx and serves the docs at port 4000
|
|
||||||
|
|
||||||
# Jekyll environment (development/production)
|
# Use same ruby version as the one in .ruby-version
|
||||||
|
# that is used by Netlify
|
||||||
|
ARG RUBY_VERSION=2.6.10
|
||||||
|
# Same as the one in Gemfile.lock
|
||||||
|
ARG BUNDLER_VERSION=2.3.13
|
||||||
|
|
||||||
ARG JEKYLL_ENV=development
|
ARG JEKYLL_ENV=development
|
||||||
|
ARG DOMAIN=docs.docker.com
|
||||||
|
|
||||||
# Engine
|
|
||||||
ARG ENGINE_BRANCH="20.10"
|
ARG ENGINE_BRANCH="20.10"
|
||||||
|
|
||||||
# Distribution
|
|
||||||
ARG DISTRIBUTION_BRANCH="release/2.7"
|
ARG DISTRIBUTION_BRANCH="release/2.7"
|
||||||
|
|
||||||
# Compose CLI
|
|
||||||
ARG COMPOSE_CLI_BRANCH="main"
|
ARG COMPOSE_CLI_BRANCH="main"
|
||||||
|
|
||||||
# extensions SDK
|
|
||||||
ARG EXTENSIONS_SDK_BRANCH="main"
|
ARG EXTENSIONS_SDK_BRANCH="main"
|
||||||
|
|
||||||
###
|
# Base stage for building
|
||||||
# Set up base stages for building and deploying
|
FROM ruby:${RUBY_VERSION}-alpine AS base
|
||||||
###
|
WORKDIR /src
|
||||||
FROM starefossen/github-pages:198 AS builderbase
|
RUN apk add --no-cache bash build-base git subversion wget
|
||||||
ENV TARGET=/usr/share/nginx/html
|
|
||||||
WORKDIR /usr/src/app/md_source/
|
|
||||||
|
|
||||||
# Set vars used by fetch-upstream-resources.sh script as an environment variable,
|
# Gem stage will install bundler used as dependency manager
|
||||||
# so that they are persisted in the image for use in later stages.
|
# for our dependencies in Gemfile for Jekyll
|
||||||
ARG ENGINE_BRANCH
|
FROM base AS gem
|
||||||
ENV ENGINE_BRANCH=${ENGINE_BRANCH}
|
ARG BUNDLER_VERSION
|
||||||
|
COPY Gemfile* .
|
||||||
|
RUN gem uninstall -aIx bundler \
|
||||||
|
&& gem install bundler -v ${BUNDLER_VERSION} \
|
||||||
|
&& bundle install --jobs 4 --retry 3
|
||||||
|
|
||||||
ARG DISTRIBUTION_BRANCH
|
# Vendor Gemfile for Jekyll
|
||||||
ENV DISTRIBUTION_BRANCH=${DISTRIBUTION_BRANCH}
|
FROM gem AS vendored
|
||||||
|
ARG BUNDLER_VERSION
|
||||||
|
RUN bundle update \
|
||||||
|
&& mkdir /out \
|
||||||
|
&& cp Gemfile.lock /out
|
||||||
|
|
||||||
ARG COMPOSE_CLI_BRANCH
|
# Stage used to output the vendored Gemfile.lock:
|
||||||
ENV COMPOSE_CLI_BRANCH=${COMPOSE_CLI_BRANCH}
|
# > make vendor
|
||||||
|
# or
|
||||||
ARG EXTENSIONS_SDK_BRANCH
|
# > docker buildx bake vendor
|
||||||
ENV EXTENSIONS_SDK_BRANCH=${EXTENSIONS_SDK_BRANCH}
|
FROM scratch AS vendor
|
||||||
|
COPY --from=vendored /out /
|
||||||
|
|
||||||
# Fetch upstream resources (reference documentation)
|
# Fetch upstream resources (reference documentation)
|
||||||
# Only add the files that are needed to build these reference docs, so that these
|
# Only add the files that are needed to build these reference docs, so that these
|
||||||
# docs are only rebuilt if changes were made to ENGINE_BRANCH or DISTRIBUTION_BRANCH.
|
# docs are only rebuilt if changes were made to ENGINE_BRANCH or DISTRIBUTION_BRANCH.
|
||||||
# Disable caching (docker build --no-cache) to force updating these docs.
|
FROM base AS upstream-resources
|
||||||
FROM alpine AS upstream-resources
|
WORKDIR /out
|
||||||
RUN apk add --no-cache subversion wget
|
|
||||||
WORKDIR /usr/src/app/md_source/
|
|
||||||
COPY ./_scripts/fetch-upstream-resources.sh ./_scripts/
|
COPY ./_scripts/fetch-upstream-resources.sh ./_scripts/
|
||||||
ARG ENGINE_BRANCH
|
ARG ENGINE_BRANCH
|
||||||
ARG DISTRIBUTION_BRANCH
|
ARG DISTRIBUTION_BRANCH
|
||||||
|
@ -60,49 +57,59 @@ ARG COMPOSE_CLI_BRANCH
|
||||||
ARG EXTENSIONS_SDK_BRANCH
|
ARG EXTENSIONS_SDK_BRANCH
|
||||||
RUN ./_scripts/fetch-upstream-resources.sh .
|
RUN ./_scripts/fetch-upstream-resources.sh .
|
||||||
|
|
||||||
|
|
||||||
# Build the static HTML for the current docs.
|
# Build the static HTML for the current docs.
|
||||||
# After building with jekyll, fix up some links
|
# After building with jekyll, fix up some links
|
||||||
FROM builderbase AS current
|
FROM gem AS generate
|
||||||
|
ARG JEKYLL_ENV
|
||||||
|
ARG DOMAIN
|
||||||
|
ENV TARGET=/out
|
||||||
COPY . .
|
COPY . .
|
||||||
COPY --from=upstream-resources /usr/src/app/md_source/. ./
|
COPY --from=upstream-resources /out .
|
||||||
|
RUN --mount=type=cache,target=/src/.jekyll-cache <<EOT
|
||||||
|
set -eu
|
||||||
|
|
||||||
# substitute the "{site.latest_engine_api_version}" in the title for the latest
|
# substitute the "{site.latest_engine_api_version}" in the title for the latest
|
||||||
# API docs, based on the latest_engine_api_version parameter in _config.yml
|
# API docs, based on the latest_engine_api_version parameter in _config.yml
|
||||||
RUN ./_scripts/update-api-toc.sh
|
(set -x ; ./_scripts/update-api-toc.sh)
|
||||||
ARG JEKYLL_ENV
|
|
||||||
RUN echo "Building docs for ${JEKYLL_ENV} environment"
|
|
||||||
RUN set -eu; \
|
|
||||||
if [ "${JEKYLL_ENV}" = "production" ]; then \
|
|
||||||
jekyll build --profile -d ${TARGET} --config _config.yml,_config_production.yml; \
|
|
||||||
sed -i 's#<loc>/#<loc>https://docs.docker.com/#' "${TARGET}/sitemap.xml"; \
|
|
||||||
else \
|
|
||||||
jekyll build --profile -d ${TARGET}; \
|
|
||||||
echo '[]' > ${TARGET}/js/metadata.json; \
|
|
||||||
fi; \
|
|
||||||
find ${TARGET} -type f -name '*.html' | while read i; do sed -i 's#\(<a[^>]* href="\)https://docs.docker.com/#\1/#g' "$i"; done;
|
|
||||||
|
|
||||||
|
if [ "${JEKYLL_ENV}" = "production" ]; then
|
||||||
|
(
|
||||||
|
set -x
|
||||||
|
bundle exec jekyll build --profile -d ${TARGET} --config _config.yml,_config_production.yml
|
||||||
|
sed -i 's#<loc>/#<loc>https://${DOMAIN}/#' "${TARGET}/sitemap.xml"
|
||||||
|
)
|
||||||
|
else
|
||||||
|
(
|
||||||
|
set -x
|
||||||
|
bundle exec jekyll build --trace --profile -d ${TARGET}
|
||||||
|
mkdir -p ${TARGET}/js
|
||||||
|
echo '[]' > ${TARGET}/js/metadata.json
|
||||||
|
)
|
||||||
|
fi
|
||||||
|
|
||||||
# This stage only contains the generated files. It can be used to host the
|
find ${TARGET} -type f -name '*.html' | while read i; do
|
||||||
# documentation on a non-containerised service (e.g. to deploy to an s3 bucket).
|
sed -i 's#\(<a[^>]* href="\)https://${DOMAIN}/#\1/#g' "$i"
|
||||||
# When using BuildKit, use the '--output' option to build the files and to copy
|
done
|
||||||
# them to your local filesystem.
|
EOT
|
||||||
#
|
|
||||||
# DOCKER_BUILDKIT=1 docker build --target=deploy-source --output=./_site .
|
|
||||||
FROM scratch AS deploy-source
|
|
||||||
COPY --from=current /usr/share/nginx/html /
|
|
||||||
|
|
||||||
# Final stage, which includes nginx, and the current docs.
|
# Release the generated files in a scratch image
|
||||||
#
|
# Can be output to your host with:
|
||||||
# To build current docs:
|
# > make release
|
||||||
# DOCKER_BUILDKIT=1 docker build -t docs .
|
# or
|
||||||
|
# > docker buildx bake release
|
||||||
|
FROM scratch AS release
|
||||||
|
COPY --from=generate /out /
|
||||||
|
|
||||||
|
# Create a runnable nginx instance with generated HTML files.
|
||||||
|
# When the image is run, it starts Nginx and serves the docs at port 4000:
|
||||||
|
# > make deploy
|
||||||
|
# or
|
||||||
|
# > docker-compose up --build
|
||||||
FROM nginx:alpine AS deploy
|
FROM nginx:alpine AS deploy
|
||||||
ENV TARGET=/usr/share/nginx/html
|
COPY --from=release / /usr/share/nginx/html
|
||||||
WORKDIR $TARGET
|
|
||||||
|
|
||||||
COPY --from=current /usr/share/nginx/html .
|
|
||||||
|
|
||||||
# Configure NGINX
|
|
||||||
COPY _deploy/nginx/default.conf /etc/nginx/conf.d/default.conf
|
COPY _deploy/nginx/default.conf /etc/nginx/conf.d/default.conf
|
||||||
ARG JEKYLL_ENV
|
ARG JEKYLL_ENV
|
||||||
ENV JEKYLL_ENV=${JEKYLL_ENV}
|
ENV JEKYLL_ENV=${JEKYLL_ENV}
|
||||||
CMD echo -e "Docker docs are viewable at:\nhttp://0.0.0.0:4000 (build target: ${JEKYLL_ENV})"; exec nginx -g 'daemon off;'
|
CMD echo -e "Docker docs are viewable at:\nhttp://0.0.0.0:4000 (build target: ${JEKYLL_ENV})"; exec nginx -g 'daemon off;'
|
||||||
|
|
||||||
|
FROM deploy
|
||||||
|
|
16
Makefile
16
Makefile
|
@ -19,3 +19,19 @@ buildx-yaml:
|
||||||
rm -rf ./_data/buildx/*
|
rm -rf ./_data/buildx/*
|
||||||
cp -R "$($@_TMP_OUT)"/out/reference/*.yaml ./_data/buildx/
|
cp -R "$($@_TMP_OUT)"/out/reference/*.yaml ./_data/buildx/
|
||||||
rm -rf $($@_TMP_OUT)/*
|
rm -rf $($@_TMP_OUT)/*
|
||||||
|
|
||||||
|
# Build website and output to _site folder
|
||||||
|
release:
|
||||||
|
rm -rf _site
|
||||||
|
$(BUILDX_CMD) bake release
|
||||||
|
|
||||||
|
# Vendor Gemfile.lock
|
||||||
|
vendor:
|
||||||
|
$(BUILDX_CMD) bake vendor
|
||||||
|
|
||||||
|
# Deploy website and run it through Docker compose
|
||||||
|
# Available in your browser at http://localhost:4000
|
||||||
|
deploy:
|
||||||
|
docker compose up --build
|
||||||
|
|
||||||
|
.PHONY: buildx-yaml release vendor deploy
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
variable "JEKYLL_ENV" {
|
||||||
|
default = "development"
|
||||||
|
}
|
||||||
|
|
||||||
|
group "default" {
|
||||||
|
targets = ["release"]
|
||||||
|
}
|
||||||
|
|
||||||
|
target "release" {
|
||||||
|
target = "release"
|
||||||
|
args = {
|
||||||
|
JEKYLL_ENV = JEKYLL_ENV
|
||||||
|
}
|
||||||
|
no-cache-filter = ["upstream-resources"]
|
||||||
|
output = ["./_site"]
|
||||||
|
}
|
||||||
|
|
||||||
|
target "vendor" {
|
||||||
|
target = "vendor"
|
||||||
|
output = ["."]
|
||||||
|
}
|
Loading…
Reference in New Issue