Skip to content

Docker Image Refresh - #2270

Open
tsengia wants to merge 32 commits into
freeCodeCamp:mainfrom
tsengia:feat/docker-dev
Open

Docker Image Refresh#2270
tsengia wants to merge 32 commits into
freeCodeCamp:mainfrom
tsengia:feat/docker-dev

Conversation

@tsengia

@tsengia tsengia commented Jun 24, 2024

Copy link
Copy Markdown

This PR combines the multiple Dockerfile's in the repo into a single, multi-stage Dockerfile that can be used to build both development and production Docker images.

I've also added a devcontainer.json file that can be used with VS Code to provider a containerized development environment. This PR was originally based off of this PR: #1337

Instead of the Docker image including all the documentation by default, now users are able to select which documentation sections they want to include in their local deployment of DevDocs.
This makes it easier/faster to publish new official Docker images of DevDocs because the image size is much smaller.
All downloaded documentation and compiled assets are stored in Docker volumes instead of being baked into the image.
This also means that new Docker images only need uploaded when code changes, and not when documentation updates.

Finally, this PR adds environment variables that can be used to configure the SSL and origin settings of DevDocs when deployed via Docker container. This helps if deploying DevDocs behind a reverse proxy/load balancer, and when running on Windows via WSL2.

This PR should close:

Once this PR is merged, I would think a new Docker image should be released again, which would close #895 and this PR.

ojeytonwilliams and others added 28 commits November 18, 2020 14:45
Co-authored-by: Simon Legner <Simon.Legner@gmail.com>
Co-authored-by: Simon Legner <Simon.Legner@gmail.com>
@tsengia
tsengia requested a review from a team as a code owner June 24, 2024 01:44
@tsengia

tsengia commented Jun 26, 2024

Copy link
Copy Markdown
Author

Also, aside from this PR, I would be interested in becoming a maintainer for this repo.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR refreshes DevDocs’ containerization story by consolidating Docker build logic into a single multi-stage Dockerfile, adding a VS Code devcontainer setup, and introducing runtime configuration knobs intended to make Docker deployments smaller and more configurable (docs/assets moved to volumes, origin/SSL settings configurable).

Changes:

  • Replaced multiple Dockerfiles with a single multi-stage Dockerfile (dev + runtime targets) and updated ignore rules to keep docs/assets out of build context.
  • Added Docker deployment documentation and a .devcontainer/devcontainer.json for containerized development.
  • Introduced new host/origin configuration plumbing (meta-based config + server-side env vars) and adjusted request handling for same-host doc serving.

Reviewed changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
views/index.erb Adds meta tags intended to provide runtime-configurable docs host/origin to client JS.
README.md Documents Docker-based deployment flow and new environment variables.
lib/app.rb Adds env var toggles for SSL/HSTS, new docs host/origin settings, and a same-host docs send_file fallback.
Dockerfile-alpine Removes the old Alpine Dockerfile in favor of the unified Dockerfile.
Dockerfile Introduces multi-stage (base/dev/runtime) build and runtime volumes for docs/assets.
assets/javascripts/models/doc.js Changes doc asset URL construction to use protocol-relative origins.
assets/javascripts/app/config.js.erb Switches config source to DOM meta tags for docs origin and production host.
.vscode/settings.json Adds workspace spellchecker configuration.
.gitignore Ignores local .env and .bash_history.
.gitattributes Enables text auto-normalization.
.dockerignore Excludes docs/assets/log/tmp/test from Docker build context to keep images smaller.
.devcontainer/devcontainer.json Adds VS Code devcontainer configuration targeting the dev stage image.
Suppressed comments (2)

lib/app.rb:135

  • Same issue as the dev/test block: settings.docs and settings.news are set to lambdas, but the rest of the app treats them as concrete values (hash/array). This will raise errors in production routes and RSS generation.
  configure :production do
    set :docs, -> { parse_docs }
    set :news, -> { parse_news }
  end

assets/javascripts/app/config.js.erb:11

  • Same issue as docs_origin: #production-host-meta is not defined in views/other.erb, so this can throw at runtime on doc pages (and any non-index route that renders other.erb).
  production_host: document.getElementById("production-host-meta").content,

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread lib/app.rb
Comment on lines 127 to 130
configure :development, :test do
set :docs, -> { parse_docs }
set :news, -> { parse_news }
end
Comment thread lib/app.rb
Comment on lines +431 to +434
elsif !request.path.end_with?(".html") && user_has_docs?(doc) && supports_js_redirection?
redirect_via_js(request.path)
elsif settings.docs_host == settings.docs_origin && File.exist?(File.join(settings.public_folder, "docs", request.path.gsub("..","")))
send_file File.join(settings.public_folder, "docs", request.path.gsub("..","")), status: status
app.config = {
db_filename: 'db.json',
default_docs: <%= App.default_docs.to_json %>,
docs_origin: document.getElementById("docs-origin-meta").content,
Comment thread views/index.erb
Comment on lines +24 to +25
<meta id="production-host-meta" content="<%= App.docs_host %>" >
<meta id="docs-origin-meta" content="//<%= App.docs_origin %>" >
Comment on lines +46 to +50
return `//${app.config.docs_origin}${this.fullPath(path)}?${this.mtime}`;
}

dbUrl() {
return `${app.config.docs_origin}/${this.slug}/${app.config.db_filename}?${this.mtime}`;
return `//${app.config.docs_origin}/${this.slug}/${app.config.db_filename}?${this.mtime}`;
Comment thread Dockerfile
Comment on lines +32 to +39
RUN bundle config unset without && \
bundle install && \
apk add --update bash curl && \
curl -LO https://download.docker.com/linux/static/stable/x86_64/docker-26.1.4.tgz && \
tar -xzf docker-26.1.4.tgz && \
mv docker/docker /usr/bin && \
rm -rf docker docker-26.1.4.tgz && \
rm -rf ~/.gem /root/.bundle/cache /usr/local/bundle/cache
Comment thread Dockerfile
Comment on lines +50 to +52
RUN apk del gzip build-base git zlib-dev && \
chown -R $USERNAME:$USERNAME /devdocs && \
rm -rf /tmp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update docker image

3 participants