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

Docs: Add Fly.io deployment guide #982

Closed
wants to merge 4 commits into from

Conversation

bogdaaamn
Copy link
Contributor

What does it do?

Added a deployment guide for Fly.io and Postgres. Pinging the Fly folks just in case they have better solutions to this @michaeldwan @jeromegn @lubien @ThisIsRahmat

Why is it needed?

n/a

Related issue(s)/PR(s)

n/a

@vercel
Copy link

vercel bot commented Jul 1, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
documentation ✅ Ready (Inspect) Visit Preview Jul 1, 2022 at 7:15AM (UTC)

@lubien
Copy link

lubien commented Jul 1, 2022

Posting the link here for simplicity: https://documentation-git-fork-bogdaaamn-docs-fly-deplo-460c6b-strapijs.vercel.app/developer-docs/latest/setup-deployment-guides/deployment/hosting-guides/fly.html

I'm not used to Strapi but just read it and that's really awesome work, well done @bogdaaamn

@jeromegn
Copy link

jeromegn commented Jul 1, 2022

Looks great to me!

@pwizla pwizla added source: Dev Docs PRs/issues targeting the Developer Docs pr: new content PRs for new product features or new documentation sections target: v4 Documentation PRs/issues targeting content from docs.strapi.io (main branch). size: large If the PR includes 1+ file(s) with a total of 50+ lines of text or 100+ lines of code labels Jul 4, 2022
@pwizla
Copy link
Collaborator

pwizla commented Jul 20, 2022

Thank you very much for creating this @bogdaaamn, and apologies for my late reply.
This PR is on hold as the Strapi documentation team is currently considering moving 3rd party deployment guides out of the main documentation repo. We will keep you posted in the upcoming weeks. Thank you for your understanding.

@pwizla pwizla added the status: on-hold Not currently planned label Jul 20, 2022
@nk9
Copy link

nk9 commented Aug 14, 2022

I followed these instructions from scratch and everything seemed to work right up until the very end. Once I used fly deploy, I can see Strapi start in the logs:

