From 1c81e05cbb23eae49043c0d088266316d293b099 Mon Sep 17 00:00:00 2001 From: Kevin Koech Date: Fri, 19 Jul 2024 12:08:32 +0300 Subject: [PATCH 1/8] VPN managerr build failing --- Dockerfile | 8 +++++--- apps/vpnmanager/app.json | 2 +- apps/vpnmanager/package.json | 5 ++--- apps/vpnmanager/tsconfig.server.json | 13 +++++++++++++ 4 files changed, 21 insertions(+), 7 deletions(-) create mode 100644 apps/vpnmanager/tsconfig.server.json diff --git a/Dockerfile b/Dockerfile index 1781522ed..a9f6394d9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -70,7 +70,8 @@ COPY packages/commons-ui-next/package.json ./packages/commons-ui-next/package.js COPY packages/eslint-config-commons-ui/package.json ./packages/eslint-config-commons-ui/package.json # TODO(kilemensi): Figure out why this is needed (charterafrica, codeforafrica) COPY packages/commons-ui-testing-library/package.json ./packages/commons-ui-testing-library/package.json - +COPY packages/playwright-config-commons-ui/package.json ./packages/playwright-config-commons-ui/package.json +COPY packages/jest-config-commons-ui/package.json ./packages/jest-config-commons-ui/package.json RUN pnpm --filter "./packages/**" install --offline --frozen-lockfile # @@ -590,7 +591,7 @@ RUN set -ex \ # PNPM # symlink some dependencies COPY --from=vpnmanager-builder --chown=nextjs:nodejs /workspace/node_modules ./node_modules - +COPY --from=vpnmanager-builder --chown=nextjs:nodejs /workspace/apps/vpnmanager/node_modules ./apps/vpnmanager/node_modules # Next.js # Public assets COPY --from=vpnmanager-builder --chown=nextjs:nodejs /workspace/apps/vpnmanager/public ./apps/vpnmanager/public @@ -599,7 +600,8 @@ 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/dist ./apps/vpnmanager/dist +COPY --from=vpnmanager-builder --chown=nextjs:nodejs /workspace/apps/vpnmanager/app.json ./app.json USER nextjs # server.js is created by next build from the standalone output diff --git a/apps/vpnmanager/app.json b/apps/vpnmanager/app.json index 5a99e1a65..42049a68b 100644 --- a/apps/vpnmanager/app.json +++ b/apps/vpnmanager/app.json @@ -2,7 +2,7 @@ "name": "vpnmanager", "cron": [ { - "command": "pnpm process-spreadsheet", + "command": "node apps/vpnmanager/dist/scripts/processGsheet.js", "schedule": "@hourly" } ] diff --git a/apps/vpnmanager/package.json b/apps/vpnmanager/package.json index 6634cd2a5..68cedd87f 100644 --- a/apps/vpnmanager/package.json +++ b/apps/vpnmanager/package.json @@ -4,14 +4,13 @@ "private": true, "scripts": { "dev": "next dev", - "build": "next build", + "build": "next build && tsc --project tsconfig.server.json && tsc-alias -p tsconfig.server.json", "start": "next start", "lint-check": "TIMING=1 next lint './'", "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", diff --git a/apps/vpnmanager/tsconfig.server.json b/apps/vpnmanager/tsconfig.server.json new file mode 100644 index 000000000..9ba10cfb5 --- /dev/null +++ b/apps/vpnmanager/tsconfig.server.json @@ -0,0 +1,13 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "target": "ES2015", + "noEmit": false, + "module": "CommonJS", + "jsx": "react", + "outDir": "./dist", + "moduleResolution": "node", + "rootDir": "./" + }, + "include": ["src/lib/**/*.ts", "src/utils/**/*.ts", "scripts/**/*.ts"] +} From 9c8bcfd31c73651da9e9ef6b0d5f6a38f7f525ea Mon Sep 17 00:00:00 2001 From: Kevin Koech Date: Fri, 19 Jul 2024 13:33:40 +0300 Subject: [PATCH 2/8] Remove tests packages --- Dockerfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index a9f6394d9..ca0fdef5d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -70,8 +70,6 @@ COPY packages/commons-ui-next/package.json ./packages/commons-ui-next/package.js COPY packages/eslint-config-commons-ui/package.json ./packages/eslint-config-commons-ui/package.json # TODO(kilemensi): Figure out why this is needed (charterafrica, codeforafrica) COPY packages/commons-ui-testing-library/package.json ./packages/commons-ui-testing-library/package.json -COPY packages/playwright-config-commons-ui/package.json ./packages/playwright-config-commons-ui/package.json -COPY packages/jest-config-commons-ui/package.json ./packages/jest-config-commons-ui/package.json RUN pnpm --filter "./packages/**" install --offline --frozen-lockfile # From c04734bb868670d564cdd62abde852563d6d16d7 Mon Sep 17 00:00:00 2001 From: Kevin Koech Date: Mon, 22 Jul 2024 11:38:45 +0300 Subject: [PATCH 3/8] VPN Manager build --- .github/workflows/vpnmanager-deploy-dev.yml | 1 + Dockerfile | 6 +- apps/vpnmanager/app.json | 2 +- apps/vpnmanager/package.json | 5 +- apps/vpnmanager/scripts/processGsheet.js | 12 ++ apps/vpnmanager/scripts/processGsheet.ts | 9 -- .../vpnmanager/src/pages/api/processGsheet.ts | 15 ++ apps/vpnmanager/tsconfig.server.json | 13 -- docker-compose.yml | 1 + pnpm-lock.yaml | 148 ++++++++++++++++-- 10 files changed, 174 insertions(+), 38 deletions(-) create mode 100644 apps/vpnmanager/scripts/processGsheet.js delete mode 100644 apps/vpnmanager/scripts/processGsheet.ts create mode 100644 apps/vpnmanager/src/pages/api/processGsheet.ts delete mode 100644 apps/vpnmanager/tsconfig.server.json diff --git a/.github/workflows/vpnmanager-deploy-dev.yml b/.github/workflows/vpnmanager-deploy-dev.yml index 56a3c256c..1d6bc4ed0 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 }} + SECRET_TOKEN=${{ secrets.VPNMANAGER_SECRET_TOKEN }} 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 ca0fdef5d..329d3e10d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -560,6 +560,7 @@ ARG NEXT_TELEMETRY_DISABLED \ NEXT_PUBLIC_SENTRY_DSN \ NEXT_PUBLIC_SEO_DISABLED \ NEXT_PUBLIC_GOOGLE_ANALYTICS \ + SECRET_TOKEN \ # Sentry (build time) SENTRY_AUTH_TOKEN \ SENTRY_ENVIRONMENT \ @@ -581,6 +582,7 @@ RUN pnpm --filter "./apps/vpnmanager" build FROM base-runner as vpnmanager-runner +ARG SECRET_TOKEN RUN set -ex \ # Create nextjs cache dir w/ correct permissions && mkdir -p ./apps/vpnmanager/.next \ @@ -589,7 +591,6 @@ RUN set -ex \ # PNPM # symlink some dependencies COPY --from=vpnmanager-builder --chown=nextjs:nodejs /workspace/node_modules ./node_modules -COPY --from=vpnmanager-builder --chown=nextjs:nodejs /workspace/apps/vpnmanager/node_modules ./apps/vpnmanager/node_modules # Next.js # Public assets COPY --from=vpnmanager-builder --chown=nextjs:nodejs /workspace/apps/vpnmanager/public ./apps/vpnmanager/public @@ -598,10 +599,11 @@ 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/dist ./apps/vpnmanager/dist +COPY --from=vpnmanager-builder --chown=nextjs:nodejs /workspace/apps/vpnmanager/scripts ./apps/vpnmanager/scripts COPY --from=vpnmanager-builder --chown=nextjs:nodejs /workspace/apps/vpnmanager/app.json ./app.json USER nextjs +ENV SECRET_TOKEN=${SECRET_TOKEN} # server.js is created by next build from the standalone output # https://nextjs.org/docs/pages/api-reference/next-config-js/output CMD ["node", "apps/vpnmanager/server.js"] diff --git a/apps/vpnmanager/app.json b/apps/vpnmanager/app.json index 42049a68b..bc28e8a0d 100644 --- a/apps/vpnmanager/app.json +++ b/apps/vpnmanager/app.json @@ -2,7 +2,7 @@ "name": "vpnmanager", "cron": [ { - "command": "node apps/vpnmanager/dist/scripts/processGsheet.js", + "command": "node apps/vpnmanager/scripts/processGsheet.js", "schedule": "@hourly" } ] diff --git a/apps/vpnmanager/package.json b/apps/vpnmanager/package.json index 68cedd87f..fc0e09504 100644 --- a/apps/vpnmanager/package.json +++ b/apps/vpnmanager/package.json @@ -4,7 +4,7 @@ "private": true, "scripts": { "dev": "next dev", - "build": "next build && tsc --project tsconfig.server.json && tsc-alias -p tsconfig.server.json", + "build": "next build", "start": "next start", "lint-check": "TIMING=1 next lint './'", "lint": "TIMING=1 next lint --fix './'", @@ -32,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.js b/apps/vpnmanager/scripts/processGsheet.js new file mode 100644 index 000000000..c4fb2b31d --- /dev/null +++ b/apps/vpnmanager/scripts/processGsheet.js @@ -0,0 +1,12 @@ +async function main() { + const { NEXT_PUBLIC_APP_URL, SECRET_TOKEN } = process.env; + const headers = { + "x-api-key": SECRET_TOKEN ?? "", + }; + const res = await fetch(`${NEXT_PUBLIC_APP_URL}/api/processGsheet`, { + headers, + }); + return res.json(); +} + +main().then(console.log); 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..2048db2ab --- /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 SECRET_TOKEN = process.env.SECRET_TOKEN; + if (!key || key !== SECRET_TOKEN) { + 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/apps/vpnmanager/tsconfig.server.json b/apps/vpnmanager/tsconfig.server.json deleted file mode 100644 index 9ba10cfb5..000000000 --- a/apps/vpnmanager/tsconfig.server.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "extends": "./tsconfig.json", - "compilerOptions": { - "target": "ES2015", - "noEmit": false, - "module": "CommonJS", - "jsx": "react", - "outDir": "./dist", - "moduleResolution": "node", - "rootDir": "./" - }, - "include": ["src/lib/**/*.ts", "src/utils/**/*.ts", "scripts/**/*.ts"] -} diff --git a/docker-compose.yml b/docker-compose.yml index e85adf903..7d078ecd8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -147,6 +147,7 @@ services: - SENTRY_ORG - SENTRY_PROJECT - SENTRY_DSN + - SECRET_TOKEN 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 From e645ea504b50c02b0a7c2fb5203589e2772981be Mon Sep 17 00:00:00 2001 From: Kevin Koech Date: Mon, 22 Jul 2024 11:43:36 +0300 Subject: [PATCH 4/8] Fix dockerfile --- Dockerfile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Dockerfile b/Dockerfile index 329d3e10d..3bf217dca 100644 --- a/Dockerfile +++ b/Dockerfile @@ -70,6 +70,7 @@ COPY packages/commons-ui-next/package.json ./packages/commons-ui-next/package.js COPY packages/eslint-config-commons-ui/package.json ./packages/eslint-config-commons-ui/package.json # TODO(kilemensi): Figure out why this is needed (charterafrica, codeforafrica) COPY packages/commons-ui-testing-library/package.json ./packages/commons-ui-testing-library/package.json + RUN pnpm --filter "./packages/**" install --offline --frozen-lockfile # @@ -591,6 +592,7 @@ RUN set -ex \ # PNPM # symlink some dependencies COPY --from=vpnmanager-builder --chown=nextjs:nodejs /workspace/node_modules ./node_modules + # Next.js # Public assets COPY --from=vpnmanager-builder --chown=nextjs:nodejs /workspace/apps/vpnmanager/public ./apps/vpnmanager/public From e7cb71ac2862d5ed69180cbf34f4a537d50564db Mon Sep 17 00:00:00 2001 From: Kevin Koech Date: Mon, 22 Jul 2024 16:12:42 +0300 Subject: [PATCH 5/8] Rename variables --- Dockerfile | 2 -- apps/vpnmanager/app.json | 2 +- apps/vpnmanager/scripts/processGsheet.js | 12 ------------ apps/vpnmanager/scripts/processGsheet.mjs | 14 ++++++++++++++ apps/vpnmanager/src/pages/api/processGsheet.ts | 4 ++-- 5 files changed, 17 insertions(+), 17 deletions(-) delete mode 100644 apps/vpnmanager/scripts/processGsheet.js create mode 100644 apps/vpnmanager/scripts/processGsheet.mjs diff --git a/Dockerfile b/Dockerfile index 3bf217dca..b69888da8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -561,7 +561,6 @@ ARG NEXT_TELEMETRY_DISABLED \ NEXT_PUBLIC_SENTRY_DSN \ NEXT_PUBLIC_SEO_DISABLED \ NEXT_PUBLIC_GOOGLE_ANALYTICS \ - SECRET_TOKEN \ # Sentry (build time) SENTRY_AUTH_TOKEN \ SENTRY_ENVIRONMENT \ @@ -605,7 +604,6 @@ COPY --from=vpnmanager-builder --chown=nextjs:nodejs /workspace/apps/vpnmanager/ COPY --from=vpnmanager-builder --chown=nextjs:nodejs /workspace/apps/vpnmanager/app.json ./app.json USER nextjs -ENV SECRET_TOKEN=${SECRET_TOKEN} # server.js is created by next build from the standalone output # https://nextjs.org/docs/pages/api-reference/next-config-js/output CMD ["node", "apps/vpnmanager/server.js"] diff --git a/apps/vpnmanager/app.json b/apps/vpnmanager/app.json index bc28e8a0d..6952f85b1 100644 --- a/apps/vpnmanager/app.json +++ b/apps/vpnmanager/app.json @@ -2,7 +2,7 @@ "name": "vpnmanager", "cron": [ { - "command": "node apps/vpnmanager/scripts/processGsheet.js", + "command": "node apps/vpnmanager/scripts/processGsheet.mjs", "schedule": "@hourly" } ] diff --git a/apps/vpnmanager/scripts/processGsheet.js b/apps/vpnmanager/scripts/processGsheet.js deleted file mode 100644 index c4fb2b31d..000000000 --- a/apps/vpnmanager/scripts/processGsheet.js +++ /dev/null @@ -1,12 +0,0 @@ -async function main() { - const { NEXT_PUBLIC_APP_URL, SECRET_TOKEN } = process.env; - const headers = { - "x-api-key": SECRET_TOKEN ?? "", - }; - const res = await fetch(`${NEXT_PUBLIC_APP_URL}/api/processGsheet`, { - headers, - }); - return res.json(); -} - -main().then(console.log); diff --git a/apps/vpnmanager/scripts/processGsheet.mjs b/apps/vpnmanager/scripts/processGsheet.mjs new file mode 100644 index 000000000..a58d27af8 --- /dev/null +++ b/apps/vpnmanager/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/src/pages/api/processGsheet.ts b/apps/vpnmanager/src/pages/api/processGsheet.ts index 2048db2ab..1da0baf84 100644 --- a/apps/vpnmanager/src/pages/api/processGsheet.ts +++ b/apps/vpnmanager/src/pages/api/processGsheet.ts @@ -4,8 +4,8 @@ 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 SECRET_TOKEN = process.env.SECRET_TOKEN; - if (!key || key !== SECRET_TOKEN) { + 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(); From 71951864c19ffcc49250e9137838548e6d3ed1df Mon Sep 17 00:00:00 2001 From: Kevin Koech Date: Mon, 22 Jul 2024 16:29:52 +0300 Subject: [PATCH 6/8] update workflow build --- .github/workflows/vpnmanager-deploy-dev.yml | 2 +- docker-compose.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/vpnmanager-deploy-dev.yml b/.github/workflows/vpnmanager-deploy-dev.yml index 1d6bc4ed0..776edc2e5 100644 --- a/.github/workflows/vpnmanager-deploy-dev.yml +++ b/.github/workflows/vpnmanager-deploy-dev.yml @@ -57,7 +57,7 @@ jobs: SENTRY_ENVIRONMENT=${{ env.SENTRY_ENVIRONMENT }} SENTRY_ORG=${{ secrets.SENTRY_ORG }} SENTRY_PROJECT=${{ secrets.VPNMANAGER_SENTRY_PROJECT }} - SECRET_TOKEN=${{ secrets.VPNMANAGER_SECRET_TOKEN }} + 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/docker-compose.yml b/docker-compose.yml index 7d078ecd8..95e2b0b9a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -147,7 +147,7 @@ services: - SENTRY_ORG - SENTRY_PROJECT - SENTRY_DSN - - SECRET_TOKEN + - API_SECRET_KEY environment: NODE_ENV: ${NODE_ENV:-production} ports: From 9c8d8aa779af0ce9fb0fd9ce2921ae0d3bea434b Mon Sep 17 00:00:00 2001 From: KEVIN KOECH Date: Mon, 22 Jul 2024 19:00:40 +0300 Subject: [PATCH 7/8] Update Dockerfile Co-authored-by: Clemence Kyara --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index b69888da8..778dac47c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -582,7 +582,7 @@ RUN pnpm --filter "./apps/vpnmanager" build FROM base-runner as vpnmanager-runner -ARG SECRET_TOKEN +ARG API_SECRET_KEY RUN set -ex \ # Create nextjs cache dir w/ correct permissions && mkdir -p ./apps/vpnmanager/.next \ From ba3c61e0a0823979c457d044848e1ff916f5664e Mon Sep 17 00:00:00 2001 From: Kevin Koech Date: Tue, 23 Jul 2024 09:51:10 +0300 Subject: [PATCH 8/8] move dokku scripts to contrib --- Dockerfile | 3 +-- apps/vpnmanager/{ => contrib/dokku}/app.json | 2 +- apps/vpnmanager/{ => contrib/dokku}/scripts/processGsheet.mjs | 0 3 files changed, 2 insertions(+), 3 deletions(-) rename apps/vpnmanager/{ => contrib/dokku}/app.json (55%) rename apps/vpnmanager/{ => contrib/dokku}/scripts/processGsheet.mjs (100%) diff --git a/Dockerfile b/Dockerfile index 778dac47c..7f974fcf6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -600,8 +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/scripts ./apps/vpnmanager/scripts -COPY --from=vpnmanager-builder --chown=nextjs:nodejs /workspace/apps/vpnmanager/app.json ./app.json +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 55% rename from apps/vpnmanager/app.json rename to apps/vpnmanager/contrib/dokku/app.json index 6952f85b1..e509d641e 100644 --- a/apps/vpnmanager/app.json +++ b/apps/vpnmanager/contrib/dokku/app.json @@ -2,7 +2,7 @@ "name": "vpnmanager", "cron": [ { - "command": "node apps/vpnmanager/scripts/processGsheet.mjs", + "command": "node contrib/dokku/scripts/processGsheet.mjs", "schedule": "@hourly" } ] diff --git a/apps/vpnmanager/scripts/processGsheet.mjs b/apps/vpnmanager/contrib/dokku/scripts/processGsheet.mjs similarity index 100% rename from apps/vpnmanager/scripts/processGsheet.mjs rename to apps/vpnmanager/contrib/dokku/scripts/processGsheet.mjs