wasp-lang / wasp

The fastest way to develop full-stack web apps with React & Node.js.

Home Page:https://wasp-lang.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Not able to deploy docker image on Render

MDSADABWASIM opened this issue · comments

I've this docker file (as generated but with linux/amd64)

# NOTE: Why do we specify alpine version here?
#   Because if not, we had situations where it would use the different version
#   locally and on Github CI. This way we ensure exact version is used,
#   and also have control over updating it (instead of update surprising us).
FROM --platform=linux/amd64 node:18.18.0-alpine3.17 AS node


# We split Dockerfile into base, server-builder and server-production.
# This way we have separate situations -> in server-builder we build all
# we need to run the server, and then in server-production we start fresh
# and just copy what we need from server-builder, avoiding intermediate
# artifacts and any settings / pollution we don't need in production
# but only for building.


FROM node AS base
RUN apk --no-cache -U upgrade # To ensure any potential security patches are applied.


# Todo: The 'server-builder' image stays on disk under <none>:<none> and is
# relatively large (~900 MB), should we remove it? Or is it useful for future
# builds?
FROM base AS server-builder
# Building the Docker image on Apple's Silicon Mac fails without python3 (the build
# throws `node-gyp` errors when it tries to compile native deps. Installing
# `python3` fixes the issue.
RUN apk add --no-cache python3 build-base libtool autoconf automake
WORKDIR /app
# Since the framwork code in /.wasp/build/server imports the user code in /src
# using relative imports, we must mirror the same directory structure in the
# Docker image.
COPY src ./src
COPY package.json .
COPY package-lock.json .
COPY server .wasp/build/server
COPY sdk .wasp/out/sdk
# Install npm packages, resulting in node_modules/.
RUN npm install && cd .wasp/build/server && npm install
# Building the server should come after Prisma generation.
RUN cd .wasp/build/server && npm run bundle


# TODO: Use pm2?
# TODO: Use non-root user (node).
FROM base AS server-production
# In case they want to use python3 in their app.
RUN apk add --no-cache python3
ENV NODE_ENV production
WORKDIR /app
# Copying the top level 'node_modules' because it contains the Prisma packages
# necessary for migrating the database.
COPY --from=server-builder /app/node_modules ./node_modules
# Copying the SDK because 'validate-env.mjs' executes independent of the bundle
# and references the 'wasp' package.
COPY --from=server-builder /app/.wasp/out/sdk .wasp/out/sdk
# Copying 'server/node_modules' because 'validate-env.mjs' executes independent
# of the bundle and references the dotenv package.
COPY --from=server-builder /app/.wasp/build/server/node_modules .wasp/build/server/node_modules
COPY --from=server-builder /app/.wasp/build/server/bundle .wasp/build/server/bundle
COPY --from=server-builder /app/.wasp/build/server/package*.json .wasp/build/server/
COPY --from=server-builder /app/.wasp/build/server/scripts .wasp/build/server/scripts
COPY db/ .wasp/build/db/
EXPOSE ${PORT}
WORKDIR /app/.wasp/build/server
ENTRYPOINT ["npm", "run", "start-production"]


# Any user-defined Dockerfile contents will be appended below.

And when I'm deploying this docker image to Render, it's giving me this error:

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'wasp' imported from /app/.wasp/build/server/scripts/validate-env.mjs

NOTE: I've all the env variables already set in Render

DATABASE_URL
PORT
WASP_SERVER_URL
WASP_WEB_CLIENT_URL

I noticed you removed the following from the Dockerfile:

COPY db/schema.prisma .wasp/build/db/

RUN cd .wasp/build/server && npx prisma generate --schema='../db/schema.prisma'

Why did you have the need to change that? :)

@infomiho I didn't remove it, and didn't make any changes to dockerfile apart from adding linux/amd64.

I think it happened cause i don't need db for my web app (and removed it from main.wasp), it's a static site which just need some APIs for showing info.

But even without it, it should work right?

I've done the following steps:

  • wasp new test
  • cd test
  • Set the PostgreSQL as the db.system in the main.wasp
  • wasp build
  • cd .wasp/build
  • docker build
  • docker run <hash>

