Here are the steps to update [Phoenix Live SaaS Kit](https://livesaaskit.com/) for [Fly](https://fly.io) and Phoenix 1.6.9: ## Initial Deployment 1. `git init`, `git add .`, `git commit -m "init repo"` 2. Remove generated docker & deploy script files * `build.sh` * `docker-entrypoint.sh` * `.dockerignore` * `Dockerfile` * `docker-compose.yml` 4. Update .tool-versions: ``` elixir 1.13.4-otp-24 erlang 24.3.4 ``` 5. Open `mix.exs` and update phoenix to `1.6.9` & phoenix_html to `3.2.0` 7. Run `mix deps.get` 7. Run `cd assets` then `rm yarn.lock`. Will use `npm` to match Dockerfile. 8. Run `npm install` 9. Update runtime.exs database config: ``` maybe_ipv6 = if System.get_env("ECTO_IPV6"), do: [:inet6], else: [] config :demo, Demo.Repo, # ssl: true, url: database_url, pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"), socket_options: maybe_ipv6 ``` See: https://community.fly.io/t/how-to-run-ecto-create-for-an-elixir-app/5001/2 10. Update runtime.ex endpoint config. ``` host = System.get_env("PHX_HOST") || "example.com" port = String.to_integer(System.get_env("PORT") || "4000") config :demo, DemoWeb.Endpoint, url: [host: host, port: 443, scheme: "https"], http: [ # Enable IPv6 and bind on all interfaces. # Set it to {0, 0, 0, 0, 0, 0, 0, 1} for local network only access. # See the documentation on https://hexdocs.pm/plug_cowboy/Plug.Cowboy.html # for details about using IPv6 vs IPv4 and loopback vs public addresses. ip: {0, 0, 0, 0, 0, 0, 0, 0}, port: port ], secret_key_base: secret_key_base ``` Source: `[error] Could not check origin for Phoenix.Socket transport. Origin of the request: https://live-saas-kit-demo.fly.dev. This happens when you are attempting a socket connection to a different host than the one configured in your config/ files.` 9. Run `fly launch`, but do NOT deploy app because we need to update the Dockerfile 10. Add `nodejs && npm` and add `RUN cd assets && npm install` to Dockerfile Steps 1 & 3 from: https://community.fly.io/t/elixir-getting-started-guide/1356/59 NOTE: Step 2 is already complete in the generated Dockerfile. 11. Run `fly deploy --remote-only` to finish deployment ## Admin Config Additional setup steps from [Fullstack Phoenix](https://fullstackphoenix.com/courses/saas-starter-kit-getting-started/lesson/initial_setup#%2F6=) 1. Add Guardian secrets using `mix guardian.gen.secret` ``` $ fly secrets set GUARDIAN_SECRET_KEY=secret GUARDIAN_SECRET_KEY_ADMINS=secret ``` 2. Create an admin using instructions from [Fullstack Phoenix Admin Area](https://fullstackphoenix.com/courses/saas-starter-kit-getting-started/lesson/admin_area#%2F1=). ## GitHub Actions 1. Delete `.github/wokflows/ci.yml` 2. Create new repo on GitHub 3. Generate Fly API token with `fly auth token` 5. Store value as `FLY_API_TOKEN` in GitHub repository secrets 4. Add `.github/workflows/main.yml` from [hello_fly](https://github.com/staknine/hello_fly/blob/main/.github/workflows/main.yml) project. 6. Merge changes and push to GitHub ## Email Config 1. Sign up for a Mailgun account 2. Add hackney package to `mix.exs` and configure the Mailgun adapter (can uncomment `runtime.config` file). ``` config :demo, Demo.Mailer, adapter: Swoosh.Adapters.Mailgun, api_key: System.get_env("MAILGUN_API_KEY"), domain: System.get_env("MAILGUN_DOMAIN") config :swoosh, :api_client, Swoosh.ApiClient.Hackney ``` 3. Set API Key and Domain as secrets in Fly ``` fly secrets set MAILGUN_API_KEY=my-api-key MAILGUN_DOMAIN=example.com ``` 4. Add authorized recipients (Mailgun sandbox mode only) 5. Update `config.exs` with `from_email`. Also update other company info...