Skip to content

Set CI_COMMIT_REF_NAME as a string in Docker images

Sarah German requested to merge 1330-archives-banner into main

What does this MR do and why?

Closes #1330 (closed)

Fixes the visibility of the "Archived version" banner for the current stable Docs release (currently this would be 15.9). The banner should not appear in the current stable release, but should appear in all older versions.

The bug

We use this logic when checking if we're running the either the next/latest or current/stable version of the Docs:

def latest?
  ENV['CI_COMMIT_REF_NAME'] == ENV['CI_DEFAULT_BRANCH'] || ENV['CI_COMMIT_REF_NAME'] == get_current_stable_version
end

And our problem is here: ENV['CI_COMMIT_REF_NAME'] == get_current_stable_version

In the regular CI pipeline, CI_COMMIT_REF_NAME is a string (it's the tag or branch name), so it can be properly compared to the result of get_current_stable_version (which reads versions.json, also strings).

However, when we set CI_COMMIT_REF_NAME as an environment variable in the Dockerfile for a cut version, we're assigning it as an integer (not a string) (example from 15.9).

This means latest? will never return true in older versions that get built in Docker since the integer won't ever equal the string.

So, to fix this, we're adjusting the single.Dockerfile template to set CI_COMMIT_REF_NAME as a string rather than an integer.

Screenshots, screen recordings, or links to review app

n/a

How to set up and validate locally

  1. Check out the 15.9 branch and cherry-pick the commit from this MR into it: git cherry-pick 9cd05de3cb10e9514cf29e2e07d64aaf999ee8a3.
  2. Edit lib/tasks/release.rake and comment-out lines 51-57 so we can test a release without actually pushing anything.
  3. If you have the 15.9 branch locally, delete it, as having it exist already will throw errors.
  4. Run the rake task to create a Dockerfile for the release: ./bin/rake "release:single[15.9]"
  5. Look at the resulting 15.9.Dockerfile and verify that line 28 sets the version as a string, like this: ARG VER="15.9"
  6. Build the image with the new dockerfile: docker build --build-arg NANOC_ENV="production" -t docs:15.9 -f 15.9.Dockerfile .
  7. Run the image: docker run -it --rm -p 4000:4000 docs:15.9
  8. Check an interior page on the site for banner visibility (e.g, http://0.0.0.0:4000/15.9/runner/)

Repeat steps 1-7, but for 15.8:

./bin/rake "release:single[15.8]"
docker build --build-arg NANOC_ENV="production" -t docs:15.9 -f 15.9.Dockerfile .
  • The 15.9 site should not show the banner.
  • The 15.8 site should show the banner.

Merge request acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Sarah German

Merge request reports