From 92eccec5c55945c449bd50d0307df8160915a060 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Thu, 27 Oct 2022 12:42:01 +0200 Subject: [PATCH 1/4] Dockerfile: add option to enforce git log history for local dev Signed-off-by: CrazyMax --- Dockerfile | 2 ++ _plugins/fetch_remote.rb | 14 ++++++++++---- _plugins/last_modified_at.rb | 15 ++++++++------- docker-bake.hcl | 4 ++++ docker-compose.yml | 1 + 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/Dockerfile b/Dockerfile index 138414522ebd..7a015513e721 100644 --- a/Dockerfile +++ b/Dockerfile @@ -11,6 +11,7 @@ ARG BUNDLER_VERSION=2.3.13 ARG JEKYLL_ENV=development ARG DOCS_URL=http://localhost:4000 +ARG DOCS_ENFORCE_GIT_LOG_HISTORY=0 # Base stage for building FROM ruby:${RUBY_VERSION}-alpine AS base @@ -45,6 +46,7 @@ COPY --from=vendored /out / FROM gem AS generate ARG JEKYLL_ENV ARG DOCS_URL +ARG DOCS_ENFORCE_GIT_LOG_HISTORY ENV TARGET=/out RUN --mount=type=bind,target=.,rw \ --mount=type=cache,target=/tmp/docker-docs-clone \ diff --git a/_plugins/fetch_remote.rb b/_plugins/fetch_remote.rb index ace1149cfd52..afc189037ef3 100644 --- a/_plugins/fetch_remote.rb +++ b/_plugins/fetch_remote.rb @@ -41,7 +41,7 @@ def pre_read(site) beginning_time = Time.now puts "Starting plugin fetch_remote.rb..." - fetch_depth = get_docs_url == "http://localhost:4000" ? 1 : 0 + fetch_depth = get_docs_url == "http://localhost:4000" && ENV['DOCS_ENFORCE_GIT_LOG_HISTORY'] == "0" ? 1 : 0 site.config['fetch-remote'].each do |entry| puts " Repo #{entry['repo']}" @@ -51,10 +51,16 @@ def pre_read(site) puts " Opening #{clonedir}" begin git = Git.open(clonedir) - puts " Fetching #{entry['ref']}" - git.fetch - git.checkout(entry['ref']) + puts " Fetch repository" + if fetch_depth > 0 + git.fetch('origin', prune: true, depth: fetch_depth) + else + git.fetch('origin', prune: true) + end + puts " Checkout #{entry['ref']}" + git.checkout(entry['ref'], force: true) rescue => e + puts " WARNING: #{e}" FileUtils.rm_rf(clonedir) puts " Cloning repository into #{clonedir}" git = Git.clone("#{entry['repo']}.git", Pathname.new(clonedir), branch: entry['ref'], depth: fetch_depth) diff --git a/_plugins/last_modified_at.rb b/_plugins/last_modified_at.rb index 09bddfd1d945..0ab6119cc207 100644 --- a/_plugins/last_modified_at.rb +++ b/_plugins/last_modified_at.rb @@ -6,26 +6,27 @@ module Jekyll class LastModifiedAt < Octopress::Hooks::Site DATE_FORMAT = '%Y-%m-%d %H:%M:%S %z' def pre_render(site) - if get_docs_url == "http://localhost:4000" - # Do not generate last_modified_at for local development - return - end - beginning_time = Time.now Jekyll.logger.info "Starting plugin last_modified_at.rb..." git = Git.open(site.source) + use_file_mtime = get_docs_url == "http://localhost:4000" && ENV['DOCS_ENFORCE_GIT_LOG_HISTORY'] == "0" site.pages.each do |page| next if page.relative_path == "redirect.html" next unless File.extname(page.relative_path) == ".md" || File.extname(page.relative_path) == ".html" unless page.data.key?('last_modified_at') begin - page.data['last_modified_at'] = git.log.path(page.relative_path).first.date.strftime(DATE_FORMAT) + if use_file_mtime + # Use file's mtime for local development + page.data['last_modified_at'] = File.mtime(page.relative_path).strftime(DATE_FORMAT) + else + page.data['last_modified_at'] = git.log.path(page.relative_path).first.date.strftime(DATE_FORMAT) + end rescue => e # Ignored end end - puts" #{page.relative_path}\n last_modified_at: #{page.data['last_modified_at']}" + puts" #{page.relative_path}\n last_modified_at(#{use_file_mtime ? 'mtime': 'git'}): #{page.data['last_modified_at']}" end end_time = Time.now diff --git a/docker-bake.hcl b/docker-bake.hcl index 4f19155b3b73..eb6843bfb3c0 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -7,11 +7,15 @@ variable "DOCS_URL" { variable "DOCS_SITE_DIR" { default = "_site" } +variable "DOCS_ENFORCE_GIT_LOG_HISTORY" { + default = "0" +} target "_common" { args = { JEKYLL_ENV = JEKYLL_ENV DOCS_URL = DOCS_URL + DOCS_ENFORCE_GIT_LOG_HISTORY = DOCS_ENFORCE_GIT_LOG_HISTORY } no-cache-filter = ["generate"] } diff --git a/docker-compose.yml b/docker-compose.yml index 6e9c5f8f5dfe..1cbb82cc3259 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,6 +11,7 @@ services: args: - JEKYLL_ENV - DOCS_URL + - DOCS_ENFORCE_GIT_LOG_HISTORY context: . image: docs/docstage ports: From 3ac076da5485fba4441702d78908245054c339cf Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Thu, 27 Oct 2022 13:20:07 +0200 Subject: [PATCH 2/4] jekyll(last_modified_at): do not override if already set with frontmatter Signed-off-by: CrazyMax --- _plugins/last_modified_at.rb | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/_plugins/last_modified_at.rb b/_plugins/last_modified_at.rb index 0ab6119cc207..85bc3eba8976 100644 --- a/_plugins/last_modified_at.rb +++ b/_plugins/last_modified_at.rb @@ -5,28 +5,45 @@ module Jekyll class LastModifiedAt < Octopress::Hooks::Site DATE_FORMAT = '%Y-%m-%d %H:%M:%S %z' + + def current_last_modified_at(site, page) + if page.data.key?('last_modified_at') + return page.data['last_modified_at'] + end + site.config['defaults'].map do |set| + if set['values'].key?('last_modified_at') && set['scope']['path'].include?(page.relative_path) + return set['values']['last_modified_at'] + end + end.compact + nil + end + def pre_render(site) beginning_time = Time.now Jekyll.logger.info "Starting plugin last_modified_at.rb..." git = Git.open(site.source) use_file_mtime = get_docs_url == "http://localhost:4000" && ENV['DOCS_ENFORCE_GIT_LOG_HISTORY'] == "0" - site.pages.each do |page| + site.pages.sort!{|l,r| l.relative_path <=> r.relative_path }.each do |page| next if page.relative_path == "redirect.html" next unless File.extname(page.relative_path) == ".md" || File.extname(page.relative_path) == ".html" - unless page.data.key?('last_modified_at') + page.data['last_modified_at'] = current_last_modified_at(site, page) + set_mode = "frontmatter" + if page.data['last_modified_at'].nil? begin if use_file_mtime # Use file's mtime for local development page.data['last_modified_at'] = File.mtime(page.relative_path).strftime(DATE_FORMAT) + set_mode = "mtime" else page.data['last_modified_at'] = git.log.path(page.relative_path).first.date.strftime(DATE_FORMAT) + set_mode = "git" end rescue => e # Ignored end end - puts" #{page.relative_path}\n last_modified_at(#{use_file_mtime ? 'mtime': 'git'}): #{page.data['last_modified_at']}" + puts" #{page.relative_path}\n last_modified_at(#{set_mode}): #{page.data['last_modified_at']}" end end_time = Time.now From bafeb72c182e48a4e4cc3399bb13b70dedafa6d8 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Thu, 27 Oct 2022 13:44:07 +0200 Subject: [PATCH 3/4] jekyll(last_modified_at): use data files for commands reference instead of stub file Signed-off-by: CrazyMax --- _plugins/last_modified_at.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/_plugins/last_modified_at.rb b/_plugins/last_modified_at.rb index 85bc3eba8976..765f8d55da08 100644 --- a/_plugins/last_modified_at.rb +++ b/_plugins/last_modified_at.rb @@ -29,21 +29,27 @@ def pre_render(site) next unless File.extname(page.relative_path) == ".md" || File.extname(page.relative_path) == ".html" page.data['last_modified_at'] = current_last_modified_at(site, page) set_mode = "frontmatter" + path_override = "" if page.data['last_modified_at'].nil? + page_relative_path = page.relative_path + if page.data.key?('datafolder') && page.data.key?('datafile') + page_relative_path = File.join('_data', page.data['datafolder'], "#{page.data['datafile']}.yaml") + path_override = "\n override: #{page_relative_path}" + end begin if use_file_mtime # Use file's mtime for local development - page.data['last_modified_at'] = File.mtime(page.relative_path).strftime(DATE_FORMAT) + page.data['last_modified_at'] = File.mtime(page_relative_path).strftime(DATE_FORMAT) set_mode = "mtime" else - page.data['last_modified_at'] = git.log.path(page.relative_path).first.date.strftime(DATE_FORMAT) + page.data['last_modified_at'] = git.log.path(page_relative_path).first.date.strftime(DATE_FORMAT) set_mode = "git" end rescue => e # Ignored end end - puts" #{page.relative_path}\n last_modified_at(#{set_mode}): #{page.data['last_modified_at']}" + puts" #{page.relative_path}#{path_override}\n last_modified_at(#{set_mode}): #{page.data['last_modified_at']}" end end_time = Time.now From a997dc9d316111900c479d59b8b4ccd7020832a1 Mon Sep 17 00:00:00 2001 From: CrazyMax Date: Thu, 27 Oct 2022 14:13:46 +0200 Subject: [PATCH 4/4] fix broken links Signed-off-by: CrazyMax --- subscription/faq.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/subscription/faq.md b/subscription/faq.md index b85069a6bf9d..4eccfff77c99 100644 --- a/subscription/faq.md +++ b/subscription/faq.md @@ -96,7 +96,7 @@ When you downgrade your Pro or Team plan, changes are applied at the end of your ### How do I downgrade from a Team plan to a Free Team plan? -Before you downgrade to a Free plan, ensure that your organization details are updated to reflect features available in the Free plan. For example, you may need to reduce the number of team members and convert any private repositories to public repositories. For information on what’s included in the Free plan, see the [billing](index.md#pricing-plans){:target="blank" rel="noopener" class=""} page. +Before you downgrade to a Free plan, ensure that your organization details are updated to reflect features available in the Free plan. For example, you may need to reduce the number of team members and convert any private repositories to public repositories. For information on what’s included in the Free plan, see the [billing](index.md){:target="blank" rel="noopener" class=""} page. ### How do I downgrade from Pro to a Free plan? @@ -141,8 +141,7 @@ Team starts at $25 per month for the first five users and $7 per month for each ### How will the new pricing plan impact existing Docker Hub customers? Legacy individual and organizational repository customers have until their January 2021 billing cycle to switch to the new pricing plans. -To view the status of your individual repository plan, see [the billing](https:// -hub.docker.com/billing/plan/update){:target="blank" rel="noopener" class=""} page. +To view the status of your individual repository plan, see [the billing](https://hub.docker.com/billing/plan/update){:target="blank" rel="noopener" class=""} page. To view the status of your organizational repository plan, see [Docker Hub Orgs](https://hub.docker.com/orgs){:target="blank" rel="noopener" class=""} page. ### What is the difference between the legacy repository plans and the newly announced plans?