Issue with deploying my wasp app to fly.io
I'm trying to deploy my wasp app to fly.io, but I'm encountering an error that doesn't make sense. When I run wasp start and operate on my localhost, everything works perfectly, but when I run "wasp deploy fly deploy" it goes through an bunch of steps and ends on this error:
Saying that it can't find the path to wasp/auth/types even though this wasn't an issue for the localhost. Can anyone help me with this?
15 Replies
Can you please check that you are running at least Wasp 0.12.4? We had a bug fix related to that import: https://github.com/wasp-lang/wasp/releases/tag/v0.12.4
Run
wasp version
to check your Wasp version.
Upgrade to 0.12.4 by running: curl -sSL https://get.wasp-lang.dev/installer.sh | sh -s -- -v 0.12.4
Optional
If you want to upgrade to 0.13.0 at some point, here are the docs for that as well: https://wasp-lang.dev/docs/migrate-from-0-12-to-0-13Yeah I'm on 0.12.3, so I'll update and try again
Also @miho Is there a way to see the exact code that fly deploys? I upgraded and it successfully deployed, but some of the functionality on my localhost is missing on my deployed website.
Wohooo @rithvik12345678, you just became a Waspeteer level 2!
Wasp generates all the code it deploys to
.wasp/build
folder π you can inspect there the web-app
folder and the server
folders. This is your app π It's just Node.js + React
What is missing for you? Maybe you didn't setup some env variables?It's the login and signup buttons that are missing
DM me your project link if you don't want to share it here π
So @rithvik12345678 needs to modify the server code a bit to execute some code after login / after signup. We have a hooks feature planned (https://github.com/wasp-lang/wasp/issues/1556) but it's not available, yet π¦
So the problem we are facing is: how to modify the outputed code from Wasp to get this custom behaviour.
In dev it's a matter of modifying the
.wasp/out
files. When deploying to Fly, Wasp builds a fresh build in .wasp/build
so those manual changes won't be deployed.
Here's an idea that might work for you:
1. One of the maybe best way to solve this is to have a "patched" versioned of the file you need to modify, somewhere in the project root.
2. Then you provide your own custom Dockerfile
(which can be just the copy paste version of the Dockerfile
in .wasp/build
folder)
3. In that Dockerfile
include a line with something like cp ./my-patched-file.js server/something/somewhere.js
It's quite a bit advanced option, here's some details in the docs: https://wasp-lang.dev/docs/advanced/deployment/overview#customizing-the-dockerfile
Basically, copy-paste the whole Dockerfile to your project root and Wasp will use that file to build your server container instead of the default file.
In your Dockerfile, you now can add the extra cp
command that will copy over the patched file to the built app before deploying it. (I'd suggest doing this at line number 42
just above the npm run bundle
line)
Huh, this is pretty hard-core, I have to say! We should really prioritise the hooks feature. @martinsosOh interesting @miho , so are you saying that I can modify the dockerfile in wasp/out to have a command that copies the modified wasp code from wasp/out into wasp/build and it'll use that to generate the website?
If you have a
Dockerfile
in the project root (the same folder where main.wasp
lives) Wasp will use it when building your server πOh, really? That's pretty convenient
@miho I've bee trying to do what you said. So I moved my modified files to the root directory, I pushed these changes to my github repo, and added these lines to the dockerfile in my root dir:
COPY ./waspchangedcode/createRouter.ts .wasp/build/server/src/auth/providers/oauth/createRouter.ts
COPY ./waspchangedcode/signup.ts .wasp/build/server/src/auth/providers/email/signup.ts
COPY ./waspchangedcode/verifyEmail.ts .wasp/build/server/src/auth/providers/email/verifyEmail.ts
preceding this line:
RUN cd .wasp/build/server && npm run bundle
However everytime I run wasp deploy fly deploy I get this error:
Saying that the file is not found. waspchangedcode is the folder that contains my modified code. I've tried a bunch of things and nothings been able to fix this error. Do you know what's happening?
How does your folder structure look? I'm asking where is your
waspchangedcode
relative to the project root and .wasp
dir?The waspchangedcode is in the app dir and .wasp is also in the app dir
.wasp and waschangedcode are on the same level
Nice, okay that helps π let me try to see how I would do it and then report back
Okay, I got it to work. Here are the steps that I took πββοΈ
My "patch" is just modifying the server's
app.js
file to add some dummy /test
route. I kept my patch files in the src/patches
folder. I'll explain why I had to do that below.
1. I ran wasp build
to get some output in .wasp/build
folder
2. I copied Dockerfile
from .wasp/build
to my project root
3. I added this line at line 37:
4. Then I ran wasp build
to build it again
Now let's test to see if the Dockerfile works π§βπ
1. cd .wasp/build
and then docker build . -t customcode-test
2. Then I run the server with docker run -p 3001:3001 customcode-test
to see if my custom code is there (/test
route should work).
3. I visit http://localhost:3001/test
and I see it works.
Cool, let's see what else you need to know:
1οΈβ£ The missing info for you is: we build the Docker container from the .wasp/build
folder - which makes that folder the "docker build context". You can only work with stuff that are in the context and if I put the "patches" dir at the project root - it won't work. Because the Wasp compiler won't copy that folder, it copies only the stuff it needs. So... what do we do?
2οΈβ£ You need to keep your "patches" folder in the "src" dir because it will get copied to the .wasp/build
folder since Wasp needs the src
folder.
3οΈβ£ I'd advise putting // @ts-ignore
on top of the patch files to avoid getting weird TS compiler errors in dev and when it builds the code.Ok @miho I tried it this way and it all runs successfully and deploys the site, but the actual code I'm trying to change at server/src/auth/providers/ is not actually changing. Once the build is over that code is exactly the same as the default code even though the copying ran successfully.
Make sure you are copying to the correct path π that happened to me while I was trying to get it to work
Yeah I agree regarding the prioritiziation!
Also, having general hooks, that run whatever you give them before/after code generation, would also be helpful in situations like this, when more specific hooks are missing, as a super-general escape hatch.
We also have a GH issue for this.