2022-08-14T15:37:31.121 app[f16735ed] lhr [info] $ strapi start
2022-08-14T15:37:34.484 app[f16735ed] lhr [info] [2022-08-14 15:37:34.481] info: The Users & Permissions plugin automatically generated a jwt secret and stored it in .env under the name JWT_SECRET.
2022-08-14T15:37:34.704 app[f16735ed] lhr [info] Project information
2022-08-14T15:37:34.718 app[f16735ed] lhr [info] ┌────────────────────┬──────────────────────────────────────────────────┐
2022-08-14T15:37:34.718 app[f16735ed] lhr [info] │ Time │ Sun Aug 14 2022 15:37:34 GMT+0000 (Coordinated … │
2022-08-14T15:37:34.718 app[f16735ed] lhr [info] │ Launched in │ 1561 ms │
2022-08-14T15:37:34.718 app[f16735ed] lhr [info] │ Environment │ development │
2022-08-14T15:37:34.718 app[f16735ed] lhr [info] │ Process PID │ 535 │
2022-08-14T15:37:34.718 app[f16735ed] lhr [info] │ Version │ 4.3.4 (node v15.14.0) │
2022-08-14T15:37:34.718 app[f16735ed] lhr [info] │ Edition │ Community │
2022-08-14T15:37:34.718 app[f16735ed] lhr [info] └────────────────────┴──────────────────────────────────────────────────┘
2022-08-14T15:37:34.718 app[f16735ed] lhr [info] Actions available
2022-08-14T15:37:34.718 app[f16735ed] lhr [info] One more thing...
2022-08-14T15:37:34.719 app[f16735ed] lhr [info] Create your first administrator 💻 by going to the administration panel at:
2022-08-14T15:37:34.720 app[f16735ed] lhr [info] ┌─────────────────────────────┐
2022-08-14T15:37:34.720 app[f16735ed] lhr [info] │ http://localhost:8080/admin │
2022-08-14T15:37:34.720 app[f16735ed] lhr [info] └─────────────────────────────┘ 

But of course, I can't access the administrator panel using localhost. Visiting https://my-app.fly.dev:8080/admin fails immediately, and both https://my-app.fly.dev/admin and https://my-app.fly.dev/ just spin for a long time before timing out.

The guide says "continue using Strapi as you would normally do, or follow the Quick Start Guide - Strapi Developer Docs." So I visited the Quick Start Guide, and the very first step is yarn create strapi-app my-project --quickstart, which I've already done. The next step is to connect to the local server and set up an admin account, which… see above.

Fly.io seems to be unhappy:

1 desired, 1 placed, 0 healthy, 1 unhealthy [health checks: 1 total, 1 critical] 

Ultimately, the deploy fails with:

--> v0 failed - Failed due to unhealthy allocations - no stable job version to auto revert to and deploying as v1

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

And under Monitoring, about 5 minutes after starting the VM, I see this:

2022-08-14T17:07:33.942 runner[2fe10c23] lhr [info] Shutting down virtual machine
2022-08-14T17:07:34.027 app[2fe10c23] lhr [info] Sending signal SIGINT to main child process w/ PID 516
2022-08-14T17:07:35.031 app[2fe10c23] lhr [info] Main child exited with signal (with signal 'SIGINT', core dumped? false)
2022-08-14T17:07:35.032 app[2fe10c23] lhr [info] Starting clean up. 

And yet, on the Overview of the app, it says the container is "Running" and it's green.

Screenshot 2022-08-14 at 18 18 23

I'm not sure at this point if I've done something wrong, or if this is expected and I just need to follow some different set of steps.

When I try the last step in the guide and attempt to run a local copy to test with, I get this error:

🕙 17:02:55 ❯ yarn develop
This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:
Error: @strapi/admin tried to access react-select, but it isn't declared in its dependencies; this makes the require call ambiguous and unsound.

Required package: react-select (via "react-select/animated")
Required by: @strapi/admin@npm:4.3.4 (via /Users/nick/Projects/nhm/nhm-learning-backend/.yarn/cache/@strapi-admin-npm-4.3.4-a96a31a86e-a0c64f8199.zip/node_modules/@strapi/admin/)

Require stack:
- /Users/nick/Projects/nhm/nhm-learning-backend/.yarn/cache/@strapi-admin-npm-4.3.4-a96a31a86e-a0c64f8199.zip/node_modules/@strapi/admin/webpack.alias.js
- /Users/nick/Projects/nhm/nhm-learning-backend/.yarn/cache/@strapi-admin-npm-4.3.4-a96a31a86e-a0c64f8199.zip/node_modules/@strapi/admin/webpack.config.js
- /Users/nick/Projects/nhm/nhm-learning-backend/.yarn/cache/@strapi-admin-npm-4.3.4-a96a31a86e-a0c64f8199.zip/node_modules/@strapi/admin/utils/get-custom-webpack-config.js
- /Users/nick/Projects/nhm/nhm-learning-backend/.yarn/cache/@strapi-admin-npm-4.3.4-a96a31a86e-a0c64f8199.zip/node_modules/@strapi/admin/utils/index.js
- /Users/nick/Projects/nhm/nhm-learning-backend/.yarn/cache/@strapi-admin-npm-4.3.4-a96a31a86e-a0c64f8199.zip/node_modules/@strapi/admin/index.js
- /Users/nick/Projects/nhm/nhm-learning-backend/.yarn/unplugged/@strapi-strapi-npm-4.3.4-47b8e573ce/node_modules/@strapi/strapi/lib/commands/builders/admin.js
- /Users/nick/Projects/nhm/nhm-learning-backend/.yarn/unplugged/@strapi-strapi-npm-4.3.4-47b8e573ce/node_modules/@strapi/strapi/lib/commands/builders/index.js
- /Users/nick/Projects/nhm/nhm-learning-backend/.yarn/unplugged/@strapi-strapi-npm-4.3.4-47b8e573ce/node_modules/@strapi/strapi/lib/commands/develop.js
- /Users/nick/Projects/nhm/nhm-learning-backend/.yarn/unplugged/@strapi-strapi-npm-4.3.4-47b8e573ce/node_modules/@strapi/strapi/bin/strapi.js
    at Function.external_module_.Module._resolveFilename (/Users/nick/Projects/nhm/nhm-learning-backend/.pnp.cjs:26995:55)
    at Function.resolve (node:internal/modules/cjs/helpers:108:19)
    at /Users/nick/Projects/nhm/nhm-learning-backend/.yarn/cache/@strapi-admin-npm-4.3.4-a96a31a86e-a0c64f8199.zip/node_modules/@strapi/admin/webpack.alias.js:51:25
    at Array.reduce (<anonymous>)
    at Object.<anonymous> (/Users/nick/Projects/nhm/nhm-learning-backend/.yarn/cache/@strapi-admin-npm-4.3.4-a96a31a86e-a0c64f8199.zip/node_modules/@strapi/admin/webpack.alias.js:50:12)
    at Module._compile (node:internal/modules/cjs/loader:1103:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1157:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.external_module_.Module._load (/Users/nick/Projects/nhm/nhm-learning-backend/.pnp.cjs:26844:14)
    at Module.require (node:internal/modules/cjs/loader:1005:19)

My guess is that this is unrelated, since it seems to actually start running on Fly.io, but I thought I should mention it. (And I haven't figured out a solution yet.) UPDATE: I have successfully gotten Strapi running locally using npm install && npm run devlop, so it would appear that this is probably a red herring.

So my feedback is: it would be helpful for the guide to explain the state your environment should be in at the end (maybe with a Fly.io screenshot?), and give more precise instructions on where to go next to continue setup. And maybe some troubleshooting steps for common issues.

@lubien
Copy link

lubien commented Aug 14, 2022

@nk9 I'm not used t Stripe but I think I have a guess that the reason it's erroring for failing allocations is that your fly.toml listens to a port different to 8080. You logs say your server is on port 8080, the internal_port should be the same.

So we don't spam this PR I'd suggest you bring that message to https://community.fly.io/ where we can help you debug this :)

@nk9
Copy link

nk9 commented Aug 14, 2022

Indeed, the problem is that the generated fly.toml has this section:

[env]
  PORT = "8080"

That's setting Strapi to listen on port 8080, but the Dockerfile exports 1337 and the internal_port is also set to 1337. Once I changed the PORT env var in fly.toml line 9 to 1337, the Fly.io deploy worked!

Also, as @lubien pointed out in the fly.io community thread, the Dockerfile is using a node base image, and so there's no need for this part of the fly.toml either:

[build]
  builder = "heroku/buildpacks:20"

And in fact, when I removed that, Strapi actually built differently. (A local .yarnrc.yml which I added to try to resolve strapi/strapi#14099 was being ignored until I removed the builder.) So it's probably a good idea to remove that.

Lastly, I see that the Docker image produced by this Dockerfile is 2.8GB.

deployment-1660507819: digest: sha256:6bc314f2ae6003270e53a69e391b0804857c121ce41f675bca83c41d0f362dd3 size: 3687
--> Pushing image done
image: registry.fly.io/my-app:deployment-1660507819
image size: 2.8 GB

That seems extremely chunky! Would it be possible to employ multi-stage builds to trim that down? And possibly a slimmer base image like node:16-alpine? There are a number of suggestions in that Snyk link which are worth considering, including to not use CMD ["yarn", "start"].

@bogdaaamn
Copy link
Contributor Author

Very good insights @nk9 @lubien, thanks a lot!! I will also spend some time on a more efficient build, it's indeed too much 😂

@stb13579
Copy link
Contributor

Hello @bogdaaamn, Thank you for your contribution. We are moving community deployment guides to the forum. In the next few days, I will move your guide there and close this PR. Thanks again for your contribution to the Strapi project.

@bogdaaamn
Copy link
Contributor Author

Thank you @StrapiShaun! Noted. There are a few changes I would like to make, but I will wait for the migration and then figure out the best way to do it

@stb13579
Copy link
Contributor

@bogdaaamn The guide is now in the community forum. I had to make some formatting changes since the callouts and code groups from the documentation do not work in the forum. Thanks for your contribution and please let me know if you have any questions.

@stb13579 stb13579 closed this Sep 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: new content PRs for new product features or new documentation sections size: large If the PR includes 1+ file(s) with a total of 50+ lines of text or 100+ lines of code source: Dev Docs PRs/issues targeting the Developer Docs status: on-hold Not currently planned target: v4 Documentation PRs/issues targeting content from docs.strapi.io (main branch).
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants