gitfile
A lightweight Docker image for securely fetching files or folders from a GitHub repository using the GitHub API.
Tech Stack
� Story / Motivation
Managing environment files can be difficult, especially across multiple services and environments.
To simplify this, I store my environment files in a private GitHub repository and use a GitHub personal access token to securely download them at runtime. This Docker image automates that process and makes it easy to use those files in Docker-based workflows and other environments.
�🚀 Features
- Fetch files or directories from any GitHub repository
- Supports branches, tags, and commit SHAs
- Recursive directory fetching
- Exact path preservation
- Built-in retry logic
- Minimal Alpine-based image
- Ideal for CI/CD and containerized workflows
🐳 Docker Image
thefoxiedk/gitfile:latest
Pull the image
▶️ Usage
Fetched files will be written to the mounted output directory.
Docker Compose Example
You can use this image with Docker Compose to fetch files automatically.
🔐 Required Environment Variables
| Variable | Description |
|---|---|
GITHUB_TOKEN | GitHub personal access token |
GITHUB_REPO | Repository in org/repo format |
GITHUB_PATHS | Comma-separated list of files or directories |
⚙️ Optional Environment Variables
| Variable | Default | Description |
|---|---|---|
GITHUB_REF | main | Branch, tag, or commit SHA |
OUT_DIR | /secrets | Output directory inside container |
RETRY_COUNT | 3 | Number of retry attempts |
RETRY_DELAY | 2 | Delay between retries (seconds) |
📁 Path Mapping (IMPORTANT)
GITHUB_PATHSare preserved exactly in the output.
The directory and file structure from the GitHub repository is mirrored 1:1 under OUT_DIR.
Example
Output
- No renaming
- No flattening
- Safe for predictable mounts and automation
🧠 How It Works
- Resolves the commit SHA from
GITHUB_REF - Fetches the full repository tree via GitHub API
- Filters files matching
GITHUB_PATHS - Downloads contents using the Contents API
- Decodes and writes files to disk preserving paths
🔒 Security Notes
- Use read-only GitHub tokens
- Never bake secrets into images
- Mount output directories as volumes
- Avoid logging sensitive content