Skip to content

Commit

Permalink
Merge branch 'main' into feat/roboshield_ui
Browse files Browse the repository at this point in the history
  • Loading branch information
m453h committed Jun 25, 2024
2 parents 251173e + 9f1032d commit 5c6e56a
Show file tree
Hide file tree
Showing 42 changed files with 3,027 additions and 355 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/roboshield-deploy-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches: [main]
paths:
- "apps/roboshield/**"
- "roboshield.Dockerfile"
- "Dockerfile"
- ".github/workflows/roboshield-dev.yml"

concurrency:
Expand Down Expand Up @@ -66,7 +66,8 @@ jobs:
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
context: .
file: roboshield.Dockerfile
target: charterafrica-runner
file: Dockerfile
push: true
tags: "${{ env.IMAGE_NAME }}:${{ github.sha }}"

Expand Down
90 changes: 90 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,96 @@ USER nextjs
# Custom server to run Payload and Next.js in the same app
CMD ["node", "dist/server.js"]

# ============================================================================
# Roboshield
# ============================================================================
FROM base-deps as roboshield-deps

COPY apps/roboshield/package.json ./apps/roboshield/package.json

RUN pnpm --filter "./apps/roboshield/" install --offline --frozen-lockfile
FROM base-builder as roboshield-builder
ARG NEXT_TELEMETRY_DISABLED \
# Next.js / Payload (build time)
PORT \
# Next.js (runtime)
NEXT_PUBLIC_APP_NAME="RoboShield" \
NEXT_PUBLIC_APP_URL=http://localhost:3000 \
NEXT_PUBLIC_SENTRY_DSN="" \
# Payload (runtime)
MONGO_URL \
PAYLOAD_SECRET \
# Sentry (build time)
SENTRY_AUTH_TOKEN \
SENTRY_ENVIRONMENT \
SENTRY_ORG="" \
SENTRY_PROJECT=""

COPY --from=roboshield-deps /workspace/node_modules ./node_modules

COPY packages ./packages

COPY --from=roboshield-deps /workspace/apps/roboshield/node_modules ./apps/roboshield/node_modules

COPY apps/roboshield ./apps/roboshield/

RUN pnpm --filter "./apps/roboshield/" build-next

ARG PAYLOAD_PUBLIC_APP_URL=${NEXT_PUBLIC_APP_URL}

RUN pnpm --filter "./apps/roboshield/" build-payload

#
# roboshield-runner: final deployable image
# --------------------------------------------
FROM base-runner as roboshield-runner

ARG MONGO_URL \
NEXT_PUBLIC_APP_LOGO_URL \
PAYLOAD_CONFIG_PATH="dist/payload.config.js" \
PAYLOAD_PUBLIC_APP_URL

ENV MONGO_URL=${MONGO_URL} \
# TODO(koech): Standadise naming of GA MEASUREMENT ID. Our options:
# - GA_MEASUREMENT_ID (charterafrica, roboshield)
# - GOOGLE_ANALYTICS (pesayetu, vpnmanager)
# This is only needed at runtime
NEXT_PUBLIC_APP_LOGO_URL=${NEXT_PUBLIC_APP_LOGO_URL} \
PAYLOAD_PUBLIC_APP_URL=${PAYLOAD_PUBLIC_APP_URL} \
PAYLOAD_CONFIG_PATH=${PAYLOAD_CONFIG_PATH} \
PAYLOAD_SECRET=${PAYLOAD_SECRET}

RUN set -ex \
# Create nextjs cache dir w/ correct permissions
&& mkdir -p ./apps/roboshield//.next \
&& chown nextjs:nodejs ./apps/roboshield/.next

# PNPM
# symlink some dependencies
COPY --from=roboshield-builder --chown=nextjs:nodejs /workspace/node_modules ./node_modules

# Since we can't use output: "standalone", copy all app's dependencies
COPY --from=roboshield-builder --chown=nextjs:nodejs /workspace/apps/roboshield/node_modules ./apps/roboshield/node_modules

