Skip to content

Commit

Permalink
Merged from main
Browse files Browse the repository at this point in the history
  • Loading branch information
bjsilva1 committed May 13, 2024
2 parents 8654138 + 550b672 commit f74c9bb
Show file tree
Hide file tree
Showing 15 changed files with 3,131 additions and 69 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ jobs:
strategy:
matrix:
node-version: [20.x]
env:
AWS_ACCESS_KEY_ID: '${{ secrets.AWS_ACCESS_KEY_ID }}'
AWS_SECRET_ACCESS_KEY: '${{ secrets.AWS_SECRET_ACCESS_KEY }}'
DATABASE_URL: '${{ secrets.DATABASE_URL }}'
NODE_ENV: 'production'
steps:
- uses: actions/checkout@v4

Expand All @@ -24,7 +29,4 @@ jobs:
args: -c "cd ./apps/server && serverless deploy --stage production"
entrypoint: /bin/sh

env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
DATABASE_URL: ${{ secrets.DATABASE_URL }}

3,028 changes: 3,028 additions & 0 deletions apps/server/certs/global-bundle.pem

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion apps/server/serverless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,15 @@ const serverlessConfiguration: AWS = {
environment: {
AWS_NODEJS_CONNECTION_REUSE_ENABLED: "1",
NODE_OPTIONS: "--enable-source-maps --stack-trace-limit=1000",
DATABASE_URL: process.env.DATABASE_URL,
},
},
// import the function via paths
functions: functions,
package: { individually: true },
package: {
individually: true,
include: ["certs/*", "src/functions/cron/*"],
},
custom: {
esbuild: {
bundle: true,
Expand Down
20 changes: 17 additions & 3 deletions apps/server/src/functions/cron/getWeeklyHandler.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
import fs from "fs";
import path from "path";
import { format } from "date-fns";
import { logger } from "logger";

import { getWeekInfo } from "@zotmeal/api";
import { createDrizzle, pool } from "@zotmeal/db";
import { restaurantNames } from "@zotmeal/utils";

const connectionString = process.env.DATABASE_URL;
import { env } from "../env";

const isProduction = process.env.NODE_ENV === "production";
const connectionString = env.DATABASE_URL;
const sslConfig = isProduction
? {
rejectUnauthorized: false,
ca: fs.readFileSync(
path.join(__dirname, "../../../certs", "global-bundle.pem").toString(),
),
}
: null;
export const main = async (_event, _context) => {
try {
const db = createDrizzle({ connectionString });

const db = createDrizzle({
connectionString,
ssl: sslConfig,
});
logger.info(`Start get weekly job...`);

const date = format(new Date(), "MM/dd/yyyy");
Expand Down
2 changes: 0 additions & 2 deletions apps/server/src/functions/cron/testLog.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { format } from "date-fns";

import { env } from "../env";

export const main = async (event, context) => {
try {
const now = new Date();
Expand Down
20 changes: 17 additions & 3 deletions apps/server/src/functions/cron/updateDailyHandler.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
import fs from "fs";
import path from "path";
import { format } from "date-fns";

import { updateDaily, UpdateDailyParams } from "@zotmeal/api";
import { createDrizzle, pool } from "@zotmeal/db";
import { restaurantNames } from "@zotmeal/utils";

import { logger } from "../../../logger";
import { env } from "../env";

const connectionString = process.env.DATABASE_URL;

const isProduction = process.env.NODE_ENV === "production";
const connectionString = env.DATABASE_URL;
const sslConfig = isProduction
? {
rejectUnauthorized: false,
ca: fs.readFileSync(
path.join(__dirname, "../../../certs", "global-bundle.pem").toString(),
),
}
: null;
export const main = async (_event, _context) => {
try {
const db = createDrizzle({ connectionString });
const db = createDrizzle({
connectionString,
ssl: sslConfig,
});
logger.info("Start update daily job...");

const date = format(new Date(), "MM/dd/yyyy");
Expand Down
10 changes: 6 additions & 4 deletions apps/server/src/functions/env.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import dotenv from "dotenv";
import { z } from "zod";

dotenv.config({
path: "../../../../.env",
});
if (process.env.NODE_ENV !== "production") {
dotenv.config({
path: "../../../../.env",
});
}
const envSchema = z.object({
DATABASE_URL: z.string(),
});

const env = envSchema.parse(process.env);

export { env };
2 changes: 2 additions & 0 deletions apps/server/src/functions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const functions: AWS["functions"] = {
},
getWeekly: {
handler: "src/functions/cron/getWeeklyHandler.main",
timeout: 600,
events: [
{
schedule: {
Expand All @@ -39,6 +40,7 @@ export const functions: AWS["functions"] = {
},
updateDaily: {
handler: "src/functions/cron/updateDailyHandler.main",
timeout: 600,
events: [
{
schedule: {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
"typecheck": "turbo typecheck"
},
"devDependencies": {
"@zotmeal/prettier-config": "workspace:^0.1.0",
"@turbo/gen": "^1.13.2",
"@zotmeal/prettier-config": "workspace:^0.1.0",
"prettier": "^3.2.5",
"ts-node": "^10.9.2",
"turbo": "^1.13.2",
"typescript": "^5.4.3"
},
Expand Down
3 changes: 2 additions & 1 deletion packages/db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"pino-pretty": "^11.0.0",
"postgres": "^3.4.4",
"tsx": "^4.7.1",
"zod": "^3.22.4"
"zod": "^3.22.4",
"@zotmeal/tsconfig": "workspace:^0.1.0"
}
}
2 changes: 2 additions & 0 deletions packages/db/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { exec } from "child_process";
import fs from "fs";
import path from "path";
import { promisify } from "util";
import type { PoolConfig } from "pg";
import { drizzle } from "drizzle-orm/node-postgres";
Expand Down
3 changes: 2 additions & 1 deletion packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"react-hook-form": "^7.51.2",
"sonner": "^1.4.41",
"tailwind-merge": "^2.2.2",
"tailwindcss-animate": "^1.0.7"
"tailwindcss-animate": "^1.0.7",
"@zotmeal/tsconfig": "workspace:^0.1.0"
},
"devDependencies": {
"@types/react": "^18.2.63",
Expand Down
3 changes: 2 additions & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
},
"prettier": "@zotmeal/prettier-config",
"dependencies": {
"vitest": "^1.4.0"
"vitest": "^1.4.0",
"@zotmeal/tsconfig": "workspace:^"
}
}
3 changes: 2 additions & 1 deletion packages/validators/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"dependencies": {
"@zotmeal/db": "workspace:^",
"@zotmeal/utils": "workspace:^",
"zod": "^3.22.4"
"zod": "^3.22.4",
"@zotmeal/tsconfig": "workspace:^0.1.0"
},
"devDependencies": {
"@zotmeal/eslint-config": "workspace:^",
Expand Down
Loading

0 comments on commit f74c9bb

Please sign in to comment.