Docker Deployment
Relevant source files
The following files were used as context for generating this wiki page:The hdrify application is a web service that converts SDR images to HDR. It can be easily deployed and run as a self-contained unit using Docker. This approach encapsulates the application, its dependencies, and its runtime environment, ensuring consistent behavior across different systems. The deployment process involves building a Docker image from the source and then running a container based on that image.
Sources: README.md:3,40
Quick Start with Docker
The primary method for deploying hdrify is via Docker. This simplifies dependency management, particularly for the required ImageMagick library.
Sources: README.md:40-44
Commands
The deployment process consists of two main commands:
| Command | Description |
|---|---|
docker build -t hdrify . | Builds the Docker image from the Dockerfile in the project root and tags it with the name hdrify. |
docker run -p 3000:3000 hdrify | Runs a container from the hdrify image, mapping port 3000 on the host to port 3000 inside the container. |
After running these commands, the application will be accessible at http://localhost:3000.
Sources: README.md:41-47, src/main.rs:201
Container Architecture
The hdrify Docker image packages all necessary components to run the web application. The architecture is based on a Rust backend that serves a vanilla HTML/CSS/JS frontend and uses an external command-line tool for image processing.
Sources: README.md:52-55
Components
The following diagram illustrates the key components bundled within the Docker container.
This diagram shows the hdrify container architecture. The Rust binary is the core, serving static frontend files and executing ImageMagick for image processing.
- Rust Binary (
hdrify): The compiled application from the Rust source code defined inCargo.tomlandsrc/main.rs. It runs awarpweb server. - Static Files: The frontend assets located in the
static/directory, includingindex.html,script.js, andstyle.css, which are served directly by the web server. - ImageMagick: A crucial system dependency. The Rust backend executes the
magickcommand-line tool to perform the HDR image conversion. - Exposed Port: The container exposes port
3000, which the internalwarpserver listens on.
Sources: src/main.rs:88,187,201, README.md:52,55, Cargo.toml:2, static/index.html, static/script.js
Deployment Process Flow
The deployment process follows a standard Docker build-and-run workflow.
This flowchart shows the steps from source code to a running application accessible by the user.
- Build: The
docker buildcommand uses the project'sDockerfile(not provided in context, but implied) to compile the Rust application and bundle it with thestaticfiles and theImageMagickdependency into a single image namedhdrify. - Run: The
docker runcommand instantiates a container from thehdrifyimage. The-p 3000:3000flag maps the host's port 3000 to the container's port 3000, where thewarpserver is listening.
Sources: README.md:41-44, src/main.rs:201
Backend Service Details
The Rust backend is responsible for handling file uploads and orchestrating the image processing.
API Endpoint
The application exposes a single API endpoint for processing images.
- Endpoint:
POST /upload - Request Body:
application/x-www-form-urlencoded - Parameters:
image: Base64 encoded string of the image data.hdr_value: A floating-point number for the HDR intensity (e.g.,1.5).
Sources: src/main.rs:16,190, static/script.js:251-253
Image Processing Logic
Upon receiving a request at /upload, the handle_upload function performs the following steps:
- Decodes the Base64 image data.
- Validates the image size (max 10MB) and format (JPEG, PNG, WebP).
- Writes the image to a temporary file.
- Executes the
magickcommand with specific arguments to apply the HDR effect. - Reads the processed image from a temporary output file.
- Base64 encodes the result and returns it in a JSON response.
The following code snippet from the backend shows the ImageMagick command execution.
// src/main.rs:88-103
let output = Command::new("magick")
.arg(input_file.path())
.arg("-define")
.arg("quantum:format=floating-point")
.arg("-colorspace")
.arg("RGB")
.arg("-auto-gamma")
.arg("-evaluate")
.arg("Multiply")
.arg(hdr_value.to_string())
.arg("-evaluate")
.arg("Pow")
.arg("0.9")
.arg("-colorspace")
.arg("sRGB")
.arg("-depth")
.arg("16")
.arg("-profile")
.arg("2020_profile.icc")
.arg(output_file.path())
.output();
This dependency on an external command makes Docker an ideal deployment solution, as ImageMagick can be installed and configured within the image, avoiding setup issues on the host machine.
Sources: src/main.rs:14-131, README.md:32-38