Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Migrate from Heroku to Fly.io #52

Closed
4 tasks done
nelsonic opened this issue Nov 29, 2022 · 9 comments
Closed
4 tasks done

Chore: Migrate from Heroku to Fly.io #52

nelsonic opened this issue Nov 29, 2022 · 9 comments

Comments

@nelsonic
Copy link
Member

nelsonic commented Nov 29, 2022

In light of Heroku discontinuing "hobby" apps dwyl/learn-heroku#52
We are migrating our apps off Heroku to Fly.io

Only do this after #54

Todo

  • Create new org for the demo app on Fly.io: dwyl-phoenix-todo-list-tutorial
  • Create new app
  • Deploy the app using fly launch
  • Update the docs in the README.md
@nelsonic
Copy link
Member Author

nelsonic commented Dec 9, 2022

"Your user is currently restricted to one organization"

image

🙄

Common issue: https://community.fly.io/t/restricted-to-one-organization/6978/13

@nelsonic
Copy link
Member Author

nelsonic commented Dec 9, 2022

new org: dwyl-phoenix-todo-list-tutorial 🆕
both @LuchoTurtle and @SimonLab invited. 📥

Steps to deploy:

First ensure you have flyctl installed: https://fly.io/docs/hands-on/install-flyctl/ then run:

flyctl auth login

Once logged in, run:

fly launch

Accept all the defaults and set the app name to: phxtodo
Select the dwyl-phoenix-todo-list-tutorial organisation.

Once that is done, git commit the newly created files.

@nelsonic
Copy link
Member Author

nelsonic commented Dec 9, 2022

PR: #59

@nelsonic
Copy link
Member Author

nelsonic commented Dec 9, 2022

Having a bit of trouble deploying:

