This repo documents how to deploy the upstream readium/cli repository to Railway using a fork, with publications stored in AWS S3. The fork contains the Railway configuration (railway.toml) while keeping the upstream codebase intact.
The deployment uses:
- A fork of
readium/clithat includesrailway.tomlfor config-as-code - AWS S3 for storing EPUB publications
- Railway for hosting the Readium CLI server
-
Fork the repository:
- Go to https://github.com/readium/cli
- Click "Fork" to create your own fork
- Note your fork's URL (e.g.,
https://github.com/YOUR_USERNAME/cli)
-
Add railway.toml to your fork:
- Clone your fork locally
- Copy
railway.tomlfrom this wrapper repo to the root of your fork - Update the
sourceinrailway.tomlto point to your fork (optional, Railway will use the repo you connect) - Commit and push to your fork's default branch (likely
developormain)
-
Via Railway UI:
- Create a new project or go to your existing project
- Click "New" → "GitHub Repo"
- Select your fork of
readium/cli - Railway will automatically detect
railway.tomlfor config-as-code
-
Via Railway CLI:
railway init --name readium-cli railway link # Then connect to your fork in the UI or use railway up with your fork URL
In Railway UI, go to your service → Settings → Source:
- Under "Upstream Repo", set it to
readium/cli - This allows Railway to show when upstream updates are available
- Click "Check for updates" periodically to see if upstream has new commits
In Railway UI, go to your service → Variables and add:
| Variable | Description | Example |
|---|---|---|
S3_ACCESS_KEY |
Your AWS access key ID | AKIAIOSFODNN7EXAMPLE |
S3_SECRET_KEY |
Your AWS secret access key | wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY |
S3_ENDPOINT |
AWS S3 endpoint URL | https://s3.amazonaws.com or https://s3.us-east-1.amazonaws.com |
S3_REGION |
AWS region where your bucket is located | us-east-1, eu-west-1, etc. |
S3_BUCKET |
Your S3 bucket name (for reference) | my-publications-bucket |
Note: The S3_BUCKET variable is for documentation/reference only. The Readium CLI uses S3 URIs in the format s3://bucket-name/path/to/file.epub when accessing publications.
- Standard AWS S3:
https://s3.amazonaws.com(us-east-1 default) - Region-specific:
https://s3.us-east-1.amazonaws.com,https://s3.eu-west-1.amazonaws.com, etc. - S3-compatible services: Use your service's endpoint URL
- In Railway UI, go to your service → Settings → Config-as-code
- Railway should automatically detect
railway.tomlin your fork - Verify the settings match what's in your
railway.tomlfile - The start command should include S3 flags with environment variable references, call the binary at
/opt/readium, and use a single string like"/bin/sh -c \"…\""so Railway expands$PORTand other env vars.
Upload your EPUB files to your S3 bucket using one of these methods:
aws s3 cp book.epub s3://your-bucket-name/publications/book.epub- Go to AWS S3 Console
- Navigate to your bucket
- Upload EPUB files (e.g., to a
publications/prefix)
Publications are accessed using S3 URIs in the format:
s3://bucket-name/path/to/file.epub
Example:
s3://my-publications-bucket/publications/hanis-assassin.epub
Important: Ensure your S3 bucket and objects have appropriate permissions. The IAM user/role associated with your S3_ACCESS_KEY needs at least s3:GetObject permission for the bucket and objects.
-
Trigger deployment:
- Railway will automatically deploy when you push to your fork
- Or manually trigger via Railway UI: Deployments → "Redeploy"
-
Test accessing publications:
- Encode your S3 URI to base64url format
- Access the manifest:
https://your-railway-url/{base64url-encoded-uri}/manifest.json
-
S3 URI:
s3://my-bucket/publications/book.epub -
Encode to base64url:
echo -n "s3://my-bucket/publications/book.epub" | base64 | tr -d '=' | tr '/+' '_-'
Result:
czM6Ly9teS1idWNrZXQvcHVibGljYXRpb25zL2Jvb2suZXB1Yg -
Access manifest:
https://your-railway-url.railway.app/czM6Ly9teS1idWNrZXQvcHVibGljYXRpb25zL2Jvb2suZXB1Yg/manifest.json -
The manifest will contain links to all resources in the publication
When upstream readium/cli has updates, sync them into your fork:
cd readium-cli # or wherever you cloned your fork
git remote add upstream https://github.com/readium/cli.git # if not already added
git fetch upstream
git merge upstream/develop # or 'main', depending on default branch
git push origin developRailway will automatically redeploy when you push to your fork.
For local development and testing, you can still use the local publications/ folder:
docker run --rm \
-p 15080:15080 \
-v "$(pwd)/publications:/srv/publications" \
readium-cli \
serve -s file,http,https --address 0.0.0.0 \
--port 15080 \
--file-directory /srv/publicationsOr use the helper script:
./scripts/run-local.sh- Verify your
S3_ACCESS_KEYandS3_SECRET_KEYare correct - Ensure the IAM user has
s3:GetObjectpermissions - Check that the bucket and objects exist
- Verify
S3_ENDPOINTmatches your region (or use the standard endpoint) - For non-AWS S3-compatible services, use the service's specific endpoint
- Verify the S3 URI is correct (bucket name, path, file extension)
- Check that the file exists in S3 and is accessible with your credentials
- Ensure the base64url encoding is correct (no padding, URL-safe characters)
- Set up automated syncing with upstream (GitHub Actions, etc.)
- Configure authentication mode (
-m jwtor-m jwks) for production - Set up monitoring and logging for your Railway service
- Consider using Railway's environment variables for different environments (staging/production)