diff --git a/.github/workflows/vpnmanager-deploy-dev.yml b/.github/workflows/vpnmanager-deploy-dev.yml index 56a3c256c..776edc2e5 100644 --- a/.github/workflows/vpnmanager-deploy-dev.yml +++ b/.github/workflows/vpnmanager-deploy-dev.yml @@ -57,6 +57,7 @@ jobs: SENTRY_ENVIRONMENT=${{ env.SENTRY_ENVIRONMENT }} SENTRY_ORG=${{ secrets.SENTRY_ORG }} SENTRY_PROJECT=${{ secrets.VPNMANAGER_SENTRY_PROJECT }} + API_SECRET_KEY=${{ secrets.VPNMANAGER_API_SECRET_KEY }} cache-from: type=local,src=/tmp/.buildx-cache cache-to: type=local,dest=/tmp/.buildx-cache-new context: . diff --git a/Dockerfile b/Dockerfile index 1781522ed..7f974fcf6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -582,6 +582,7 @@ RUN pnpm --filter "./apps/vpnmanager" build FROM base-runner as vpnmanager-runner +ARG API_SECRET_KEY RUN set -ex \ # Create nextjs cache dir w/ correct permissions && mkdir -p ./apps/vpnmanager/.next \ @@ -599,7 +600,7 @@ COPY --from=vpnmanager-builder --chown=nextjs:nodejs /workspace/apps/vpnmanager/ # https://nextjs.org/docs/advanced-features/output-file-tracing COPY --from=vpnmanager-builder --chown=nextjs:nodejs /workspace/apps/vpnmanager/.next/standalone ./apps/vpnmanager COPY --from=vpnmanager-builder --chown=nextjs:nodejs /workspace/apps/vpnmanager/.next/static ./apps/vpnmanager/.next/static - +COPY --from=vpnmanager-builder --chown=nextjs:nodejs /workspace/apps/vpnmanager/contrib/dokku ./contrib/dokku USER nextjs # server.js is created by next build from the standalone output diff --git a/apps/vpnmanager/app.json b/apps/vpnmanager/contrib/dokku/app.json similarity index 56% rename from apps/vpnmanager/app.json rename to apps/vpnmanager/contrib/dokku/app.json index 5a99e1a65..e509d641e 100644 --- a/apps/vpnmanager/app.json +++ b/apps/vpnmanager/contrib/dokku/app.json @@ -2,7 +2,7 @@ "name": "vpnmanager", "cron": [ { - "command": "pnpm process-spreadsheet", + "command": "node contrib/dokku/scripts/processGsheet.mjs", "schedule": "@hourly" } ] diff --git a/apps/vpnmanager/contrib/dokku/scripts/processGsheet.mjs b/apps/vpnmanager/contrib/dokku/scripts/processGsheet.mjs new file mode 100644 index 000000000..a58d27af8 --- /dev/null +++ b/apps/vpnmanager/contrib/dokku/scripts/processGsheet.mjs @@ -0,0 +1,14 @@ +async function main() { + const NEXT_PUBLIC_APP_URL = process.env.NEXT_PUBLIC_APP_URL; + const API_SECRET_KEY = process.env.API_SECRET_KEY; + const headers = { + "x-api-key": API_SECRET_KEY ?? "", + }; + const res = await fetch(`${NEXT_PUBLIC_APP_URL}/api/processGsheet`, { + headers, + }); + return res.json(); +} + +const responseJson = await main(); +console.log(responseJson); diff --git a/apps/vpnmanager/package.json b/apps/vpnmanager/package.json index 6634cd2a5..fc0e09504 100644 --- a/apps/vpnmanager/package.json +++ b/apps/vpnmanager/package.json @@ -10,8 +10,7 @@ "lint": "TIMING=1 next lint --fix './'", "clean": "rm -rf .next .turbo node_modules", "jest": "jest --passWithNoTests", - "playwright": "npx playwright test", - "process-spreadsheet": "node dist/scripts/processGsheet.js" + "playwright": "npx playwright test" }, "dependencies": { "@babel/preset-react": "^7.24.7", @@ -33,8 +32,7 @@ "next": "^14.2.5", "react": "^18.3.1", "react-dom": "^18.3.1", - "tsc-alias": "^1.8.10", - "tsconfig-paths": "^4.2.0" + "tsc-alias": "^1.8.10" }, "devDependencies": { "@babel/core": "^7.24.8", diff --git a/apps/vpnmanager/scripts/processGsheet.ts b/apps/vpnmanager/scripts/processGsheet.ts deleted file mode 100644 index 2fb3639b8..000000000 --- a/apps/vpnmanager/scripts/processGsheet.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { processNewUsers } from "@/vpnmanager/lib/processUsers"; -import { loadEnvConfig } from "@next/env"; -import { initSentry } from "../sentry.server.config"; - -initSentry(); -const projectDir = process.cwd(); -loadEnvConfig(projectDir); - -processNewUsers(); diff --git a/apps/vpnmanager/src/pages/api/processGsheet.ts b/apps/vpnmanager/src/pages/api/processGsheet.ts new file mode 100644 index 000000000..1da0baf84 --- /dev/null +++ b/apps/vpnmanager/src/pages/api/processGsheet.ts @@ -0,0 +1,15 @@ +import { NextApiResponse, NextApiRequest } from "next"; +import { processNewUsers } from "@/vpnmanager/lib/processUsers"; + +export async function handler(req: NextApiRequest, res: NextApiResponse) { + try { + const key: string = req.headers["x-api-key"] as string; + const API_SECRET_KEY = process.env.API_SECRET_KEY; + if (!(key && key !== API_SECRET_KEY)) { + return res.status(403).json({ message: "INVALID_API_KEY" }); + } + processNewUsers(); + return res.status(200).json({ message: "Process Started" }); + } catch (error) {} +} +export default handler; diff --git a/docker-compose.yml b/docker-compose.yml index e85adf903..95e2b0b9a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -147,6 +147,7 @@ services: - SENTRY_ORG - SENTRY_PROJECT - SENTRY_DSN + - API_SECRET_KEY environment: NODE_ENV: ${NODE_ENV:-production} ports: diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7b99828cc..44abde036 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1457,7 +1457,7 @@ importers: version: 133.0.0(encoding@0.1.13) jest: specifier: ^29.7.0 - version: 29.7.0(@types/node@20.14.10)(babel-plugin-macros@3.1.0)(ts-node@10.9.2(@swc/core@1.6.13(@swc/helpers@0.5.5))(@types/node@20.14.10)(typescript@5.5.3)) + version: 29.7.0(@types/node@20.14.10)(babel-plugin-macros@3.1.0)(ts-node@10.9.2(@types/node@20.14.10)(typescript@5.5.3)) next: specifier: ^14.2.5 version: 14.2.5(@babel/core@7.24.8)(@opentelemetry/api@1.9.0)(@playwright/test@1.45.1)(babel-plugin-macros@3.1.0)(react-dom@18.3.1(react@18.3.1))(react@18.3.1)(sass@1.69.4) @@ -1470,9 +1470,6 @@ importers: tsc-alias: specifier: ^1.8.10 version: 1.8.10 - tsconfig-paths: - specifier: ^4.2.0 - version: 4.2.0 devDependencies: '@babel/core': specifier: ^7.24.8 @@ -16197,6 +16194,41 @@ snapshots: - supports-color - ts-node + '@jest/core@29.7.0(babel-plugin-macros@3.1.0)(ts-node@10.9.2(@types/node@20.14.10)(typescript@5.5.3))': + dependencies: + '@jest/console': 29.7.0 + '@jest/reporters': 29.7.0 + '@jest/test-result': 29.7.0 + '@jest/transform': 29.7.0 + '@jest/types': 29.6.3 + '@types/node': 20.14.10 + ansi-escapes: 4.3.2 + chalk: 4.1.2 + ci-info: 3.9.0 + exit: 0.1.2 + graceful-fs: 4.2.11 + jest-changed-files: 29.7.0 + jest-config: 29.7.0(@types/node@20.14.10)(babel-plugin-macros@3.1.0)(ts-node@10.9.2(@types/node@20.14.10)(typescript@5.5.3)) + jest-haste-map: 29.7.0 + jest-message-util: 29.7.0 + jest-regex-util: 29.6.3 + jest-resolve: 29.7.0 + jest-resolve-dependencies: 29.7.0 + jest-runner: 29.7.0 + jest-runtime: 29.7.0 + jest-snapshot: 29.7.0 + jest-util: 29.7.0 + jest-validate: 29.7.0 + jest-watcher: 29.7.0 + micromatch: 4.0.7 + pretty-format: 29.7.0 + slash: 3.0.0 + strip-ansi: 6.0.1 + transitivePeerDependencies: + - babel-plugin-macros + - supports-color + - ts-node + '@jest/environment@29.7.0': dependencies: '@jest/fake-timers': 29.7.0 @@ -21375,6 +21407,21 @@ snapshots: - supports-color - ts-node + create-jest@29.7.0(@types/node@20.14.10)(babel-plugin-macros@3.1.0)(ts-node@10.9.2(@types/node@20.14.10)(typescript@5.5.3)): + dependencies: + '@jest/types': 29.6.3 + chalk: 4.1.2 + exit: 0.1.2 + graceful-fs: 4.2.11 + jest-config: 29.7.0(@types/node@20.14.10)(babel-plugin-macros@3.1.0)(ts-node@10.9.2(@types/node@20.14.10)(typescript@5.5.3)) + jest-util: 29.7.0 + prompts: 2.4.2 + transitivePeerDependencies: + - '@types/node' + - babel-plugin-macros + - supports-color + - ts-node + create-require@1.1.1: {} cross-spawn@5.1.0: @@ -22298,7 +22345,7 @@ snapshots: '@typescript-eslint/parser': 7.2.0(eslint@8.57.0)(typescript@5.5.3) eslint: 8.57.0 eslint-import-resolver-node: 0.3.9 - eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1)(eslint@8.57.0) + eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(eslint@8.57.0))(eslint@8.57.0) eslint-plugin-import: 2.29.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-typescript@3.6.1)(eslint@8.57.0) eslint-plugin-jsx-a11y: 6.9.0(eslint@8.57.0) eslint-plugin-react: 7.34.3(eslint@8.57.0) @@ -22356,12 +22403,12 @@ snapshots: - eslint-import-resolver-webpack - supports-color - eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1)(eslint@8.57.0): + eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(eslint@8.57.0))(eslint@8.57.0): dependencies: debug: 4.3.5 enhanced-resolve: 5.17.0 eslint: 8.57.0 - eslint-module-utils: 2.8.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1)(eslint@8.57.0))(eslint@8.57.0) + eslint-module-utils: 2.8.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0) eslint-plugin-import: 2.29.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-typescript@3.6.1)(eslint@8.57.0) fast-glob: 3.3.2 get-tsconfig: 4.7.5 @@ -22457,14 +22504,14 @@ snapshots: transitivePeerDependencies: - supports-color - eslint-module-utils@2.8.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1)(eslint@8.57.0))(eslint@8.57.0): + eslint-module-utils@2.8.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0): dependencies: debug: 3.2.7 optionalDependencies: '@typescript-eslint/parser': 7.2.0(eslint@8.57.0)(typescript@5.5.3) eslint: 8.57.0 eslint-import-resolver-node: 0.3.9 - eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1)(eslint@8.57.0) + eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(eslint@8.57.0))(eslint@8.57.0) transitivePeerDependencies: - supports-color @@ -22515,7 +22562,7 @@ snapshots: doctrine: 2.1.0 eslint: 8.57.0 eslint-import-resolver-node: 0.3.9 - eslint-module-utils: 2.8.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1)(eslint@8.57.0))(eslint@8.57.0) + eslint-module-utils: 2.8.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.5.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0) hasown: 2.0.2 is-core-module: 2.14.0 is-glob: 4.0.3 @@ -24288,6 +24335,25 @@ snapshots: - supports-color - ts-node + jest-cli@29.7.0(@types/node@20.14.10)(babel-plugin-macros@3.1.0)(ts-node@10.9.2(@types/node@20.14.10)(typescript@5.5.3)): + dependencies: + '@jest/core': 29.7.0(babel-plugin-macros@3.1.0)(ts-node@10.9.2(@types/node@20.14.10)(typescript@5.5.3)) + '@jest/test-result': 29.7.0 + '@jest/types': 29.6.3 + chalk: 4.1.2 + create-jest: 29.7.0(@types/node@20.14.10)(babel-plugin-macros@3.1.0)(ts-node@10.9.2(@types/node@20.14.10)(typescript@5.5.3)) + exit: 0.1.2 + import-local: 3.1.0 + jest-config: 29.7.0(@types/node@20.14.10)(babel-plugin-macros@3.1.0)(ts-node@10.9.2(@types/node@20.14.10)(typescript@5.5.3)) + jest-util: 29.7.0 + jest-validate: 29.7.0 + yargs: 17.7.2 + transitivePeerDependencies: + - '@types/node' + - babel-plugin-macros + - supports-color + - ts-node + jest-config@29.7.0(@types/node@20.14.10): dependencies: '@babel/core': 7.24.8 @@ -24350,6 +24416,37 @@ snapshots: - babel-plugin-macros - supports-color + jest-config@29.7.0(@types/node@20.14.10)(babel-plugin-macros@3.1.0)(ts-node@10.9.2(@types/node@20.14.10)(typescript@5.5.3)): + dependencies: + '@babel/core': 7.24.8 + '@jest/test-sequencer': 29.7.0 + '@jest/types': 29.6.3 + babel-jest: 29.7.0(@babel/core@7.24.8) + chalk: 4.1.2 + ci-info: 3.9.0 + deepmerge: 4.3.1 + glob: 7.2.3 + graceful-fs: 4.2.11 + jest-circus: 29.7.0(babel-plugin-macros@3.1.0) + jest-environment-node: 29.7.0 + jest-get-type: 29.6.3 + jest-regex-util: 29.6.3 + jest-resolve: 29.7.0 + jest-runner: 29.7.0 + jest-util: 29.7.0 + jest-validate: 29.7.0 + micromatch: 4.0.7 + parse-json: 5.2.0 + pretty-format: 29.7.0 + slash: 3.0.0 + strip-json-comments: 3.1.1 + optionalDependencies: + '@types/node': 20.14.10 + ts-node: 10.9.2(@types/node@20.14.10)(typescript@5.5.3) + transitivePeerDependencies: + - babel-plugin-macros + - supports-color + jest-diff@29.7.0: dependencies: chalk: 4.1.2 @@ -24611,6 +24708,18 @@ snapshots: - supports-color - ts-node + jest@29.7.0(@types/node@20.14.10)(babel-plugin-macros@3.1.0)(ts-node@10.9.2(@types/node@20.14.10)(typescript@5.5.3)): + dependencies: + '@jest/core': 29.7.0(babel-plugin-macros@3.1.0)(ts-node@10.9.2(@types/node@20.14.10)(typescript@5.5.3)) + '@jest/types': 29.6.3 + import-local: 3.1.0 + jest-cli: 29.7.0(@types/node@20.14.10)(babel-plugin-macros@3.1.0)(ts-node@10.9.2(@types/node@20.14.10)(typescript@5.5.3)) + transitivePeerDependencies: + - '@types/node' + - babel-plugin-macros + - supports-color + - ts-node + jiti@1.21.6: {} jmespath@0.16.0: {} @@ -28414,6 +28523,25 @@ snapshots: optionalDependencies: '@swc/core': 1.6.13(@swc/helpers@0.5.5) + ts-node@10.9.2(@types/node@20.14.10)(typescript@5.5.3): + dependencies: + '@cspotcode/source-map-support': 0.8.1 + '@tsconfig/node10': 1.0.11 + '@tsconfig/node12': 1.0.11 + '@tsconfig/node14': 1.0.3 + '@tsconfig/node16': 1.0.4 + '@types/node': 20.14.10 + acorn: 8.12.1 + acorn-walk: 8.3.3 + arg: 4.1.3 + create-require: 1.1.1 + diff: 4.0.2 + make-error: 1.3.6 + typescript: 5.5.3 + v8-compile-cache-lib: 3.0.1 + yn: 3.1.1 + optional: true + ts-pnp@1.2.0(typescript@5.5.3): optionalDependencies: typescript: 5.5.3