Resizing Instances
Resizing lets you change an instance's CPU, memory, and disk size while preserving its filesystem and identity. Use a big machine to compile and test quickly, then resize down to a smaller footprint for serving—without baking new images or swapping instance IDs.
Under the hood, Morph preserves your on‑disk changes and restarts with the new resources. URLs, exposed services, and the instance ID stay the same.
Typical Workflow: Burst to Build, Shrink to Serve
- Scale up for builds and CI workloads
morphcloud instance reboot inst_123 \
--vcpus 16 --memory 32768 --disk-size 65536 \
-m role=build -m stage=compile
-
Run your build and validation tasks (via SSH or
morphcloud instance exec
). -
Scale down for deployment
morphcloud instance reboot inst_123 \
--vcpus 1 --memory 2048 --disk-size 65536 \
-m role=serve -m stage=run
Cost control
Add a TTL while scaled up so large machines don't linger.
morphcloud instance reboot inst_123 \
--vcpus 16 --memory 32768 --disk-size 65536 \
--ttl-seconds 1800 --ttl-action pause
Use With systemd
Trigger setup or build steps automatically at boot using a one‑shot systemd
service.
/etc/systemd/system/app-boot.service
[Unit]
Description=App build/deploy tasks at boot
After=network-online.target
Wants=network-online.target
[Service]
Type=oneshot
User=root
WorkingDirectory=/root/app
ExecStart=/usr/local/bin/app-bootstrap.sh
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
Enable and test:
chmod +x /usr/local/bin/app-bootstrap.sh
systemctl enable app-boot.service
systemctl start app-boot.service # run now
# After each resize (via reboot), systemd runs it again at boot
Script outline
- Detect the desired role via instance metadata (e.g.,
role=build
vsrole=serve
). - For build role: pull deps, compile artifacts, populate cache.
- For serve role: apply migrations, warm caches, start your supervisor.
SDK Example (Python)
- Python
from morphcloud.api import MorphCloudClient
client = MorphCloudClient()
inst = client.instances.get("inst_123")
# Burst to build
inst.reboot(vcpus=16, memory=32_768, disk_size=65_536, metadata={"role": "build"})
# ... run build steps via SSH/exec ...
# Shrink to serve
inst.reboot(vcpus=1, memory=2_048, disk_size=65_536, metadata={"role": "serve"})
Guarantees
- Filesystem is preserved across the resize.
- Instance ID and URLs remain stable; exposed services continue to work.
- Resource/billing accounting updates to the new spec immediately after the resize.