Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 10 additions & 106 deletions elixir/getting-started/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,137 +41,41 @@ The output ends with instructions for configuring the database and starting the

When you run `fly launch` from the newly-created project directory, the launcher provides some defaults for your new app, and gives you the option to tweak the settings.

Run:
Run `fly launch` with `--db=mpg` to give the app a [Managed Postgres](/postgres) cluster:
```sh
cd hello_elixir
fly launch
fly launch --db=mpg
```

You'll get a summary of the defaults chosen for your app:
If your organization is on the [Free plan](/about/free-plan), `fly launch --db=mpg` can't create the cluster: launch uses the Basic plan, and the Free plan includes only the Developer plan. Instead, run `fly launch --no-db --no-deploy`, create a Developer plan cluster with `fly mpg create`, [attach it](/postgres/create-and-connect) with `fly mpg attach <CLUSTER_ID>`, and then run `fly deploy`.

```output
Organization: MyOrgName (fly launch defaults to the personal org)
Name: hello_elixir (derived from your directory name)
Region: Secaucus, NJ (US) (this is the fastest region for you)
App Machines: shared-cpu-1x, 1GB RAM (most apps need about 1GB of RAM)
Postgres: <none> (not requested)
Redis: <none> (not requested)

? Do you want to tweak these settings before proceeding? Yes
Opening https://fly.io/cli/launch/bea626e2d179a083a3ba622a367e24ec ...
```

Type `y` at the prompt to open the Fly Launch page, and make the following changes to your app config:

* Change the default app name and region, if needed.
* For Databases, select Fly Postgres, give the Postgres database app a name (for example, your app name with `-db` appended) and choose a configuration.
You'll get a summary of the defaults chosen for your app, including a Managed Postgres cluster on the Basic plan, and the launcher asks whether you want to tweak these settings. Type `y` to open the Fly Launch page and change the app name or region, or `n` to accept the defaults.

Once you confirm your settings, you can return to the terminal, where the launcher will:
Once you confirm your settings, the launcher will:

* Create the Managed Postgres cluster, wait for it to be ready, and set the `DATABASE_URL` secret on your app
* Run the deployment setup task
* Build the image
* Set secrets required by (`SECRET_KEY_BASE`, for example)
* Deploy the application in your selected region

```output
Waiting for launch data... Done
Created app 'hello_elixir' in organization 'personal'
Admin URL: https://fly.io/apps/hello_elixir
Hostname: hello_elixir.fly.dev
Set secrets on hello_elixir: SECRET_KEY_BASE
Creating postgres cluster in organization personal
Creating app...
Setting secrets on app hello_elixir-db...
Provisioning 1 of 1 machines with image flyio/postgres-flex:15.3@sha256:44b698752cf113110f2fa72443d7fe452b48228aafbb0d93045ef1e3282360a6
Waiting for machine to start...
Machine 2865550c7e96d8 is created
==> Monitoring health checks
Waiting for 2865550c7e96d8 to become healthy (started, 3/3)

Postgres cluster hello_elixir-db created
Username: postgres
Password: EChe3BrhCjsPQEI
Hostname: hello_elixir-db.internal
Flycast: fdaa:2:45b:0:1::1d
Proxy port: 5432
Postgres port: 5433
Connection string: postgres://postgres:EChe3BrhCjsPQEI@hello_elixir-db.flycast:5432

Save your credentials in a secure place -- you won't be able to see them again!

Connect to postgres
Any app within the MyOrgName organization can connect to this Postgres using the above connection string

Now that you've set up Postgres, here's what you need to understand: https://fly.io/docs/postgres/getting-started/what-you-should-know/
Checking for existing attachments
Registering attachment
Creating database
Creating user

Postgres cluster hello_elixir-db is now attached to hello_elixir
The following secret was added to hello_elixir:
DATABASE_URL=postgres://aa_hello_elixir2:Er6pLzUBuhKcbBl@hello_elixir-db.flycast:5432/aa_hello_elixir2?sslmode=disable
Postgres cluster hello_elixir-db is now attached to hello_elixir
Generating rel/env.sh.eex for distributed Elixir support
Preparing system for Elixir builds
Installing application dependencies
Running Docker release generator
Wrote config file fly.toml
Validating /Users/anderson/test-elixir-gs/hello_elixir2/fly.toml
✓ Configuration is valid
==> Building image
Remote builder fly-builder-black-pine-7645 ready
Remote builder fly-builder-black-pine-7645 ready
==> Building image with Docker
--> docker host: 20.10.12 linux x86_64
The output ends with the URL of your deployed app:

```output
...

--> Pushing image done
image: registry.fly.io/hello_elixir:deployment-01HPMGHTG8XSYH3ZCV82SF5CEZ
image size: 126 MB

Watch your deployment at https://fly.io/apps/hello_elixir/monitoring

Provisioning ips for hello_elixir
Dedicated ipv6: 2a09:8280:1::2a:bc0b:0
Shared ipv4: 66.241.124.79
Add a dedicated ipv4 with: fly ips allocate-v4

Running hello_elixir release_command: /app/bin/migrate

-------
✔ release_command 784eee4c294298 completed successfully
-------
This deployment will:
* create 2 "app" machines

No machines in group app, launching a new machine
Creating a second machine to increase service availability
Finished launching new machines
-------
NOTE: The machines for [app] have services with 'auto_stop_machines = true' that will be stopped when idling

-------
Checking DNS configuration for hello_elixir.fly.dev

Visit your newly deployed app at https://hello_elixir.fly.dev/
```

<Note>
Make sure to note your Postgres credentials from the output.
</Note>

That's it! Run `fly apps open` to see your deployed app in action.

Try a few other commands:

* `fly logs` - Tail your application logs
* `fly status` - App deployment details
* `fly status -a postgres-database-app-name` - Database deployment details
* `fly mpg status` - Database cluster details
* `fly deploy` - Deploy the application after making changes

To recap, the `fly launch` command detected that we are using Phoenix, set up a Fly app, created a Fly Postgres app and configured it for us, updated our Dockerfile, and created special modules and scripts to run ecto migrations for us!
To recap, the `fly launch` command detected that we are using Phoenix, set up a Fly app, created a Managed Postgres cluster and attached it for us, updated our Dockerfile, and created special modules and scripts to run ecto migrations for us!

### Storing secrets on Fly.io

Expand Down
Loading