Crash dump is being written to: erl_crash.dump...,83,69,10>>},[{elixir_eval,'__FILE__',1,[{file,"/app/releases/1.17.0/runtime.exs"},{line,26}]},{elixir,'-eval_external_handler/1-fun-2-',4,[{file,"src/elixir.erl"},{line,298},{error_info,#{module=>'Elixir.Exception'}}]},{erl_eval,do_apply,7,[{file,"erl_eval.erl"},{line,748}]},{erl_eval,expr,6,[{file,"erl_eval.erl"},{line,492}]},{erl_eval,exprs,6,[{file,"erl_eval.erl"},{line,136}]},{elixir,eval_forms,3,[{file,"src/elixir.erl"},{line,288}]},{'Elixir.Module.ParallelChecker',verify,1,[{file,"lib/module/parallel_checker.ex"},{line,107}]},{'Elixir.Code',validated_eval_string,3,[{file,"lib/code.ex"},{line,422}]}]}}
	 init terminating in do_boot ({,[{elixir_eval,__FILE__,1,[{_},{_}]},{elixir,-eval_external_handler/1-fun-2-,4,[{_},{_},{_}]},{erl_eval,do_apply,7,[{_},{_}]},{erl_eval,expr,6,[{_},{_}]},{erl_eval,exprs,6,[{_},{_}]},{elixir,eval_forms,3,[{_},{_}]},{Elixir.Module.ParallelChecker,verify,1,[{_},{_}]},{Elixir.Code,validated_eval_string,3,[{_},{_}]}]})
	 Crash dump is being written to: erl_crash.dump...done
	 Starting clean up.
	 Starting instance
	 Configuring virtual machine
	 Pulling container image
	 Unpacking image
	 Preparing kernel init
	 Configuring firecracker
	 Starting virtual machine
	 Starting init (commit: f447594)...
	 Setting up swapspace version 1, size = 512 MiB (536866816 bytes)
	 no label, UUID=f8302239-d6d9-457f-affc-998eb06d4757
	 Preparing to run: `/app/bin/migrate` as nobody
	 2022/12/09 17:51:28 listening on [fdaa:0:fe1f:a7b:7e:12e6:e186:2]:22 (DNS: [fdaa::3]:53)
	 ERROR! Config provider Config.Reader failed with:
	 ** (RuntimeError) environment variable DATABASE_URL is missing.
	 For example: ecto://USER:PASS@HOST/DATABASE
	     /app/releases/1.17.0/runtime.exs:26: (file)
	     (elixir 1.14.1) src/elixir.erl:298: anonymous fn/4 in :elixir.eval_external_handler/1
	     (stdlib 4.1.1) erl_eval.erl:748: :erl_eval.do_apply/7
	     (stdlib 4.1.1) erl_eval.erl:492: :erl_eval.expr/6
	     (stdlib 4.1.1) erl_eval.erl:136: :erl_eval.exprs/6
	     (elixir 1.14.1) src/elixir.erl:288: :elixir.eval_forms/3
	     (elixir 1.14.1) lib/module/parallel_checker.ex:107: Module.ParallelChecker.verify/1
	     (elixir 1.14.1) lib/code.ex:422: Code.validated_eval_string/3
	 init terminating in do_boot ({,[{elixir_eval,__FILE__,1,[{_},{_}]},{elixir,-eval_external_handler/1-fun-2-,4,[{_},{_},{_}]},{erl_eval,do_apply,7,[{_},{_}]},{erl_eval,expr,6,[{_},{_}]},{erl_eval,exprs,6,[{_},{_}]},{elixir,eval_forms,3,[{_},{_}]},{Elixir.Module.ParallelChecker,verify,1,[{_},{_}]},{Elixir.Code,validated_eval_string,3,[{_},{_}]}]})

Crash dump is being written to: erl_crash.dump...,83,69,10>>},[{elixir_eval,'__FILE__',1,[{file,"/app/releases/1.17.0/runtime.exs"},{line,26}]},{elixir,'-eval_external_handler/1-fun-2-',4,[{file,"src/elixir.erl"},{line,298},{error_info,#{module=>'Elixir.Exception'}}]},{erl_eval,do_apply,7,[{file,"erl_eval.erl"},{line,748}]},{erl_eval,expr,6,[{file,"erl_eval.erl"},{line,492}]},{erl_eval,exprs,6,[{file,"erl_eval.erl"},{line,136}]},{elixir,eval_forms,3,[{file,"src/elixir.erl"},{line,288}]},{'Elixir.Module.ParallelChecker',verify,1,[{file,"lib/module/parallel_checker.ex"},{line,107}]},{'Elixir.Code',validated_eval_string,3,[{file,"lib/code.ex"},{line,422}]}]}}
	 init terminating in do_boot ({,[{elixir_eval,__FILE__,1,[{_},{_}]},{elixir,-eval_external_handler/1-fun-2-,4,[{_},{_},{_}]},{erl_eval,do_apply,7,[{_},{_}]},{erl_eval,expr,6,[{_},{_}]},{erl_eval,exprs,6,[{_},{_}]},{elixir,eval_forms,3,[{_},{_}]},{Elixir.Module.ParallelChecker,verify,1,[{_},{_}]},{Elixir.Code,validated_eval_string,3,[{_},{_}]}]})
	 Crash dump is being written to: erl_crash.dump...done
	 Starting clean up.
Error release command failed, deployment aborted

@nelsonic
Copy link
Member Author

nelsonic commented Dec 9, 2022

Ran:

flyctl postgres attach 
phxtodo-db is now attached to phxtodo
The following secret was added to phxtodo:
  DATABASE_URL=postgres://phxtodo:pwd@top2.nearest.of.phxtodo-db.internal:5432/phxtodo?sslmode=disable

Now need to add a couple more secrets: https://fly.io/docs/reference/secrets/

Create SECRET_KEY_BASE with the following command:

mix phx.gen.secret
KFlYIG9+w/qK2jJJGrWjVa0J2JT737xwvyyH/bkGnLtQj20+EvWZWDyuHstwz2vz

Don't worry, the this is not the "real" one I used!

followed by:

flyctl secrets set SECRET_KEY_BASE=KFlYIG9+w/qK2jJJGrWjVa0J2JT737xwvyyH/bkGnLtQj20+EvWZWDyuHstwz2vz

That triggered a deploy:

Release v1 created
==> Monitoring deployment
Logs: https://fly.io/apps/phxtodo/monitoring

 1 desired, 1 placed, 0 healthy, 1 unhealthy
--> v1 failed - Failed due to unhealthy allocations - no stable job version to auto revert to and deploying as v2

--> Troubleshooting guide at https://fly.io/docs/getting-started/troubleshooting/
Error abort

Fail ... 🤦‍♂️

Tried a manual deploy:

fly deploy

Looks like it worked:

==> Verifying app config
--> Verified app config
==> Building image
Remote builder fly-builder-green-dust-6146 ready
==> Creating build context
--> Creating build context done
==> Building image with Docker
--> docker host: 20.10.12 linux x86_64
[+] Building 74.9s (0/1)
[+] Building 15.2s (28/28) FINISHED
 => [internal] load remote build context                                                                                                                                                                                                        0.0s
 => copy /context /                                                                                                                                                                                                                             0.2s
 => [internal] load metadata for docker.io/library/debian:bullseye-20220801-slim                                                                                                                                                                0.6s
 => [internal] load metadata for docker.io/hexpm/elixir:1.14.1-erlang-25.1.1-debian-bullseye-20220801-slim                                                                                                                                      0.6s
 => [builder  1/17] FROM docker.io/hexpm/elixir:1.14.1-erlang-25.1.1-debian-bullseye-20220801-slim@sha256:03ba790fed12ff8e4ec4243b66d54802ecc5ae81eec38acfcde4d21feea1193d                                                                      0.0s
 => [stage-1 1/6] FROM docker.io/library/debian:bullseye-20220801-slim@sha256:a811e62769a642241b168ac34f615fb02da863307a14c4432cea8e5a0f9782b8                                                                                                  0.0s
 => CACHED [builder  2/17] RUN apt-get update -y && apt-get install -y build-essential git     && apt-get clean && rm -f /var/lib/apt/lists/*_*                                                                                                 0.0s
 => CACHED [builder  3/17] WORKDIR /app                                                                                                                                                                                                         0.0s
 => CACHED [builder  4/17] RUN mix local.hex --force &&     mix local.rebar --force                                                                                                                                                             0.0s
 => CACHED [builder  5/17] COPY mix.exs mix.lock ./                                                                                                                                                                                             0.0s
 => CACHED [builder  6/17] RUN mix deps.get --only prod                                                                                                                                                                                         0.0s
 => CACHED [builder  7/17] RUN mkdir config                                                                                                                                                                                                     0.0s
 => CACHED [builder  8/17] COPY config/config.exs config/prod.exs config/                                                                                                                                                                       0.0s
 => CACHED [builder  9/17] RUN mix deps.compile                                                                                                                                                                                                 0.0s
 => CACHED [builder 10/17] COPY priv priv                                                                                                                                                                                                       0.0s
 => [builder 11/17] COPY lib lib                                                                                                                                                                                                                0.0s
 => [builder 12/17] COPY assets assets                                                                                                                                                                                                          0.0s
 => [builder 13/17] RUN mix assets.deploy                                                                                                                                                                                                      10.6s
 => [builder 14/17] RUN mix compile                                                                                                                                                                                                             1.1s
 => [builder 15/17] COPY config/runtime.exs config/                                                                                                                                                                                             0.0s
 => [builder 16/17] COPY rel rel                                                                                                                                                                                                                0.0s
 => [builder 17/17] RUN mix release                                                                                                                                                                                                             1.9s
 => CACHED [stage-1 2/6] RUN apt-get update -y && apt-get install -y libstdc++6 openssl libncurses5 locales   && apt-get clean && rm -f /var/lib/apt/lists/*_*                                                                                  0.0s
 => CACHED [stage-1 3/6] RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen                                                                                                                                                       0.0s
 => CACHED [stage-1 4/6] WORKDIR /app                                                                                                                                                                                                           0.0s
 => CACHED [stage-1 5/6] RUN chown nobody /app                                                                                                                                                                                                  0.0s
 => [stage-1 6/6] COPY --from=builder --chown=nobody:root /app/_build/prod/rel/app ./                                                                                                                                                           0.2s
 => exporting to image                                                                                                                                                                                                                          0.3s
 => => exporting layers                                                                                                                                                                                                                         0.3s
 => => writing image sha256:9a746dddbc6d3612b20fa917b72160ee7bdff12afd00641f4f5ddf6a50c39bce                                                                                                                                                    0.0s
 => => naming to registry.fly.io/phxtodo:deployment-01GKW30GDFTVE2G2J930FPZP4Y                                                                                                                                                                  0.0s
--> Building image done
==> Pushing image to fly
The push refers to repository [registry.fly.io/phxtodo]
bde60c1dba5e: Pushed
385455468b69: Layer already exists
40197aa1bfc8: Layer already exists
ba3a395c0822: Layer already exists
8cff46b8b0cb: Layer already exists
92a4e8a3140f: Layer already exists
deployment-01GKW30GDFTVE2G2J930FPZP4Y: digest: sha256:451aceb182844a96903365f8fa3a93e1f0065bb08a235d8ac9f77ee089736c97 size: 1576
--> Pushing image done
image: registry.fly.io/phxtodo:deployment-01GKW30GDFTVE2G2J930FPZP4Y
image size: 124 MB
==> Creating release
--> release v2 created

--> You can detach the terminal anytime without stopping the deployment
==> Release command detected: /app/bin/migrate

--> This release will not be available until the release command succeeds.
	 Starting instance
	 Configuring virtual machine
	 Pulling container image
	 Unpacking image
	 Configuring firecracker
	 2022/12/09 18:42:27 listening on [fdaa:0:fe1f:a7b:7e:2ba7:c7ea:2]:22 (DNS: [fdaa::3]:53)
	 18:42:29.647 [info] == Running 20221205102303 App.Repo.Migrations.CreateItems.change/0 forward
	 Starting clean up.
	 Starting instance
	 Configuring virtual machine
	 Pulling container image
	 Unpacking image
	 Preparing kernel init
	 Configuring firecracker
	 Starting virtual machine
	 Starting init (commit: f447594)...
	 Setting up swapspace version 1, size = 512 MiB (536866816 bytes)
	 no label, UUID=5fec500f-687b-49d6-83d3-99bfc3013bea
	 Preparing to run: `/app/bin/migrate` as nobody
	 2022/12/09 18:42:27 listening on [fdaa:0:fe1f:a7b:7e:2ba7:c7ea:2]:22 (DNS: [fdaa::3]:53)
	 18:42:29.647 [info] == Running 20221205102303 App.Repo.Migrations.CreateItems.change/0 forward
	 18:42:29.651 [info] create table items
	 18:42:29.666 [info] == Migrated 20221205102303 in 0.0s
	 Starting clean up.
==> Monitoring deployment
Logs: https://fly.io/apps/phxtodo/monitoring

 1 desired, 1 placed, 1 healthy, 0 unhealthy [health checks: 1 total, 1 passing]
--> v2 deployed successfully

Next: get AUTH_API_KEY from: https://authdemo.fly.dev/apps/new

flyctl secrets set AUTH_API_KEY=88SwQHTsVbZjEzpvDgH8UuUrbmXetc./88SwQE72ftpwN5SzNbXDK1MSWwwM5Xetc./authdemo.fly.dev

Note: not a valid key.

@nelsonic nelsonic closed this as completed Dec 9, 2022
Repository owner moved this from 🔖 Ready for Development to ✅ Done in dwyl app kanban Dec 9, 2022
@LuchoTurtle LuchoTurtle reopened this Dec 9, 2022
@LuchoTurtle
Copy link
Member

Assigning this to me, so I can change the README to point to the correct link.

@LuchoTurtle LuchoTurtle assigned LuchoTurtle and unassigned nelsonic Dec 9, 2022
@LuchoTurtle LuchoTurtle moved this from ✅ Done to 🏗 In progress in dwyl app kanban Dec 9, 2022
@nelsonic
Copy link
Member Author

nelsonic commented Dec 9, 2022

https://phxtodo.fly.dev/
image

@nelsonic nelsonic moved this from 🏗 In progress to ⏳Awaiting Review in dwyl app kanban Dec 9, 2022
@nelsonic
Copy link
Member Author

nelsonic commented Dec 9, 2022

PR: #59 contains this update including updating all the links from Heroku to https://phxtodo.fly.dev/ 🔗 ✅

@LuchoTurtle
Copy link
Member

Ok

Repository owner moved this from ⏳Awaiting Review to ✅ Done in dwyl app kanban Dec 9, 2022
LuchoTurtle added a commit that referenced this issue Dec 9, 2022
@LuchoTurtle LuchoTurtle unpinned this issue Dec 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

No branches or pull requests

2 participants