# Next.js
# Public assets
COPY --from=roboshield-builder --chown=nextjs:nodejs /workspace/apps/roboshield/public ./apps/roboshield/public

# Since we can't use output: "standalone", copy the whole app's .next folder
# TODO(kilemensi): Figure out which files in .next folder are not needed
COPY --from=roboshield-builder --chown=nextjs:nodejs /workspace/apps/roboshield/.next ./apps/roboshield/.next

# Payload
COPY --from=roboshield-builder /workspace/apps/roboshield/dist ./apps/roboshield/dist
COPY --from=roboshield-builder /workspace/apps/roboshield/build ./apps/roboshield/build

# Since we can't use output: "standalone", switch to specific app's folder
WORKDIR /workspace/apps/roboshield

USER nextjs

# Custom server to run Payload and Next.js in the same app
CMD ["node", "dist/server.js"]
# ============================================================================
# PesaYetu
# ============================================================================
Expand Down
5 changes: 5 additions & 0 deletions apps/roboshield/.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
MIGRATIONS_DIR=./migrations

PAYLOAD_PUBLIC_DEFAULT_LOCALE=en
PAYLOAD_PUBLIC_LOCALES="en"

SENTRY_ENVIRONMENT=local
SENTRY_ORG=code-for-africa
SENTRY_PROJECT=roboshield
10 changes: 10 additions & 0 deletions apps/roboshield/.env.template
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,13 @@ SENTRY_ENVIRONMENT=local|development|staging|production
SENTRY_ORG=
# Defaults to roboshield
SENTRY_PROJECT=

# Payload
MONGO_URL=
PAYLOAD_SECRET=
PAYLOAD_PUBLIC_APP_URL=

S3_ACCESS_KEY_ID=
S3_SECRET_ACCESS_KEY=
S3_BUCKET=
S3_REGION=
26 changes: 21 additions & 5 deletions apps/roboshield/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
"version": "0.1.0",
"private": true,
"scripts": {
"build": "next build",
"build-server": "tsc --project tsconfig.server.json",
"build-next": "NEXT_BUILD=true pnpm build-server && NEXT_BUILD=true PAYLOAD_CONFIG_PATH=${PAYLOAD_CONFIG_PATH:-dist/payload.config.js} node dist/server.js",
"build-payload": "payload build",
"start": "PAYLOAD_CONFIG_PATH=${PAYLOAD_CONFIG_PATH:-dist/payload.config.js} NODE_ENV=${NODE_ENV:-production} node dist/server.js",
"dev": "NODE_OPTIONS='--inspect' ts-node --project tsconfig.server.json server.ts",
"clean": "rm -rf .next .turbo node_modules",
"dev": "next dev",
"jest": "jest --passWithNoTests",
"lint-check": "TIMING=1 next lint './'",
"lint": "TIMING=1 next lint --fix './'",
"start": "next start"
"lint": "TIMING=1 next lint --fix './'"
},
"dependencies": {
"@commons-ui/core": "workspace:*",
Expand All @@ -23,11 +25,22 @@
"@mui/utils": "^5.15.14",
"@mui/x-date-pickers": "^7.6.2",
"@next/env": "^14.2.3",
"@payloadcms/bundler-webpack": "^1.0.7",
"@payloadcms/db-mongodb": "^1.5.2",
"@payloadcms/plugin-cloud-storage": "^1.1.3",
"@payloadcms/plugin-nested-docs": "^1.0.12",
"@payloadcms/plugin-sentry": "^0.0.6",
"@payloadcms/plugin-seo": "^2.3.2",
"@payloadcms/richtext-slate": "^1.5.2",
"@sentry/nextjs": "^8.10.0",
"ace-builds": "^1.34.2",
"crawler-user-agents": "^1.0.142",
"date-fns": "^3.6.0",
"dotenv": "^16.4.5",
"express": "^4.18.2",
"next": "14.2.4",
"nodemailer-sendgrid": "^1.0.3",
"payload": "2.22.0",
"react": "^18.3.1",
"react-ace": "^11.0.1",
"react-dom": "^18.3.1",
Expand All @@ -41,7 +54,9 @@
"devDependencies": {
"@commons-ui/testing-library": "workspace:*",
"@svgr/webpack": "^8.1.0",
"@types/node": "^20.14.2",
"@types/express": "^4.17.21",
"@types/node": "^20.14.7",
"@types/nodemailer-sendgrid": "^1.0.3",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"babel-jest": "^29.7.0",
Expand All @@ -52,6 +67,7 @@
"eslint-plugin-import": "^2.29.1",
"jest": "^29.7.0",
"jest-config-commons-ui": "workspace:*",
"prettier": "3.1.1",
"typescript": "^5.4.5"
}
}
117 changes: 117 additions & 0 deletions apps/roboshield/payload.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import path from "path";

