Skip to content

Commit

Permalink
Merge pull request #790 from CodeForAfrica/fix/vpnmanager-build-failing
Browse files Browse the repository at this point in the history
@vpnmanager script not running
  • Loading branch information
koechkevin authored Jul 23, 2024
2 parents 4032512 + e7c2830 commit efbe2c6
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 25 deletions.
1 change: 1 addition & 0 deletions .github/workflows/vpnmanager-deploy-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: .
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vpnmanager",
"cron": [
{
"command": "pnpm process-spreadsheet",
"command": "node contrib/dokku/scripts/processGsheet.mjs",
"schedule": "@hourly"
}
]
Expand Down
14 changes: 14 additions & 0 deletions apps/vpnmanager/contrib/dokku/scripts/processGsheet.mjs
Original file line number Diff line number Diff line change
@@ -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);
6 changes: 2 additions & 4 deletions apps/vpnmanager/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
9 changes: 0 additions & 9 deletions apps/vpnmanager/scripts/processGsheet.ts

This file was deleted.

15 changes: 15 additions & 0 deletions apps/vpnmanager/src/pages/api/processGsheet.ts
Original file line number Diff line number Diff line change
@@ -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;
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ services:
- SENTRY_ORG
- SENTRY_PROJECT
- SENTRY_DSN
- API_SECRET_KEY
environment:
NODE_ENV: ${NODE_ENV:-production}
ports:
Expand Down
148 changes: 138 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit efbe2c6

Please sign in to comment.