Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support for embedding code snippets #22226

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

mdelapenya
Copy link
Member

Description

This pull request includes changes to the Dockerfile, documentation, and template files to support embedding code snippets from the testcontainers-go repository into the documentation. The most important changes include adding a new build stage to clone the testcontainers-go repository, updating the documentation to include an embedded code snippet, and modifying the shortcode template to handle these embedded snippets.

Dockerfile changes:

  • Added a new build stage git-src-oss to clone the testcontainers-go repository and copy it to the project directory ([DockerfileR36-R45](https://github.com/docker/docs/pull/22226/files#diff-dd2c0eb6ea5cfc6c4bd4eac30934e2d5746747af48fef6da689e85b752f39557R36-R45)).

Documentation changes:

  • Updated content/manuals/testcontainers.md to include an embedded Go code snippet from the testcontainers-go repository ([content/manuals/testcontainers.mdR45-R46](https://github.com/docker/docs/pull/22226/files#diff-7905b168f0bee5db6711b541f42c48f5d0901c8cdc17f323e3c1725a5445a3dcR45-R46)).

IMPORTANT: this change is a demonstration on how to use the embedding shortcode.

Template changes:

  • Created layouts/shortcodes/embedded.html to handle embedded code snippets, including logic to identify and extract specific code sections based on custom tags ([layouts/shortcodes/embedded.htmlR1-R65](https://github.com/docker/docs/pull/22226/files#diff-dc256c151d3b9c325236dc0c38d0ef5155ce617bb93d44b669b7641a00fbe42aR1-R65)).

The tag is using the following format:

  • start tag: // START $id
  • end tag: // END $id

Exception: for testcontainers-go, where this mechanism already exists, we are using different start/end tags:

  • start tag: // $id {
  • end tag: // }

Reviews

  • Technical review
  • Editorial review
  • Product review

@github-actions github-actions bot added hugo Updates related to hugo area/config labels Mar 11, 2025
Copy link

netlify bot commented Mar 11, 2025

Deploy Preview for docsdocker ready!

Name Link
🔨 Latest commit ca0901b
🔍 Latest deploy log https://app.netlify.com/sites/docsdocker/deploys/67d0159f0a5c3c0008fa0c9b
😎 Deploy Preview https://deploy-preview-22226--docsdocker.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@aevesdocker aevesdocker requested a review from a team March 11, 2025 10:56
@@ -42,6 +42,8 @@ Testcontainers provide support for the most popular languages, and Docker sponso

The rest are community-driven and maintained by independent contributors.

{{< embedded language="go" source="/git-src/testcontainers-go/modules/redis/examples_test.go" id="runRedisContainer" >}}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before merging this PR, this line is just an example on how to use it, so it should be removed from here.

Comment on lines +36 to +40
# git-src clones the OSS projects in order to include
# code snippets into the docs.
FROM base AS git-src-oss
WORKDIR /git-src
RUN git clone https://github.com/testcontainers/testcontainers-go.git
Copy link
Member

@crazy-max crazy-max Mar 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should use vendoring through go mod convention of hugo if we need to use external resources like we do for cli reference docs:

Also git clone without pinning to commit sha is not reproducible and can lead to regressions with unrelated changes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, this is a PoC, and during the initial discussion with the Docs team we considered having the code snippets living in the docs repo, so the upstream repo (i.e. tc-go) would have to send a PR to the docs syncing the code snippets. As a result, no git clone would be needed, and the embedded short-code would just read from a local path, ideally next to the docs page using the code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/config hugo Updates related to hugo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants