Skip to content

Commit

Permalink
Mage 0.12 producing 0.11 (wasp-lang#1805)
Browse files Browse the repository at this point in the history
* Upgraded Mage to Wasp 0.12 while producing Wasp 0.11.4 apps.

* Rearranged imports to be nicer.

* Updated tsconfig.json and .gitignore according to new changes to wasp new.
  • Loading branch information
Martinsos authored Feb 26, 2024
1 parent fda10de commit a445da9
Show file tree
Hide file tree
Showing 34 changed files with 9,430 additions and 297 deletions.
4 changes: 4 additions & 0 deletions mage/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
/.wasp/
/.env.server
/.env.client
/node_modules

# We ignore env files recognized and used by Wasp.
.env.server
Expand All @@ -10,5 +13,6 @@
*.env
*.env.*

**/.DS_Store
# Emacs specific
.projectile
1 change: 1 addition & 0 deletions mage/src/.waspignore → mage/.waspignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Ignore editor tmp files
**/*~
**/#*#
.DS_Store
52 changes: 33 additions & 19 deletions mage/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,49 @@ FROM node:18 AS node

FROM node AS base
RUN apt update && apt upgrade -y # To ensure any potential security patches are applied.
# TODO: Remove line below (installation of openssl 1.1) once Prisma adds support for
# openssl 3 on alpine. Alpine >= 3.17 has openssl 3 as default.
# Relevant GH issue: https://github.com/wasp-lang/wasp/issues/877
# RUN apt install openssl1.1-compat


# Any user-defined Dockerfile contents will be appended below.
# 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
WORKDIR /app
COPY server/ ./server/
# 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 cd server && npm install
COPY db/schema.prisma ./db/
RUN cd server && PRISMA_CLIENT_OUTPUT_DIR=../server/node_modules/.prisma/client/ npx prisma generate --schema='../db/schema.prisma'
RUN npm install && cd .wasp/build/server && npm install
COPY db/schema.prisma .wasp/build/db/
RUN cd .wasp/build/server && npx prisma generate --schema='../db/schema.prisma'
# Building the server should come after Prisma generation.
RUN cd server && npm run build
RUN cd .wasp/build/server && npm run bundle


# TODO: Use pm2?
# TODO: Use non-root user (node).
FROM base AS server-production
RUN curl -sSL https://get.wasp-lang.dev/installer.sh | sh -s -- -v 0.12.0
RUN curl -sSL https://get.wasp-lang.dev/installer.sh | sh -s -- -v 0.11.4-wasp-ai-12
ENV PATH "$PATH:/root/.local/bin"
ENV NODE_ENV production
WORKDIR /app
COPY --from=server-builder /app/server/node_modules ./server/node_modules
COPY --from=server-builder /app/server/dist ./server/dist
COPY --from=server-builder /app/server/package*.json ./server/
COPY --from=server-builder /app/server/scripts ./server/scripts
COPY db/ ./db/
# 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/server
# RUN cat /root/.local/bin/wasp
# RUN wasp version
WORKDIR /app/.wasp/build/server
ENTRYPOINT ["npm", "run", "start-production"]
87 changes: 28 additions & 59 deletions mage/main.wasp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
app waspAi {
wasp: {
version: "^0.11.5"
version: "^0.12.0"
},
title: "MAGE - GPT Web App Generator ✨",
head: [
Expand All @@ -14,42 +14,22 @@ app waspAi {
"<meta name=\"twitter:card\" content=\"summary_large_image\" />",
"<script defer data-domain=\"usemage.ai\" src=\"https://plausible.apps.twoducks.dev/js/script.js\"></script>",
],
dependencies: [
("prismjs", "^1.29.0"),
("react-accessible-treeview", "2.6.1"),
("react-icons", "4.10.1"),
("@zip.js/zip.js", "2.7.16"),
("async-mutex", "0.4.0"),
("@headlessui/react", "1.7.15"),
("@heroicons/react", "2.0.18"),
("react-parallax-tilt", "1.7.151"),
("timeago.js", "4.0.2"),
("@visx/mock-data", "3.0.0"),
("@visx/group", "3.0.0"),
("@visx/shape", "3.0.0"),
("@visx/scale", "3.2.0"),
("@visx/responsive", "3.0.0"),
("@visx/gradient", "3.0.0"),
("@visx/axis", "3.2.0"),
("js-confetti", "0.11.0")
],
client: {
rootComponent: import { RootComponent } from "@client/RootComponent.jsx",
rootComponent: import { RootComponent } from "@src/client/RootComponent.jsx",
},
db: {
system: PostgreSQL
system: PostgreSQL,
},
auth: {
userEntity: User,
externalAuthEntity: SocialLogin,
methods: {
gitHub: {
configFn: import { getGitHubAuthConfig } from "@server/auth.js",
getUserFieldsFn: import { getGitHubUserFields } from "@server/auth.js",
configFn: import { getGitHubAuthConfig } from "@src/server/auth.js",
userSignupFields: import { gitHubUserSignupFields } from "@src/server/auth.ts",
},
google: {
configFn: import { getGoogleAuthConfig } from "@server/auth.js",
getUserFieldsFn: import { getGoogleUserFields } from "@server/auth.js",
configFn: import { getGoogleAuthConfig } from "@src/server/auth.js",
userSignupFields: import { googleUserSignupFields } from "@src/server/auth.ts",
},
},
onAuthFailedRedirectTo: "/",
Expand All @@ -59,93 +39,93 @@ app waspAi {

route RootRoute { path: "/", to: MainPage }
page MainPage {
component: import Main from "@client/pages/MainPage.jsx"
component: import Main from "@src/client/pages/MainPage.jsx"
}

route ResultRoute { path: "/result/:appId", to: ResultPage }
page ResultPage {
component: import { ResultPage } from "@client/pages/ResultPage.jsx"
component: import { ResultPage } from "@src/client/pages/ResultPage.jsx"
}

route UserRoute { path: "/user", to: UserPage }
page UserPage {
component: import { UserPage } from "@client/pages/UserPage.jsx",
component: import { UserPage } from "@src/client/pages/UserPage.jsx",
authRequired: true
}

route StatsRoute { path: "/stats", to: StatsPage }
page StatsPage {
component: import { Stats } from "@client/pages/StatsPage.jsx",
component: import { Stats } from "@src/client/pages/StatsPage.jsx",
authRequired: true
}

route FeedbackRoute { path: "/feedback", to: FeedbackPage }
page FeedbackPage {
component: import { Feedback } from "@client/pages/FeedbackPage.jsx",
component: import { Feedback } from "@src/client/pages/FeedbackPage.jsx",
authRequired: true
}

route LoginRoute { path: "/login", to: LoginPage }
page LoginPage {
component: import { LoginPage } from "@client/pages/LoginPage.jsx",
component: import { LoginPage } from "@src/client/pages/LoginPage.jsx",
}

action startGeneratingNewApp {
fn: import { startGeneratingNewApp } from "@server/operations.js",
fn: import { startGeneratingNewApp } from "@src/server/operations.js",
entities: [
Project,
]
}

action registerZipDownload {
fn: import { registerZipDownload } from "@server/operations.js",
fn: import { registerZipDownload } from "@src/server/operations.js",
entities: [Project]
}

action createFeedback {
fn: import { createFeedback } from "@server/operations.js",
fn: import { createFeedback } from "@src/server/operations.js",
entities: [Feedback]
}

action deleteMyself {
fn: import { deleteMyself } from "@server/operations.js",
fn: import { deleteMyself } from "@src/server/operations.js",
entities: [User, Project, File, Log]
}

query getFeedback {
fn: import { getFeedback } from "@server/operations.js",
fn: import { getFeedback } from "@src/server/operations.js",
entities: [Feedback]
}

query getProjectsByUser {
fn: import { getProjectsByUser } from "@server/operations.js",
fn: import { getProjectsByUser } from "@src/server/operations.js",
entities: [Project]
}


query getAppGenerationResult {
fn: import { getAppGenerationResult } from "@server/operations.js",
fn: import { getAppGenerationResult } from "@src/server/operations.js",
entities: [
Project
]
}

query getProjects {
fn: import { getProjects } from "@server/operations.js",
fn: import { getProjects } from "@src/server/operations.js",
entities: [
Project
]
}

query getStats {
fn: import { getStats } from "@server/operations.js",
fn: import { getStats } from "@src/server/operations.js",
entities: [
Project
]
}

query getNumProjects {
fn: import { getNumProjects } from "@server/operations.js",
fn: import { getNumProjects } from "@src/server/operations.js",
entities: [
Project
]
Expand All @@ -154,21 +134,10 @@ query getNumProjects {
entity User {=psl
id Int @id @default(autoincrement())

email String @unique
email String?
username String?
externalAuthAssociations SocialLogin[]
projects Project[]
psl=}

entity SocialLogin {=psl
id String @id @default(uuid())

provider String
providerId String

userId Int
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
createdAt DateTime @default(now())
projects Project[]
psl=}

entity Project {=psl
Expand Down Expand Up @@ -224,7 +193,7 @@ job checkPendingAppsJob {
cron: "* * * * *",
},
perform: {
fn: import { checkForPendingApps } from "@server/jobs/checkForPendingApps.js"
fn: import { checkForPendingApps } from "@src/server/jobs/checkForPendingApps.js"
},
entities: [Project]
}
Expand All @@ -235,15 +204,15 @@ job failStaleAppsJobs {
cron: "* * * * *",
},
perform: {
fn: import { failStaleGenerations } from "@server/jobs/failStaleGenerations.js",
fn: import { failStaleGenerations } from "@src/server/jobs/failStaleGenerations.js",
},
entities: [Project, Log]
}

job generateAppJob {
executor: PgBoss,
perform: {
fn: import { generateApp } from "@server/jobs/generateApp.js",
fn: import { generateApp } from "@src/server/jobs/generateApp.js",
},
entities: [
Project,
Expand Down
44 changes: 44 additions & 0 deletions mage/migrations/20240222151121_new_auth/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
-- CreateTable
CREATE TABLE "Auth" (
"id" TEXT NOT NULL,
"userId" INTEGER,

CONSTRAINT "Auth_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "AuthIdentity" (
"providerName" TEXT NOT NULL,
"providerUserId" TEXT NOT NULL,
"providerData" TEXT NOT NULL DEFAULT '{}',
"authId" TEXT NOT NULL,

CONSTRAINT "AuthIdentity_pkey" PRIMARY KEY ("providerName","providerUserId")
);

-- CreateTable
CREATE TABLE "Session" (
"id" TEXT NOT NULL,
"expiresAt" TIMESTAMP(3) NOT NULL,
"userId" TEXT NOT NULL,

CONSTRAINT "Session_pkey" PRIMARY KEY ("id")
);

-- CreateIndex
CREATE UNIQUE INDEX "Auth_userId_key" ON "Auth"("userId");

-- CreateIndex
CREATE UNIQUE INDEX "Session_id_key" ON "Session"("id");

-- CreateIndex
CREATE INDEX "Session_userId_idx" ON "Session"("userId");

-- AddForeignKey
ALTER TABLE "Auth" ADD CONSTRAINT "Auth_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "AuthIdentity" ADD CONSTRAINT "AuthIdentity_authId_fkey" FOREIGN KEY ("authId") REFERENCES "Auth"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Session" ADD CONSTRAINT "Session_userId_fkey" FOREIGN KEY ("userId") REFERENCES "Auth"("id") ON DELETE CASCADE ON UPDATE CASCADE;
17 changes: 17 additions & 0 deletions mage/migrations/20240223170839_remove_old_auth/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
Warnings:
- You are about to drop the `SocialLogin` table. If the table is not empty, all the data it contains will be lost.
*/
-- DropForeignKey
ALTER TABLE "SocialLogin" DROP CONSTRAINT "SocialLogin_userId_fkey";

-- DropIndex
DROP INDEX "User_email_key";

-- AlterTable
ALTER TABLE "User" ALTER COLUMN "email" DROP NOT NULL;

-- DropTable
DROP TABLE "SocialLogin";
Loading

0 comments on commit a445da9

Please sign in to comment.