import { buildConfig } from "payload/config";
import { slateEditor } from "@payloadcms/richtext-slate";
import { mongooseAdapter } from "@payloadcms/db-mongodb";
import { webpackBundler } from "@payloadcms/bundler-webpack";
import { CollectionConfig, GlobalConfig } from "payload/types";
import { cloudStorage } from "@payloadcms/plugin-cloud-storage";
import Site from "./src/payload/globals/Site";
import dotenv from "dotenv";
import Media from "./src/payload/collections/Media";
import Pages from "./src/payload/collections/Pages";
import seo from "@payloadcms/plugin-seo";
import nestedDocs from "@payloadcms/plugin-nested-docs";
import { s3Adapter } from "@payloadcms/plugin-cloud-storage/s3";
import Users from "./src/payload/collections/Users";
import { defaultLocale, locales } from "./src/payload/utils/locales";

dotenv.config();
dotenv.config({ path: "./.env.local" });

const appURL = process?.env?.PAYLOAD_PUBLIC_APP_URL;

const cors =
process?.env?.PAYLOAD_CORS?.split(",")
?.map((d) => d.trim())
?.filter(Boolean) ?? [];

const csrf =
process?.env?.PAYLOAD_CSRF?.split(",")
?.map((d) => d.trim())
?.filter(Boolean) ?? [];

const adapter = s3Adapter({
config: {
region: process?.env?.S3_REGION,
credentials: {
accessKeyId: process?.env?.S3_ACCESS_KEY_ID,
secretAccessKey: process?.env?.S3_SECRET_ACCESS_KEY,
},
},
bucket: process?.env?.S3_BUCKET,
} as any);

export default buildConfig({
serverURL: appURL,
editor: slateEditor({}),
db: mongooseAdapter({
url: process.env.MONGO_URL ?? false,
migrationDir: process.env.MIGRATIONS_DIR,
}),
collections: [Media, Pages, Users] as CollectionConfig[],
globals: [Site] as GlobalConfig[],
...(locales?.length
? {
localization: {
locales,
defaultLocale,
fallback: true,
},
}
: undefined),
admin: {
user: Users.slug,
webpack: (config) => ({
...config,
resolve: {
...config.resolve,
fallback: {
...config?.resolve?.fallback,
fs: false,
os: false,
"process/browser": false,
},
},
}),
bundler: webpackBundler(),
},
cors,
csrf,
i18n: {
fallbackLng: "en", // default
debug: false, // default
resources: {
en: {
"codeforafrica.validation": {
uniquePlatforms: "Please select a unique platform",
},
},
},
},
plugins: [
cloudStorage({
collections: {
media: {
adapter,
prefix: "media",
},
},
}),
seo({
collections: ["pages", "posts"],
globals: [],
uploadsCollection: "media",
generateTitle: ({ doc }: any) => doc?.title?.value as string,
generateURL: ({ doc }: any) =>
doc?.slug?.value ? `${appURL}/${doc.slug.value}` : undefined,
} as any),
nestedDocs({
collections: ["pages"],
generateLabel: (_, doc) => doc.title as string,
generateURL: (docs) =>
docs.reduce((url, doc) => `${url}/${doc.slug}`, ""),
}),
] as any[],
telemetry: process?.env?.NODE_ENV !== "production",
});
Loading

0 comments on commit 5c6e56a

Please sign in to comment.