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

feat(desktop): multi region #4558

Merged
merged 2 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions frontend/desktop/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# next.js
/.next/
/out/

/prisma/**/generated
# production
/build

Expand Down Expand Up @@ -40,4 +40,6 @@ tests/*
.yalc/
yalc.lock

config.yaml
config.yaml
.env
#/prisma/region/generated/
11 changes: 7 additions & 4 deletions frontend/desktop/jest.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ const config = {
// Add more setup options before each test is run
// setupFilesAfterEnv: ['<rootDir>/jest.setup.js'],
moduleNameMapper: {
'^@/(.*)$': '<rootDir>/src/$1'
'^@/(.*)$': '<rootDir>/src/$1',
"^nanoid(/(.*)|$)": "nanoid$1"
},
testSequencer:'./src/__tests__/jest-sequencer.cjs',
testMatch: ['**/__tests__/**/*.test.ts'],
testEnvironment:'node',
maxWorkers: 1
testMatch: ['**/__tests__/**/*.test.ts'],
maxWorkers: 1,
"transformIgnorePatterns": [
"/node_modules/(?!(nanoid)/)"
]
}

// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
Expand Down
14 changes: 14 additions & 0 deletions frontend/desktop/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const path = require('path');
const runtimeCaching = require('next-pwa/cache');
const isProduction = process.env.NODE_ENV === 'production';
const { i18n } = require('./next-i18next.config');

