cli/Cargo.toml
Jake Runzer c65c909420
Add dev command for local development with Docker Compose (#710)
* init develop command

* develop: use service names, random ports, project-specific dir

- extract environment config types to controllers/environment_config.rs
- use slugified service names instead of IDs in compose
- generate deterministic external ports (10000-60000) to avoid conflicts
- save compose to ~/.railway/develop/<project_id>/
- always run detached

* develop: show service names and URLs in output

* develop: resolve variables and override Railway networking vars

- Fetch resolved variables via VariablesForServiceDeployment API
- Override RAILWAY_PRIVATE_DOMAIN with docker-compose service slug
- Override RAILWAY_PUBLIC_DOMAIN and RAILWAY_TCP_PROXY_DOMAIN with localhost
- Override RAILWAY_TCP_PROXY_PORT with mapped local port
- Replace *.railway.internal refs in values with service slugs
- Filter deprecated vars (RAILWAY_STATIC_URL, RAILWAY_SERVICE_*_URL)
- Add docker-compose networking for inter-container communication
- Escape $ as $$ in commands for docker-compose interpolation

* develop: add volume support and down subcommand

- Add volumes field to docker-compose output (persist through up/down)
- Add `develop down` subcommand to stop containers
- Use environment ID for compose dir and volume names
- Show volume mount paths in service summary

* run: use local services when develop is active

Add --no-local flag to skip. Extracts shared variable override logic
into controllers/local_override.rs for reuse between run and develop.

* develop down: add --clean flag to remove volumes and files

* restart services on failure

* develop: add local HTTPS with mkcert and pretty URLs

- auto-generate TLS certs via mkcert for {project}.railway.dev
- add Caddy reverse proxy for HTTPS termination
- set RAILWAY_PUBLIC_DOMAIN to https://{domain}:{port}
- auto-add /etc/hosts entry on develop up
- remove hosts entry on develop down --clean
- skip cert generation if already exists

* develop: use .localhost TLD instead of .railway.dev

.localhost resolves to 127.0.0.1 per RFC 6761, eliminating need for
/etc/hosts manipulation and sudo prompts

* process manager

* develop: support port 443 for prettier public URLs

- Try binding to port 443 at startup for cleaner URLs
- Port 443 mode: https://{service}.{project}.railway.localhost
- Fallback mode: https://{project}.railway.localhost:{port}
- Generate wildcard certs (*.project.railway.localhost) for port 443
- SNI-based routing in Caddy when using port 443
- Add http:// prefix to private domain display

* develop: add session lock to prevent concurrent code service runs

- Add DevelopSessionLock using fs2 file locking to prevent multiple
  develop sessions running code services for the same environment
- Check existing https_mode before falling back from port 443
- Lock auto-releases on drop or process crash

* develop: refactor into testable module structure

- Extract shared types to controllers/config/ (EnvironmentConfig)
- Create controllers/develop/ with submodules:
  - ports.rs: slugify, generate_port + tests
  - variables.rs: override_railway_vars + tests
  - session.rs: DevelopSessionLock + tests
  - traits.rs: EnvironmentDataProvider, CommandRunner + mocks
  - compose.rs: DockerCompose types, build_port_infos
  - https_proxy.rs: HttpsConfig, certs, Caddyfile gen
  - code_runner.rs: ProcessManager
  - local_config.rs: LocalDevConfig
- Add async-trait dependency for trait abstractions
- Old controller files re-export for backward compat

* develop: remove unused traits and cleanup backward compat stubs

- Delete unused EnvironmentDataProvider and CommandRunner traits (371 lines)
- Add fetch_environment_config() function to controllers/config
- Update develop.rs to use centralized fetch function
- Delete empty stub files: process_manager.rs, develop_lock.rs,
  local_https.rs, local_dev_config.rs
- Update local_override.rs to import directly from develop module

* develop: remove unused get_env_vars, cleanup dead_code attributes

- Remove unused get_env_vars method from ServiceInstance
- Remove unnecessary #![allow(dead_code)] from compose.rs and output.rs
- Add explanatory comment for dead_code allow in environment.rs
  (needed for API deserialization struct fields)

* dev: rename develop to dev, add clean subcommand

- rename command from `develop` to `dev` (with `develop` alias)
- extract `--clean` flag from `down` into separate `clean` subcommand
- update output: remove "Using port 443" msg, add checkmark to "Started X image services"

* dev: store data in ~/.railway/develop/{projectId} instead of environmentId

* remove unnecessary comments

* dev: add unit tests for compose, https_proxy, local_config

Tests for port building, caddyfile generation, cert existence, and config operations.

* dev: fix cross-platform compatibility for Linux/Windows

- Add extra_hosts to Caddy service for host.docker.internal on Linux
- Use shell execution (sh -c / cmd /C) for proper command parsing
- Replace path unwraps with to_string_lossy()

* dev: check docker compose availability before running

* fix: handle Windows error kind for file lock conflicts

* dev configure: add service menu and --remove <name> support

* dev: clarify comments in up_command

* fix: use fs2 lock_contended_error for cross-platform lock check

* fix: use privateNetworkEndpoint for private domain resolution

Previously used slugified service name which may not match the actual
private network endpoint configured in the environment.

* refactor: extract build_service_endpoints helper for privateNetworkEndpoint

DRYs up duplicate logic between dev.rs and local_override.rs.
Fixes run command using environment_id instead of project_id for
is_local_develop_active check.

* dev: improve empty state messages

Distinguish "no services at all" from "no code services" so users
get actionable guidance (railway add vs railway develop configure)

* fix: only show networking for code services when port configured

* fix: skip canonicalize on windows to avoid UNC path prefix

canonicalize() returns \\?\C:\... paths on Windows which cmd.exe rejects

* dev: improve empty state messages with color

* dev: show command as first log line for code services

* dev: add port selection to configure and detect port conflicts

- prompt for port during service configuration (default: inferred from Railway)
- skip port prompt if service has no networking config
- detect and warn about port conflicts during configure
- force reconfigure conflicting ports during `railway dev up`
- only set PORT env var for services with networking configured

* dev: allow configuring multiple services on first-time setup

Use multi-select prompt instead of single-select, with summary at end

* dev: show OS-specific Docker install URL

* dev: format Docker not found message

* remove test dir

* remove test and to gitignore

* dev: fix cross-service public domain replacement

When service A references service B's RAILWAY_PUBLIC_DOMAIN via variable
interpolation, the production domain wasn't being replaced with the local
equivalent. Now builds a mapping of production -> local public domains
and replaces them in all variable values.

* dev: show next steps when only image services running

* dev: extract constants and refactor up_command

- Add port range constants (PORT_RANGE_MIN, PORT_RANGE_SIZE, RANDOM_PORT_MIN, RANDOM_PORT_MAX)
- Add resolve_path() for cross-platform path canonicalization
- Move generate_random_port() to ports.rs
- Extract helper functions from up_command:
  - print_image_service_summary()
  - print_code_service_summary()
  - build_public_domain_mapping()
  - build_image_service_compose()
  - setup_caddy_proxy()
2025-12-12 18:18:58 -05:00

110 lines
2.6 KiB
TOML

[package]
name = "railwayapp"
version = "4.12.0"
edition = "2024"
license = "MIT"
authors = ["Railway <contact@railway.com>"]
description = "Interact with Railway via CLI"
readme = "README.md"
homepage = "https://github.com/railwayapp/cli"
repository = "https://github.com/railwayapp/cli"
rust-version = "1.85.0"
default-run = "railway"
include = ["src/**/*", "LICENSE", "README.md"]
[[bin]]
name = "railway"
path = "src/main.rs"
[dependencies]
anyhow = "1.0.95"
clap = { version = "4.5.23", features = ["derive", "suggestions", "cargo"] }
colored = "2.2.0"
dirs = "5.0.1"
serde = { version = "1.0.217", features = ["derive"] }
serde_json = "1.0.134"
serde_yaml = "0.9"
reqwest = { version = "0.12.12", default-features = false, features = [
"rustls-tls",
"json",
] }
chrono = { version = "0.4.39", features = [
"serde",
"clock",
], default-features = false }
graphql_client = "0.14.0"
tokio = { version = "1.48.0", features = ["full"] }
clap_complete = "4.5.40"
open = "5.3.1"
inquire = "0.9.1"
hyper = { version = "1.5.2", features = ["server", "http1"] }
hyper-util = { version = "0.1.10", features = ["tokio"] }
base64 = "0.22.1"
http-body-util = "0.1.2"
rand = "0.8.5"
hostname = "0.4.0"
indicatif = "0.18.3"
indoc = "2.0.5"
console = "0.15.10"
box_drawing = "0.1.2"
textwrap = "0.16.1"
gzp = { version = "0.11.3", default-features = false, features = [
"deflate_rust",
] }
tar = "0.4.43"
synchronized-writer = "1.1.11"
ignore = "0.4.23"
num_cpus = "1.16.0"
url = "2.5.4"
futures = { version = "0.3.31", default-features = false, features = [
"compat",
"io-compat",
"executor"
] }
futures-util = "0.3"
graphql-ws-client = { version = "0.11.1", features = [
"client-graphql-client",
"tungstenite",
] }
async-tungstenite = { version = "0.28.2", features = [
"tokio-runtime",
"tokio-rustls-native-certs",
] }
crossterm = { version = "0.27.0", features = ["event-stream"] }
http = "0.2"
is-terminal = "0.4.13"
serde_with = "3.12.0"
ctrlc = "3.4.5"
which = "7.0.1"
thiserror = "2.0.9"
winapi = { version = "0.3.9", features = [
"minwindef",
"tlhelp32",
"processthreadsapi",
"handleapi",
"winerror",
] }
strum = { version = "0.26.3", features = ["derive"] }
structstruck = "0.4.1"
derive-new = "0.7.0"
struct-field-names-as-array = "0.3.0"
json_dotpath = "1.1.0"
country-emoji = "0.2.0"
chrono-humanize = "0.2.3"
notify = "8.0.0"
croner = "3.0.1"
tokio-util = "0.7.15"
similar = "2.7.0"
pathdiff = "0.2.3"
pastey = "0.1.1"
nix = { version = "0.30.1", features = ["signal"] }
fs2 = "0.4.3"
async-trait = "0.1.89"
[profile.release]
lto = "fat"
opt-level = "z"
panic = "abort"
[dev-dependencies]
tempfile = "3.23.0"