Migrate from Heroku to Coherence
This guide shows you how to easily migrate your application from Heroku to Coherence.
By running your app in your own cloud account on Amazon Web Services (AWS) or Google Cloud Platform (GCP), you get the compliance, cost, and customization benefits that only the large public cloud providers can offer. Read more about Coherence vs. platform-as-a-service (PaaS) provider hosting here.
Coherence offers the features you love on Heroku, like built-in CI/CD and preview environments, while also delivering a great developer experience with a user-friendly developer portal and CLI. When you use Coherence, you don't need to be a DevOps expert to manage a world-class deployment platform - leave that part to us. Additionally, you can use your cloud credits with Coherence, making it the perfect choice for startups.
What You'll Learn
This guide will show you how to:
- Prepare an application deployed on Heroku for deployment on Coherence
- Deploy the application on Coherence
- Migrate the data from your Heroku database to Coherence
- Transfer your domain from Heroku to Coherence
Prerequisites
To follow along, you'll need:
- A Coherence account
- A GitHub account
- Administrator access to your Heroku account
- Administrator access to a Google Cloud Platform (GCP) or Amazon Web Services (AWS) account
- An app on Heroku that you want to migrate. If you don't have one, you can fork our example application.
1. Prepare your Heroku application for migration
Coherence gives you flexible options for building and deploying your application.
Option A: Use Nixpacks (recommended)
If you don't have a Dockerfile, Coherence will automatically use Nixpacks to build your container. This means you don't need to make any changes to your application structure.
Option B: Use an existing Dockerfile
If you've been using the Heroku container registry with a Dockerfile, Coherence will use that Dockerfile to deploy your application. No additional preparation is needed.
Option C: Write a Dockerfile (if necessary)
If your application uses a Heroku Procfile and you prefer not to use Nixpacks, you'll need to write a Dockerfile for your application. For more information on writing a Dockerfile, see the Dockerfile reference documentation.
Save your startup command
Regardless of which option you choose, you'll need to note the command used to start your application. You can find this in your Procfile or Dockerfile, or by checking the Resources tab in your Heroku dashboard under the Eco Dynos heading.
For example, your startup command might look like this:
web: npm run start
You'll need this command when configuring your service in Coherence.
2. Deploy your application on Coherence
Now that your code is prepared, let's set up your application on Coherence.
Create a new application
- In the Coherence dashboard, click New application
- Give the application a name
- Select Google Cloud as the provider and Cloud Run as the architecture
- Click Continue
Create a collection
Collections in Coherence allow you to organize environments.
- On the application's landing page, click Create collection
- Give the collection a name
- Click Create Collection
Configure an environment
- In the collection, click New Environment
- Give the environment a name
- Select the appropriate environment type (Staging is recommended for initial testing)
- Click Create
Add Coherence services
Services in Coherence are loosely equivalent to web dynos in Heroku. Here's how to set them up.
Create a backend service
- Click the environment name to enter the environment homepage
- Go to the Services tab
- Click New service and select the framework for your project under Container
- Configure the service:
- Name: Give the service a name, like "backend"
- Start Command: Enter the command you saved earlier (e.g.,
npm run start
) - Enter "/" under URL path
- Container source: Choose Repository
- Click Add one under Repo
- Paste in the link to your GitHub code repository
- Enter "/" under Context
- If you're using a Dockerfile, enter "Dockerfile" under Dockerfile. Otherwise, leave it blank to use Nixpacks
- Select your track branch (for example,
main
) - Click Create service
After creating the service, add the necessary environment variables in the Variables tab. You can bulk import variables using the Coherence UI. The Coherence CLI offers environment variable management capability for scripting.
Create a database service
- In the Services tab, click New service and select Postgres (or equivalent database)
- Configure the database:
- Name: Give the service the same name as your application's database
- Engine: Enter "postgres"
- Version: Choose the appropriate version
- Click Create service
Connect to your cloud provider
Follow the steps in our Google Cloud guide or AWS guide to connect Coherence to your cloud account.
Start a provisioning task
When Coherence has been granted access to your cloud account, submit a provisioning task so that Coherence can automatically set up and manage the necessary cloud resources for your collection.
- Select the Provision Tasks tab for the collection
- Click the Submit button to submit a provisioning task
- Click the Submit new task button
Coherence will automatically provision infrastructure for your project based on your service requirements. Wait for this step to complete before moving on. It should take several minutes.
Start a build and deploy pipeline
- Go to the Deployments tab for the environment
- Click New deployment
- Select the branch and commit to build from
- Click Submit deployment to start the build and deploy process
View your deployed application
Once the build is complete:
- In your Coherence dashboard, navigate to your environment
- Look for the Domains section and find the provided URL
- Click the URL to open your deployed application in a new browser tab
3. Migrate the data
This is a crucial step in the migration process. Don't hesitate to contact the Coherence team if you need assistance.
Export data from Heroku
- In your Heroku dashboard, go to the Settings tab
- In the Config Vars section, copy the
DATABASE_URL
value - On your local machine, install
pg_dump
- Use
pg_dump
to export your data:
pg_dump "your-connection-string" > heroku_db_dump.sql
Choose a migration method
You can migrate data to Coherence in two ways:
- Using the Coherence CLI (
cocli
), which includes a bastion to a private IP in your VPC - Migrating directly to your cloud database using a public IP
Choose the method you prefer below.
Set up a CNC toolbox
Set up a CNC toolbox to interact with your Coherence environment from your local machine:
- Install
cocnc
by following the instructions in the CNC documentation - Install
cocli
by following the instructions in the cocli GitHub repository - Install the Google Cloud CLI by following the instructions in the Google Cloud documentation
- Authenticate the Google Cloud CLI with these commands:
gcloud auth application-default login
gcloud auth login
Start a toolbox
First, set up authentication.
- In the Coherence dashboard, navigate to your profile
- Click Create token
- Give the token a name and select an expiration period
- Click Create token
- Copy the token value
- Run the following command on your local machine with your access token:
export COHERENCE_ACCESS_TOKEN="your-access-token-here"
Next, set your app ID and collection ID to variables.
In your terminal, add your app name and collection name to the command below:
app_id=$(cocli apps list | jq '.[] | select(.title=="Your App Name") | .id')
collection_id=$(cocli collections list -a $app_id | jq '.data[] | select(.name=="your-collection-name") | .id')
To start a toolbox, replace main
with your environment name in the following command:
cocli cnc -c $collection_id -- toolbox start main --proxy-only
Keep the toolbox running while you migrate the data in a new terminal.
Migrate the data to the Coherence project
To import your data to your new Coherence-managed database:
- Open a new terminal in the folder containing the
heroku_db_dump.sql
file - Get the
psql
database connection string from Coherence by copying the value of theDATABASE_URL
variable found in the Variables tab on your environment homepage - Run the following command, replacing
<database-connection-string>
with your database connection string andpath/to/heroku_db_dump.sql
with the path to your migration file:
psql -d <database-connection-string> < path/to/heroku_db_dump.sql
To migrate your data directly to GCP, first authorize your public IP.
- Get your public IP. Find your public IP here.
- Navigate to your GCP console
- Navigate to SQL in the left menu
- Navigate to Connections and open the Networking tab
- Scroll down to Authorized networks
- In New network*, give your network a name and add your public IP address in the Network* field
- Click Add network, then click Save at the bottom of the page
Connect to your Cloud SQL database on your local machine with the following command:
psql -d <database-connection-string> < path/to/heroku_db_dump.sql
Verify the data migration
Check your application to ensure your data has been successfully migrated.
4. Migrate the domain
The final step is to update your domain settings to point to your Coherence-hosted application.
Remove the domain from Heroku
- In your Heroku project settings, navigate to the Domains section
- Remove the custom domain from your Heroku project
Change DNS settings for the domain
- Log in to your domain registrar's dashboard
- In the Coherence dashboard, navigate to your environment homepage and select the Custom domains tab
- Add your custom domain to the Domain field
- Copy the provided DNS record and add it to your domain registrar's settings
- Click Add domain to save the configuration
Wait for DNS propagation (up to 48 hours).
Once DNS propagation is complete, visit your domain to verify that your website is accessible and your migrated data is functioning correctly.
Conclusion
Congratulations! You've successfully migrated your application from Heroku to Coherence. Enjoy the benefits of running your application on your own cloud infrastructure while maintaining the ease of use you're accustomed to with PaaS providers.
If you encounter any issues or have questions during the migration process, don't hesitate to reach out to the Coherence support team. We're here to ensure your migration is smooth and successful.