# Migration from Heroku to Fly.io

We recently migrated our app from heroku to fly.io server with minimum downtime (almost 5 seconds of downtime) to be more precise. Here is how we did that.

First step obviously is to create a new branch and setup fly configuration. For that fly has a really nice CLI command which generates all the necessary configurations for you by inspecting your project files. For that first thing you need to do is Install fly CTL tool

* Install [https://fly.io/docs/hands-on/install-flyctl/](https://fly.io/docs/hands-on/install-flyctl/)
    
* login to your fly app with
    

```bash
fly auth login
```

Now you are ready to move forward.

Now follow [https://fly.io/docs/rails/getting-started/existing/](https://fly.io/docs/rails/getting-started/existing/) to configure your existing ruby on rails application.

```bash
fly launch
```

and provide all necessary information if needed. This will generate `Dockerfile` if missing and `fly.toml` file and bunch of configuration files for your project.

Once your setup are done, it will also create a fly app in the fly dashboard, you can check it and confirm everything is fine.

Now next step is to Deploy our application with:

```bash
fly deploy
```

This command will build docker, push it to registry, run assets pre-compilation and so on, you can configure your Dockerfile as needed and finally it will deploy your app to fly server.

You will also see a fly domain where you can confirm all of the app features are working fine.

```bash
fly apps open
```

### Migration from Heroku

Now that we our app is working as expected we need to migrate from Heroku for that follow: [https://fly.io/docs/rails/getting-started/migrate-from-heroku/](https://fly.io/docs/rails/getting-started/migrate-from-heroku/)

You can see, you can easily move all of your production Heroku Config vars with one single command:

```bash
heroku config -s | grep -v -e "RAILS_MASTER_KEY" -e "DATABASE_URL" -e "REDIS_URL" -e "REDIS_TLS_URL" | fly secrets import
```

I will keep sharing the migration process in upcoming articles.