This is a set up where the DB is not used.

It seems to work for me locally. How are you deploying the app to Render, could you share a bit more details? Did you connect it to your repo, which folder, which commands etc? Thanks!

I manually created docker image from the generated dockerfile.

You can see the created docker image here: docker pull mdsadabwasim/app-server

And I'm deploying this docker image to render, in which it's saying can't find wasp.

Did you run the wasp build command before doing your deployment? That's what you need to do deploy Wasp apps https://wasp-lang.dev/docs/advanced/deployment/manually

I tried using your Dockerfile and I successfully ran docker build and docker run <hash>.

Yes.

I ran wasp build and then it generated .wasp/build folder with this dockerfile in it.

I was able to deploy web-app to netlify in a minute, but don't know why it's failing for server side deployment.

And in time of development everything worked fine as well.

Obviously we are doing something differently. In order to further debug, I'll nice a bit more information like:

  • which exact commands did you run?
  • in which folder did you run them?
  • what is your Wasp version?
  • if possible, the repository of your project or just the Wasp file

EDIT: I'd recommend going to our Discord and asking the question in the #questions channel since this is more of a debug thread then an issue https://discord.gg/rzdnErX

  • I ran wasp build under app folder

  • Current wasp version is 0.13.2

I'm using opensaas to create it(with some edits), here's the main file:

app ShipAppFast {
  wasp: {
    version: "^0.13.0"
  },
  title: "Ship app fast",
  head: [
        "<meta property='og:type' content='website' />",
        "<meta property='og:title' content='Ship app fast' />",
        "<meta property='og:url' content='https://opensaas.sh' />", 
        "<meta property='og:description' content='Ship app in days not weeks.' />",
        "<meta property='og:image' content='https://opensaas.sh/public-banner.png' />",
        "<meta name='twitter:image' content='https://opensaas.sh/public-banner.png' />", 
        "<meta name='twitter:image:width' content='800' />",
        "<meta name='twitter:image:height' content='400' />",
        "<meta name='twitter:card' content='summary_large_image' />",
  ],
  
  db: { 
   system: PostgreSQL,
  },
  client: {
    rootComponent: import App from "@src/client/App",
  },
  
}

route LandingPageRoute { path: "/", to: LandingPage }
page LandingPage {
  component: import LandingPage from "@src/client/landing-page/LandingPage"
}

route PricingPageRoute { path: "/pricing", to: PricingPage }
page PricingPage {
  component: import PricingPage from "@src/client/app/PricingPage"
}

route CheckoutRoute { path: "/checkout", to: CheckoutPage }
page CheckoutPage {
  component: import Checkout from "@src/client/app/CheckoutPage"
}

/* ⛑ These are the Wasp Operations, which allow the client and server to interact:
 * https://wasp-lang.dev/docs/data-model/operations/overview
 */

// 📝 Actions

action stripePayment {
  fn: import { stripePayment } from "@src/server/actions.js",
}

/*
 * 📡 These are custom Wasp API Endpoints. Use them for callbacks, webhooks, etc.
 * https://wasp-lang.dev/docs/advanced/apis
 */ 

api stripeWebhook {
  fn: import { stripeWebhook } from "@src/server/webhooks/stripe.js",
  middlewareConfigFn: import { stripeMiddlewareFn } from "@src/server/webhooks/stripe.js",
  httpRoute: (POST, "/stripe-webhook")
}

Should I remove db section, cause I don't need it?

I also noticed I'm using 0.13.0 instead of 0.13.2 in main.wasp, maybe that's causing the issue.

and Maybe try to rebuild.

Update: I can't build without db section so I need to add it even though I don't require any db.

I also updated wasp version to 0.13.2 in main.wasp and rebuilt the app but nothing changed.

Thank you for the info, I'll try deploying Open SaaS to Render and see how it goes for me. I'll use your main.wasp file and report back sometime tomorrow.

After rebuilding the docker image from scratch and changing the platform to linux/amd64 (cause render expect this). I'm able to successfully deploy it on Render.

Thanks for the help @infomiho

@MDSADABWASIM I am curious, what exactly do you think was the problem then?

Maybe when I built the docker image it got corrupted somehow.