This project provides automated build systems for creating portable database binaries for macOS and Linux across multiple architectures (x86_64 and arm64). The binaries are built with portable configurations and uploaded to Cloudflare R2 storage for distribution.
- PostgreSQL 17.5 (manual builds)
- MongoDB 8.0.12 (automated via GitHub Actions)
- Redis 7.2.5 (automated via GitHub Actions)
.
├── .github/workflows/
│ └── upload-binaries.yml # GitHub Actions workflow for MongoDB/Redis
├── manual/
│ └── postgresql/
│ ├── build_macos # macOS build script
│ └── build_linux # Linux build script
├── config.json # R2 credentials (not in repo)
└── README.md
Only required for manual builds. You can create a config.json
file in the project root directory:
{
"R2_ACCESS_KEY_ID": "your-r2-access-key",
"R2_SECRET_ACCESS_KEY": "your-r2-secret-key",
"R2_BUCKET": "your-bucket-name",
"R2_ENDPOINT": "https://your-account-id.r2.cloudflarestorage.com"
}
PostgreSQL builds are handled manually due to the complexity of creating truly portable binaries with proper library linking.
Features:
- Cross-compilation support for both arm64 and x86_64
- Portable rpath configuration using
@loader_path
- Automatic Homebrew installation if missing
- Library path fixing for portability
- Verification of portable paths
Usage:
cd manual/postgresql
./build_macos arm64 # Build for Apple Silicon
./build_macos x86_64 # Build for Intel Macs
Build Process:
- Downloads PostgreSQL 17.5 source
- Configures with portable settings (no readline, zlib, openssl, icu)
- Builds with architecture-specific flags
- Fixes library paths using
install_name_tool
- Verifies portable rpath configuration
- Creates tarball and uploads to R2
Features:
- Cross-compilation support for arm64 and x86_64
- RPATH configuration using
$ORIGIN/../lib
- Shared library bundling
- Binary stripping for size optimization
- Dependency verification
Usage:
cd manual/postgresql
./build_linux arm64 # Build for ARM64 Linux
./build_linux x86_64 # Build for x86_64 Linux
Build Process:
- Installs required packages and cross-compilation tools
- Downloads PostgreSQL 17.5 source
- Configures with shared libraries and portable RPATH
- Builds and installs to temporary directory
- Copies shared libraries and sets RPATH
- Strips binaries for size reduction
- Creates tarball and uploads to R2
MongoDB and Redis builds are automated through GitHub Actions workflow.
The workflow requires the following secrets to be configured in your GitHub repository:
Required Secrets:
R2_ACCESS_KEY_ID
- Your Cloudflare R2 access key IDR2_SECRET_ACCESS_KEY
- Your Cloudflare R2 secret access keyR2_BUCKET
- Your R2 bucket nameR2_ENDPOINT
- Your R2 endpoint URL (format:https://your-account-id.r2.cloudflarestorage.com
)
How to Set GitHub Secrets:
- Navigate to your GitHub repository
- Go to Settings → Secrets and variables → Actions
- Click New repository secret
- Add each of the required secrets listed above
- The workflow uses the
production
environment, so ensure secrets are available to that environment.
GitHub Environments Setup
The workflow uses the production
environment. To create and configure environments:
Creating a New Environment:
- Go to Settings → Environments
- Click New environment
- Enter environment name (e.g.,
production
,staging
,development
) - Click Configure environment
Adding Secrets to an Environment:
- In the environment configuration page
- Scroll to Environment secrets
- Click Add secret
- Add each of the required R2 secrets listed above
Using Different Environments: To use a different environment, modify the workflow file:
environment: staging # Change from 'production' to your environment name
Environment Benefits:
- Separate credentials for different deployment targets
- Additional security controls and approval processes
- Environment-specific configuration and protection rules
- Better organization for multi-stage deployments
# Manually trigger the workflow
gh workflow run "Build and Upload DB Binaries to R2"
The workflow builds for:
- Platforms: macOS, Linux
- Architectures: x86_64, arm64
- Databases: MongoDB 8.0.12, Redis 7.2.5
-
Update the
VERSION
variable in both build scripts:VERSION="17.6" # Update to new version
-
Update the
MAJOR_VERSION
calculation if needed (for major version changes) -
Run the build scripts on target machines:
cd manual/postgresql ./build_macos arm64 ./build_macos x86_64 ./build_linux arm64 ./build_linux x86_64
-
Update the
db_version
in.github/workflows/upload-binaries.yml
:- database: mongodb db_version: 8.0.13 # Update version
-
Update download URLs if the MongoDB/Redis release structure changes
-
Trigger the GitHub Actions workflow
Binaries are uploaded to R2 with the following structure:
s3://bucket/
├── postgresql/
│ └── 17/
│ ├── macos/
│ │ ├── arm64.tar.gz
│ │ └── x86_64.tar.gz
│ └── linux/
│ ├── arm64.tar.gz
│ └── x86_64.tar.gz
├── mongodb/
│ └── 8/
│ ├── macos/
│ │ ├── arm64.tar.gz
│ │ └── x86_64.tar.gz
│ └── linux/
│ ├── arm64.tar.gz
│ └── x86_64.tar.gz
└── redis/
└── 7/
├── macos/
│ ├── arm64.tar.gz
│ └── x86_64.tar.gz
└── linux/
├── arm64.tar.gz
└── x86_64.tar.gz
- Uses
@loader_path
for relative library paths - Fixes install names with
install_name_tool
- Sets minimum macOS versions (11.0 for arm64, 10.15 for x86_64)
- Verifies portable paths with
otool
- Uses
$ORIGIN/../lib
RPATH for relative library paths - Bundles required shared libraries
- Sets RPATH with
patchelf
orchrpath
- Strips binaries to reduce size
- Verifies dependencies with
ldd
andreadelf
- Xcode Command Line Tools
- Homebrew (auto-installed if missing)
- build-essential
- Development libraries (zlib1g-dev, libreadline-dev, etc.)
- Cross-compilation tools (for cross-arch builds)
- patchelf or chrpath for RPATH manipulation
- curl
- jq
- AWS CLI (for R2 uploads)
- Check that all prerequisites are installed
- Verify
config.json
exists and has correct R2 credentials - Ensure sufficient disk space for builds
- Check network connectivity for downloads
- Verify RPATH settings with
otool -L
(macOS) orreadelf -d
(Linux) - Check that all required libraries are bundled
- Test binaries on clean systems without development tools
- Verify R2 credentials and endpoint URL
- Check bucket permissions
- Ensure AWS CLI is properly configured
config.json
is excluded from version control- R2 credentials should be kept secure
- GitHub Actions uses encrypted secrets for credentials
- Build scripts use
set -euo pipefail
for error handling
- Add automated testing of built binaries
- Implement checksum verification
- Add support for additional PostgreSQL extensions
- Create unified build script for all databases
- Add Docker-based builds for better reproducibility