# syntax=docker/dockerfile:1 # This Dockerfile builds the docs for https://docs.docker.com/ # from the master branch of https://github.com/docker/docker.github.io # 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 DOMAIN=docs.docker.com ARG ENGINE_BRANCH="20.10" ARG DISTRIBUTION_BRANCH="release/2.7" ARG COMPOSE_CLI_BRANCH="main" ARG EXTENSIONS_SDK_BRANCH="main" # Base stage for building FROM ruby:${RUBY_VERSION}-alpine AS base WORKDIR /src RUN apk add --no-cache bash build-base git subversion wget # Gem stage will install bundler used as dependency manager # for our dependencies in Gemfile for Jekyll FROM base AS gem ARG BUNDLER_VERSION COPY Gemfile* . RUN gem uninstall -aIx bundler \ && gem install bundler -v ${BUNDLER_VERSION} \ && bundle install --jobs 4 --retry 3 # Vendor Gemfile for Jekyll FROM gem AS vendored ARG BUNDLER_VERSION RUN bundle update \ && mkdir /out \ && cp Gemfile.lock /out # Stage used to output the vendored Gemfile.lock: # > make vendor # or # > docker buildx bake vendor FROM scratch AS vendor COPY --from=vendored /out / # Fetch upstream resources (reference documentation) # 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. FROM base AS upstream-resources WORKDIR /out COPY ./_scripts/fetch-upstream-resources.sh ./_scripts/ ARG ENGINE_BRANCH ARG DISTRIBUTION_BRANCH ARG COMPOSE_CLI_BRANCH ARG EXTENSIONS_SDK_BRANCH RUN ./_scripts/fetch-upstream-resources.sh . # Build the static HTML for the current docs. # After building with jekyll, fix up some links FROM gem AS generate ARG JEKYLL_ENV ARG DOMAIN ENV TARGET=/out COPY . . COPY --from=upstream-resources /out . RUN --mount=type=cache,target=/src/.jekyll-cache </#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 find ${TARGET} -type f -name '*.html' | while read i; do sed -i 's#\(]* href="\)https://${DOMAIN}/#\1/#g' "$i" done EOT # Release the generated files in a scratch image # Can be output to your host with: # > make release # 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 COPY --from=release / /usr/share/nginx/html COPY _deploy/nginx/default.conf /etc/nginx/conf.d/default.conf ARG 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;' FROM deploy