A Golang HTTP service that updates Railway services with new Docker image tags.
- HTTP endpoint accepting JSON PUT requests to update Railway service images
- Validates UUIDs and input parameters
- Filters services by Docker image prefixes
- Automatically updates matching services to a new version
- Triggers deployment of updated services
- Health check endpoint
- Go 1.20 or higher
- Railway API token
go mod download
go build -o railway-image-updater .Set the following environment variable:
RAILWAY_API_TOKEN: Your Railway API token (required)PORT: Port to run the server on (optional, defaults to 8080)
export RAILWAY_API_TOKEN=your-railway-token
./railway-image-updaterThe server will start on port 8080 by default.
Endpoint: PUT /update
Request Body:
{
"project_id": "550e8400-e29b-41d4-a716-446655440000",
"environment_id": "550e8400-e29b-41d4-a716-446655440001",
"image_prefixes": ["myapp", "docker.io/myorg/myapp"],
"new_version": "v1.2.3"
}Parameters:
project_id(string, required): Railway project UUIDenvironment_id(string, required): Railway environment UUIDimage_prefixes(array of strings, required): List of Docker image name prefixes (without version tags)new_version(string, required): New Docker image tag to update to
Success Response (200 OK):
{
"message": "Successfully updated 2 service(s)",
"updated_services": ["api-service", "worker-service"]
}Error Response (4xx/5xx):
{
"error": "Error message describing what went wrong"
}Endpoint: GET /health
Response:
{
"status": "ok"
}- The endpoint receives a PUT request with project ID, environment ID, image prefixes, and new version
- Input validation is performed (UUIDs, non-empty arrays, etc.)
- The service queries Railway API for all services in the specified environment
- Services with Docker images matching any of the provided prefixes are identified
- Each matching service's image tag is updated to the new version
- The updated services are redeployed
- A list of updated service names is returned
Update all services using the "myapp" Docker image to version "v2.0.0":
curl -X PUT http://localhost:8080/update \
-H "Content-Type: application/json" \
-d '{
"project_id": "550e8400-e29b-41d4-a716-446655440000",
"environment_id": "550e8400-e29b-41d4-a716-446655440001",
"image_prefixes": ["myapp"],
"new_version": "v2.0.0"
}'Run the test suite:
go test -v .This project includes GitHub Actions workflows that automatically:
- Run tests on every push and pull request
- Run
go vetandgo fmtchecks - Build Docker images
- Push images to GitHub Container Registry (ghcr.io) on main/master branch
docker pull ghcr.io/returnearly/railway-image-updater:latest
docker run -p 8080:8080 -e RAILWAY_API_TOKEN=your-token ghcr.io/returnearly/railway-image-updater:latestBuild and run with Docker:
docker build -t railway-image-updater .
docker run -p 8080:8080 -e RAILWAY_API_TOKEN=your-token railway-image-updaterDeploy to Railway:
- Push your code to a Git repository
- Connect the repository to Railway
- Set the
RAILWAY_API_TOKENenvironment variable in Railway - Railway will automatically build and deploy your service
See LICENSE file for details.