const withPWA = require('next-pwa')({
dest: 'public',
runtimeCaching,
Expand All @@ -12,6 +13,19 @@ const withPWA = require('next-pwa')({
const nextConfig = withPWA({
i18n,
reactStrictMode: false,
async redirects() {
if (isProduction) {
return [
{
source: '/api/dev/:slug',
destination: '/',
permanent: true
}
];
} else {
return [];
}
},
swcMinify: isProduction,
output: 'standalone',
transpilePackages: ['@sealos/ui', 'sealos-desktop-sdk', '@sealos/driver'],
Expand Down
37 changes: 32 additions & 5 deletions frontend/desktop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@
"version": "1.0.0",
"private": true,
"scripts": {
"dev": "next dev",
"dev": "dotenv -e .env.local next dev",
"build": "next build",
"start": "next start",
"lint": "next lint",
"test:e2e": "jest --testPathPattern=/e2e/ --runInBand",
"test:e2e-namespace": "jest --testPathPattern=/e2e/namespace/ --runInBand",
"test:e2e-auth": "jest --testPathPattern=/e2e/auth/ --runInBand",
"test:e2e-api": "jest --testPathPattern=/e2e/v1alpha/ --runInBand",
"test:ci": "jest --runInBand"
"test:ci": "jest --runInBand",
"gen:global": "prisma generate --schema ./prisma/global/schema.prisma",
"gen:region": "prisma generate --schema ./prisma/region/schema.prisma",
"postinstall": "pnpm gen:global && pnpm gen:region"
},
"dependencies": {
"@alicloud/dysmsapi20170525": "^2.0.24",
Expand All @@ -25,12 +28,13 @@
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@kubernetes/client-node": "^0.18.1",
"@prisma/client": "^5.10.2",
"@sealos/driver": "workspace:^",
"@sealos/ui": "workspace:^",
"@tanstack/react-query": "^4.35.3",
"axios": "^1.5.1",
"clsx": "^1.2.1",
"cors": "^2.8.5",
"cors": "^2.8.5",
"dayjs": "^1.11.10",
"eslint": "8.38.0",
"eslint-config-next": "13.3.0",
Expand All @@ -40,7 +44,9 @@
"js-cookie": "^3.0.5",
"js-yaml": "^4.1.0",
"jsonwebtoken": "^9.0.2",
"jwt-decode": "^4.0.0",
"lodash": "^4.17.21",
"minio": "^7.1.3",
"mongodb": "^5.9.0",
"nanoid": "^4.0.2",
"next": "13.3.0",
Expand All @@ -56,25 +62,46 @@
"react-i18next": "^12.3.1",
"sass": "^1.68.0",
"sealos-desktop-sdk": "workspace:*",
"sharp": "^0.32.6",
"uuid": "^9.0.1",
"xml2js": "^0.6.2",
"zustand": "^4.4.1"
},
"devDependencies": {
"@testing-library/jest-dom": "^6.1.3",
"@testing-library/react": "^14.0.0",
"@types/jest": "^29.5.5",
"@types/jest": "^29.5.10",
"@types/js-cookie": "^3.0.4",
"@types/js-yaml": "^4.0.6",
"@types/jsonwebtoken": "^9.0.3",
"@types/lodash": "^4.14.199",
"@types/minio": "^7.1.1",
"@types/node": "18.15.11",
"@types/nprogress": "^0.2.1",
"@types/react": "18.2.37",
"@types/react-dom": "18.0.11",
"@types/uuid": "^9.0.4",
"dotenv-cli": "^7.3.0",
"jest": "^29.7.0",
"jest-environment-jsdom": "^29.7.0",
"prettier": "^2.8.8"
"prettier": "^2.8.8",
"prisma": "^5.10.2"
},
"pnpm": {
"supportedArchitectures": {
"os": [
"win32",
"darwin",
"current",
"linuxmusl"
],
"cpu": [
"x64",
"arm64"
],
"libc": [
"musl"
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
-- CreateEnum
CREATE TYPE "ProviderType" AS ENUM ('PHONE', 'GITHUB', 'WECHAT', 'GOOGLE', 'PASSWORD');

-- CreateTable
CREATE TABLE "OauthProvider" (
"uid" UUID NOT NULL DEFAULT gen_random_uuid(),
"userUid" UUID NOT NULL,
"createdAt" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMPTZ(3) NOT NULL,
"providerType" "ProviderType" NOT NULL,
"providerId" STRING NOT NULL,
"password" STRING,

CONSTRAINT "OauthProvider_pkey" PRIMARY KEY ("uid")
);

-- CreateTable
CREATE TABLE "Region" (
"uid" UUID NOT NULL DEFAULT gen_random_uuid(),
"displayName" STRING NOT NULL,
"location" STRING NOT NULL,
"domain" STRING NOT NULL,
"description" STRING,

CONSTRAINT "Region_pkey" PRIMARY KEY ("uid")
);

-- CreateTable
CREATE TABLE "Account" (
"userUid" UUID NOT NULL DEFAULT gen_random_uuid(),
"activityBonus" INT8 NOT NULL,
"encryptBalance" STRING NOT NULL,
"encryptDeductionBalance" STRING NOT NULL,
"created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"create_region_id" STRING NOT NULL,
"balance" INT8,
"deduction_balance" INT8,

CONSTRAINT "Account_pkey" PRIMARY KEY ("userUid")
);

-- CreateTable
CREATE TABLE "ErrorPaymentCreate" (
"userUid" UUID NOT NULL,
"regionUid" UUID NOT NULL,
"created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"regionUserOwner" STRING NOT NULL,
"method" STRING NOT NULL,
"amount" INT8 NOT NULL,
"gift" INT8,
"trade_no" STRING NOT NULL,
"code_url" STRING,
"invoiced_at" BOOL DEFAULT false,
"remark" STRING,
"message" STRING NOT NULL,
"create_time" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP
);

-- CreateTable
CREATE TABLE "Payment" (
"id" STRING NOT NULL,
"userUid" UUID NOT NULL,
"regionUid" UUID NOT NULL,
"created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"regionUserOwner" STRING NOT NULL,
"method" STRING NOT NULL,
"amount" INT8 NOT NULL,
"gift" INT8,
"trade_no" STRING NOT NULL,
"code_url" STRING,
"invoiced_at" BOOL DEFAULT false,
"remark" STRING,
"message" STRING NOT NULL,

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

-- CreateTable
CREATE TABLE "TransferAccountV1" (
"regionUid" UUID NOT NULL,
"regionUserOwner" STRING NOT NULL,
"userUid" UUID NOT NULL DEFAULT gen_random_uuid(),
"activityBonus" INT8 NOT NULL,
"encryptBalance" STRING NOT NULL,
"encryptDeductionBalance" STRING NOT NULL,
"created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"create_region_id" STRING NOT NULL,
"balance" INT8,
"deduction_balance" INT8,

CONSTRAINT "TransferAccountV1_pkey" PRIMARY KEY ("userUid")
);

-- CreateTable
CREATE TABLE "User" (
"uid" UUID NOT NULL DEFAULT gen_random_uuid(),
"createdAt" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMPTZ(3) NOT NULL,
"avatarUri" STRING NOT NULL,
"nickname" STRING NOT NULL,
"id" STRING NOT NULL,
"name" STRING NOT NULL,

CONSTRAINT "User_pkey" PRIMARY KEY ("uid")
);

-- CreateTable
CREATE TABLE "ErrorAccountCreate" (
"userUid" UUID NOT NULL DEFAULT gen_random_uuid(),
"activityBonus" INT8 NOT NULL,
"encryptBalance" STRING NOT NULL,
"encryptDeductionBalance" STRING NOT NULL,
"created_at" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"create_region_id" STRING NOT NULL,
"balance" INT8,
"deduction_balance" INT8,
"userCr" STRING NOT NULL,
"error_time" TIMESTAMPTZ(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"regionUid" UUID NOT NULL,
"regionUserOwner" STRING NOT NULL,
"message" STRING NOT NULL,

CONSTRAINT "ErrorAccountCreate_pkey" PRIMARY KEY ("userUid")
);

-- CreateTable
CREATE TABLE "NullUserRecord" (
"crName" STRING NOT NULL,
"region_id" STRING NOT NULL
);

-- CreateIndex
CREATE INDEX "OauthProvider_userUid_idx" ON "OauthProvider"("userUid");

-- CreateIndex
CREATE UNIQUE INDEX "OauthProvider_providerId_providerType_key" ON "OauthProvider"("providerId", "providerType");

-- CreateIndex
CREATE UNIQUE INDEX "ErrorPaymentCreate_trade_no_key" ON "ErrorPaymentCreate"("trade_no");

-- CreateIndex
CREATE UNIQUE INDEX "Payment_trade_no_key" ON "Payment"("trade_no");

-- CreateIndex
CREATE UNIQUE INDEX "User_id_key" ON "User"("id");

-- CreateIndex
CREATE UNIQUE INDEX "User_name_key" ON "User"("name");

-- CreateIndex
CREATE UNIQUE INDEX "ErrorAccountCreate_userCr_key" ON "ErrorAccountCreate"("userCr");

-- CreateIndex
CREATE UNIQUE INDEX "NullUserRecord_crName_key" ON "NullUserRecord"("crName");
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
Warnings:

- You are about to drop the `NullUserRecord` table. If the table is not empty, all the data it contains will be lost.
- You are about to drop the `TransferAccountV1` table. If the table is not empty, all the data it contains will be lost.

*/
-- DropTable
DROP TABLE "NullUserRecord";

-- DropTable
DROP TABLE "TransferAccountV1";
3 changes: 3 additions & 0 deletions frontend/desktop/prisma/global/migrations/migration_lock.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Please do not edit this file manually
# It should be added in your version-control system (i.e. Git)
provider = "cockroachdb"