Assuming a few things:
- the original server is still running, and that the new server cannot be bootstrapped from an image or backup of the old server (for example, they are with different hosts)
- Dokku has been installed on the new server and is accessible using the dokku user (See https://dokku.com)
- We have an SSH config entry for both old and new servers in ~/.ssh/config:
host new_server
RequestTTY yes
Hostname 55.190.140.231
User dokku
IdentityFile ~/.ssh/id_rsa
Host old_server
RequestTTY yes
Hostname 55.78.183.109
User dokku
IdentityFile ~/.ssh/id_rsa
Create new app
ssh new_server apps:create icepop_app
Fetch env vars for original
ssh old_server config:show icepop_app
Set important keys (not DOKKU_*)
ssh new_server config:set icepop_app RAILS_MASTER_KEY=VALUE EMAIL_API_KEY=VALUE MAP_API_KEY=VALUE
Add new git remote repo based on the current one
git remote -v
git remote add new_server dokku@new_server:icepop_app
Create new DB
ssh new_server postgres:create icepop_app_production
Link DB to the new app
ssh new_server postgres:link icepop_app_production icepop_app
Dump the data from the old DB
You might want to do this at a slow time to minimise lost updates, or introduce the maintenance page.
ssh old_server postgres:export icepop_app-production > ~/Downloads/sql/icepop_app_production.dump
Import the dump
ssh new_server postgres:import icepop_app_production < ~/Downloads/sql/icepop_app_production.dump
Deploy the project
git push new_server deploy:main
Add domains to the app
ssh new_server domains:add icepop_app www.icepop_app.com icepop_app.com
Configure SSL certificate(s) via letsencrypt
ssh new_server letsencrypt:set icepop_app email james@icepop_app.com
Check where the DNS is configured and move the A records to point to the new server using the registrar’s UI
whois will give you a clue which registrar you used if you’re anything like me and have three in use.
whois icepop_app.com
Request SSL certificates
ssh new_server letsencrypt:enable icepop_app
Tail the logs to ensure traffic is flowing as expected
ssh new_server logs -t icepop_app
Connect to the Rails console to check changes are reflected in the browser
ssh new_server run icepop_app "bundle exec rails console -e production"
All being well, your app is migrated (remember to check for any local file uploads etc) and the old server can be decomissioned.