From 4e757a50db879dcb6633518cc06230c5d346b114 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Fri, 9 Feb 2024 12:49:47 +0300 Subject: [PATCH 01/17] Create pesayetu dockerfile Signed-off-by: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> --- Dockerfile.pesayetu | 104 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 Dockerfile.pesayetu diff --git a/Dockerfile.pesayetu b/Dockerfile.pesayetu new file mode 100644 index 000000000..046524594 --- /dev/null +++ b/Dockerfile.pesayetu @@ -0,0 +1,104 @@ +FROM node:18-alpine as node-alpine + +# Always install security updated e.g. https://pythonspeed.com/articles/security-updates-in-docker/ +# Update local cache so that other stages don't need to update cache +RUN apk update \ + && apk upgrade + +FROM node-alpine as base + +# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. +RUN apk add --no-cache libc6-compat + +ARG PNPM_VERSION=8.5.0 + +RUN corepack enable && corepack prepare pnpm@${PNPM_VERSION} --activate + +WORKDIR /workspace + +COPY pnpm-lock.yaml . + +RUN pnpm fetch + + +FROM base as builder + +WORKDIR /workspace + +COPY *.yaml *.json ./ +COPY packages ./packages +COPY apps/pesayetu ./apps/pesayetu + +# Use virtual store: https://pnpm.io/cli/fetch#usage-scenario +RUN pnpm install --recursive --offline --frozen-lockfile + +ARG NEXT_TELEMETRY_DISABLED=1 \ + # Needed by Next.js at build time + NEXT_PUBLIC_APP_NAME=Pesayetu \ + NEXT_PUBLIC_APP_URL=http://localhost:3000 \ + NEXT_PUBLIC_SENTRY_DSN="" \ + NEXT_PUBLIC_SEO_DISABLED="true" \ + NEXT_PUBLIC_IMAGE_DOMAINS="cms.dev.codeforafrica.org,hurumap-v2.s3.amazonaws.com" \ + NEXT_PUBLIC_IMAGE_SCALE_FACTOR=2 \ + NEXT_PUBLIC_OPENAFRICA_DOMAINS="open.africa,openafrica.net,africaopendata.org" \ + NEXT_PUBLIC_SOURCEAFRICA_DOMAINS="dc.sourceafrica.net" \ + NEXT_PUBLIC_GOOGLE_ANALYTICS="" \ + # Needed by Next.js and server.ts at build time + PORT=3000 \ + # Sentry config for source maps upload (needed at build time only) + SENTRY_AUTH_TOKEN="" \ + SENTRY_ENV="" \ + SENTRY_ORG="" \ + SENTRY_PROJECT="" \ + # Wordpress config + WORDPRESS_URL \ + WORDPRESS_MULTISITE_PREFIX="/pesayetu" \ + WORDPRESS_PREVIEW_SECRET \ + WORDPRESS_APPLICATION_USERNAME \ + WORDPRESS_APPLICATION_PASSWORD \ + JWT_SECRET_KEY \ + HURUMAP_API_URL \ + # AWS S3 bucket for storing images + S3_UPLOAD_KEY \ + S3_UPLOAD_SECRET \ + S3_UPLOAD_BUCKET \ + S3_UPLOAD_REGION + +RUN pnpm build --filter=pesayetu + +FROM builder as runner + +# Remember to remove local cache from runner +RUN rm -rf /var/cache/apk/* + +ARG NEXT_TELEMETRY_DISABLED \ + NEXT_PUBLIC_APP_NAME \ + NEXT_PUBLIC_APP_URL \ + NEXT_PUBLIC_SENTRY_DSN \ + NEXT_PUBLIC_SEO_DISABLED \ + NEXT_PUBLIC_IMAGE_DOMAINS \ + NEXT_PUBLIC_IMAGE_SCALE_FACTOR \ + NEXT_PUBLIC_OPENAFRICA_DOMAINS \ + NEXT_PUBLIC_SOURCEAFRICA_DOMAINS \ + NEXT_PUBLIC_GOOGLE_ANALYTICS \ + PORT \ + SENTRY_ENV + +ENV NODE_ENV=production \ + NEXT_PUBLIC_APP_NAME=${NEXT_PUBLIC_APP_NAME} \ + NEXT_PUBLIC_APP_URL=${NEXT_PUBLIC_APP_URL} \ + NEXT_PUBLIC_SENTRY_DSN=${NEXT_PUBLIC_SENTRY_DSN} \ + NEXT_PUBLIC_SEO_DISABLED=${NEXT_PUBLIC_SEO_DISABLED} \ + NEXT_PUBLIC_IMAGE_DOMAINS=${NEXT_PUBLIC_IMAGE_DOMAINS} \ + NEXT_PUBLIC_IMAGE_SCALE_FACTOR=${NEXT_PUBLIC_IMAGE_SCALE_FACTOR} \ + NEXT_PUBLIC_OPENAFRICA_DOMAINS=${NEXT_PUBLIC_OPENAFRICA_DOMAINS} \ + NEXT_PUBLIC_SOURCEAFRICA_DOMAINS=${NEXT_PUBLIC_SOURCEAFRICA_DOMAINS} \ + NEXT_PUBLIC_GOOGLE_ANALYTICS=${NEXT_PUBLIC_GOOGLE_ANALYTICS} \ + PORT=${PORT} \ + SENTRY_ENV=${SENTRY_ENV} + +WORKDIR /workspace/apps/pesayetu + +EXPOSE ${PORT} + +CMD ["node", "dist/server.js"] From d5e30de5e5635258f5b0bb1ca7e755a36dabd314 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Mon, 12 Feb 2024 10:15:16 +0300 Subject: [PATCH 02/17] Remove unrequired env variables Signed-off-by: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> --- Dockerfile.pesayetu | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/Dockerfile.pesayetu b/Dockerfile.pesayetu index 046524594..16d236920 100644 --- a/Dockerfile.pesayetu +++ b/Dockerfile.pesayetu @@ -57,12 +57,7 @@ ARG NEXT_TELEMETRY_DISABLED=1 \ WORDPRESS_APPLICATION_USERNAME \ WORDPRESS_APPLICATION_PASSWORD \ JWT_SECRET_KEY \ - HURUMAP_API_URL \ - # AWS S3 bucket for storing images - S3_UPLOAD_KEY \ - S3_UPLOAD_SECRET \ - S3_UPLOAD_BUCKET \ - S3_UPLOAD_REGION + HURUMAP_API_URL RUN pnpm build --filter=pesayetu From f4df91ad54bbdd0b5dd0af932695610c19ddca19 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Thu, 16 May 2024 16:10:48 +0300 Subject: [PATCH 03/17] Add workflow file Signed-off-by: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> --- .github/workflows/pesayetu-deploy-dev.yml | 83 +++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 .github/workflows/pesayetu-deploy-dev.yml diff --git a/.github/workflows/pesayetu-deploy-dev.yml b/.github/workflows/pesayetu-deploy-dev.yml new file mode 100644 index 000000000..d5f164dc7 --- /dev/null +++ b/.github/workflows/pesayetu-deploy-dev.yml @@ -0,0 +1,83 @@ +name: Pesayetu | Deploy | DEV + +on: + push: + branches: [ft/pesayetu-deployment] + paths: + - "apps/pesayetu/**" + - "Dockerfile.pesayetu" + - ".github/workflows/pesayetu-deploy-dev.yml" + +concurrency: + group: "${{ github.workflow }} @ ${{ github.ref }}" + cancel-in-progress: true + +env: + DOKKU_REMOTE_BRANCH: "master" + DOKKU_REMOTE_URL: "ssh://azureuser@ui-1.dev.codeforafrica.org" + IMAGE_NAME: "pesayetu/pesayetu-ui" + NEXT_PUBLIC_APP_URL: "https://pesayetu-ui.dev.codeforafrica.org" + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + APP_NAME: pesayetu-ui + +jobs: + deploy: + runs-on: ${{ matrix.os }} + strategy: + matrix: + node-version: [18] + os: [ubuntu-latest] + steps: + - name: Cloning repo + uses: actions/checkout@v3 + with: + fetch-depth: 0 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Cache Docker layers + uses: actions/cache@v3 + with: + key: ${{ runner.os }}-buildx-${{ github.sha }} + path: /tmp/.buildx-cache + restore-keys: | + ${{ runner.os }}-buildx- + + - name: Login to DockerHub + uses: docker/login-action@v2 + with: + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + username: ${{ secrets.DOCKER_HUB_USERNAME }} + + - name: Build Docker image + uses: docker/build-push-action@v3 + with: + build-args: | + WORDPRESS_URL=${{ secrets.PESAYETU_WORDPRESS_URL }} + WORDPRESS_MULTISITE_PREFIX=${{ secrets.PESAYETU_WORDPRESS_MULTISITE_PREFIX }} + WORDPRESS_PREVIEW_SECRET=${{ secrets.PESAYETU_WORDPRESS_PREVIEW_SECRET }} + WORDPRESS_APPLICATION_USERNAME=${{ secrets.PESAYETU_WORDPRESS_APPLICATION_USERNAME }} + WORDPRESS_APPLICATION_PASSWORD=${{ secrets.PESAYETU_WORDPRESS_APPLICATION_PASSWORD }} + JWT_SECRET_KEY=${{ secrets.PESAYETU_JWT_SECRET_KEY }} + HURUMAP_API_URL=${{ secrets.PESAYETU_HURUMAP_API_URL }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + context: . + file: Dockerfile.pesayetu + tags: pesayetu/pesayetu-ui:latest + + # Temp fix + # https://github.com/docker/build-push-action/issues/252 + # https://github.com/moby/buildkit/issues/1896 + - name: Move cache + run: | + rm -rf /tmp/.buildx-cache + mv /tmp/.buildx-cache-new /tmp/.buildx-cach + + - name: Push to Dokku + uses: dokku/github-action@v1.4.0 + with: + git_remote_url: ${{ env.DOKKU_REMOTE_URL }}/${{ env.APP_NAME }} + ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }} + deploy_docker_image: ${{ env.IMAGE_NAME }}:${{ github.sha }} From 14b56ee80bf2fc5e25835fbb1267c8c289cc6a66 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Thu, 16 May 2024 16:22:17 +0300 Subject: [PATCH 04/17] Fix move cache in workflow Signed-off-by: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> --- .github/workflows/pesayetu-deploy-dev.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pesayetu-deploy-dev.yml b/.github/workflows/pesayetu-deploy-dev.yml index d5f164dc7..0c81f7837 100644 --- a/.github/workflows/pesayetu-deploy-dev.yml +++ b/.github/workflows/pesayetu-deploy-dev.yml @@ -71,9 +71,10 @@ jobs: # https://github.com/docker/build-push-action/issues/252 # https://github.com/moby/buildkit/issues/1896 - name: Move cache + if: steps.version-check.outputs.changed == 'true' run: | rm -rf /tmp/.buildx-cache - mv /tmp/.buildx-cache-new /tmp/.buildx-cach + mv /tmp/.buildx-cache-new /tmp/.buildx-cache - name: Push to Dokku uses: dokku/github-action@v1.4.0 From 809fd73052d2631084f3c065b94d2ec5eaf39e79 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Thu, 16 May 2024 16:37:33 +0300 Subject: [PATCH 05/17] FIx image name Signed-off-by: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> --- .github/workflows/pesayetu-deploy-dev.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pesayetu-deploy-dev.yml b/.github/workflows/pesayetu-deploy-dev.yml index 0c81f7837..e1c7f7467 100644 --- a/.github/workflows/pesayetu-deploy-dev.yml +++ b/.github/workflows/pesayetu-deploy-dev.yml @@ -15,7 +15,7 @@ concurrency: env: DOKKU_REMOTE_BRANCH: "master" DOKKU_REMOTE_URL: "ssh://azureuser@ui-1.dev.codeforafrica.org" - IMAGE_NAME: "pesayetu/pesayetu-ui" + IMAGE_NAME: "codeforafrica/pesayetu-ui" NEXT_PUBLIC_APP_URL: "https://pesayetu-ui.dev.codeforafrica.org" GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} APP_NAME: pesayetu-ui @@ -65,7 +65,7 @@ jobs: cache-to: type=local,dest=/tmp/.buildx-cache context: . file: Dockerfile.pesayetu - tags: pesayetu/pesayetu-ui:latest + tags: "${{ env.IMAGE_NAME }}:${{ steps.version-check.outputs.version }}" # Temp fix # https://github.com/docker/build-push-action/issues/252 From e54ec2914a2dc66def93665ca103ab4681207b88 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Thu, 16 May 2024 16:44:18 +0300 Subject: [PATCH 06/17] Fix image tag Signed-off-by: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> --- .github/workflows/pesayetu-deploy-dev.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/pesayetu-deploy-dev.yml b/.github/workflows/pesayetu-deploy-dev.yml index e1c7f7467..f1b16366b 100644 --- a/.github/workflows/pesayetu-deploy-dev.yml +++ b/.github/workflows/pesayetu-deploy-dev.yml @@ -65,13 +65,12 @@ jobs: cache-to: type=local,dest=/tmp/.buildx-cache context: . file: Dockerfile.pesayetu - tags: "${{ env.IMAGE_NAME }}:${{ steps.version-check.outputs.version }}" + tags: "${{ env.IMAGE_NAME }}:${{ github.sha }}" # Temp fix # https://github.com/docker/build-push-action/issues/252 # https://github.com/moby/buildkit/issues/1896 - name: Move cache - if: steps.version-check.outputs.changed == 'true' run: | rm -rf /tmp/.buildx-cache mv /tmp/.buildx-cache-new /tmp/.buildx-cache From 3847c568e2ac33f101cc47dd9297f6f9aa6d76ec Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Thu, 16 May 2024 16:57:00 +0300 Subject: [PATCH 07/17] Fix docker cache Signed-off-by: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> --- .github/workflows/pesayetu-deploy-dev.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pesayetu-deploy-dev.yml b/.github/workflows/pesayetu-deploy-dev.yml index f1b16366b..425f767f9 100644 --- a/.github/workflows/pesayetu-deploy-dev.yml +++ b/.github/workflows/pesayetu-deploy-dev.yml @@ -62,7 +62,7 @@ jobs: JWT_SECRET_KEY=${{ secrets.PESAYETU_JWT_SECRET_KEY }} HURUMAP_API_URL=${{ secrets.PESAYETU_HURUMAP_API_URL }} cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,dest=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache-new context: . file: Dockerfile.pesayetu tags: "${{ env.IMAGE_NAME }}:${{ github.sha }}" From ed8c7a808314e8da8b6c9daf5c3e3618d53680ce Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Thu, 16 May 2024 17:10:56 +0300 Subject: [PATCH 08/17] Push docker image after build Signed-off-by: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> --- .github/workflows/pesayetu-deploy-dev.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/pesayetu-deploy-dev.yml b/.github/workflows/pesayetu-deploy-dev.yml index 425f767f9..d7c70c7c5 100644 --- a/.github/workflows/pesayetu-deploy-dev.yml +++ b/.github/workflows/pesayetu-deploy-dev.yml @@ -65,6 +65,7 @@ jobs: cache-to: type=local,dest=/tmp/.buildx-cache-new context: . file: Dockerfile.pesayetu + push: true tags: "${{ env.IMAGE_NAME }}:${{ github.sha }}" # Temp fix From d4e7117d8716badf59c91e8396d09582d77e31cc Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Thu, 16 May 2024 18:38:29 +0300 Subject: [PATCH 09/17] use pnpm start after build Signed-off-by: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> --- Dockerfile.pesayetu | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile.pesayetu b/Dockerfile.pesayetu index 16d236920..912b051cc 100644 --- a/Dockerfile.pesayetu +++ b/Dockerfile.pesayetu @@ -96,4 +96,4 @@ WORKDIR /workspace/apps/pesayetu EXPOSE ${PORT} -CMD ["node", "dist/server.js"] +CMD ["pnpm", "start"] From a9f3a68ea72e05d4583705d892e4390df6dc01f9 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Tue, 21 May 2024 09:52:49 +0300 Subject: [PATCH 10/17] Ensure valid map bounds Signed-off-by: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> --- apps/pesayetu/src/components/HURUmap/Map/Layers.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/apps/pesayetu/src/components/HURUmap/Map/Layers.js b/apps/pesayetu/src/components/HURUmap/Map/Layers.js index e29dfedc0..e3ad603ba 100644 --- a/apps/pesayetu/src/components/HURUmap/Map/Layers.js +++ b/apps/pesayetu/src/components/HURUmap/Map/Layers.js @@ -236,10 +236,13 @@ function Layers({ }); layer.addLayer(featuredGeo); if (!isPinOrCompare) { - map.fitBounds(layer.getBounds(), { - animate: true, - duration: 0.5, // in seconds - }); + const bounds = layer.getBounds(); + if (bounds.isValid()) { + map.fitBounds(layer.getBounds(), { + animate: true, + duration: 0.5, // in seconds + }); + } } else { const mark = new L.Marker(layer.getBounds().getCenter(), { icon: pinIcon, From 0befcd8baa17dee0ccf3d459665cb8bb26d2b65d Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Tue, 21 May 2024 17:40:05 +0300 Subject: [PATCH 11/17] Pesayetu dev setup --- apps/pesayetu/next.config.js | 5 +++ .../src/components/HURUmap/Tutorial/index.js | 2 +- apps/pesayetu/src/components/Page/Base.js | 3 +- .../src/components/ProjectOwner/index.js | 2 +- .../pesayetu/src/pages/explore/[[...slug]].js | 31 ++++++++++--------- 5 files changed, 26 insertions(+), 17 deletions(-) diff --git a/apps/pesayetu/next.config.js b/apps/pesayetu/next.config.js index 4fe83b790..9611749db 100644 --- a/apps/pesayetu/next.config.js +++ b/apps/pesayetu/next.config.js @@ -41,6 +41,11 @@ module.exports = { }, async redirects() { return [ + { + source: "/", + destination: "/explore/ke", + permanent: true, + }, { source: "/data", destination: "/data/documents", diff --git a/apps/pesayetu/src/components/HURUmap/Tutorial/index.js b/apps/pesayetu/src/components/HURUmap/Tutorial/index.js index d6a991b04..b1b9ef800 100644 --- a/apps/pesayetu/src/components/HURUmap/Tutorial/index.js +++ b/apps/pesayetu/src/components/HURUmap/Tutorial/index.js @@ -63,7 +63,7 @@ function Tutorial({ children, defaultOpen, items, ...props }) { accentColor="#fff" maskClassName={classes.mask} highlightedMaskClassName={classes.highlightedMask} - steps={items.map((item, index) => ({ + steps={items?.map((item, index) => ({ selector: item?.selector, content: , }))} diff --git a/apps/pesayetu/src/components/Page/Base.js b/apps/pesayetu/src/components/Page/Base.js index 405e29fdc..56c48082b 100644 --- a/apps/pesayetu/src/components/Page/Base.js +++ b/apps/pesayetu/src/components/Page/Base.js @@ -14,7 +14,8 @@ import getNavigationMenu from "@/pesayetu/functions/menus/getNavigationMenu"; /** * Base page that can be used to build all other pages. */ -function BasePage({ children, menus, variant, post: { seo } = {}, ...props }) { +function BasePage({ children, menus, variant, post, ...props }) { + const seo = {}; const footerProps = getFooterMenu(menus?.footerMenu || []); const navigation = getNavigationMenu(menus?.primaryMenu || []); const { menuProps, socialLinks } = navigation; diff --git a/apps/pesayetu/src/components/ProjectOwner/index.js b/apps/pesayetu/src/components/ProjectOwner/index.js index 3f68dd79d..1dfdf20f5 100644 --- a/apps/pesayetu/src/components/ProjectOwner/index.js +++ b/apps/pesayetu/src/components/ProjectOwner/index.js @@ -62,7 +62,7 @@ function ProjectOwner({ >
- {name} + {name} {description} diff --git a/apps/pesayetu/src/pages/explore/[[...slug]].js b/apps/pesayetu/src/pages/explore/[[...slug]].js index 2bab12923..ebe5e3b25 100644 --- a/apps/pesayetu/src/pages/explore/[[...slug]].js +++ b/apps/pesayetu/src/pages/explore/[[...slug]].js @@ -6,7 +6,6 @@ import ExplorePage from "@/pesayetu/components/ExplorePage"; import Tutorial from "@/pesayetu/components/HURUmap/Tutorial"; import Page from "@/pesayetu/components/Page"; import formatBlocksForSections from "@/pesayetu/functions/formatBlocksForSections"; -import getPostTypeStaticProps from "@/pesayetu/functions/postTypes/getPostTypeStaticProps"; import { fetchProfile, fetchProfileGeography } from "@/pesayetu/lib/hurumap"; export default function Explore(props) { @@ -43,7 +42,7 @@ Explore.defaultProps = { blocks: undefined, }; -const postType = "page"; +// const postType = "page"; export async function getStaticPaths() { const { locations } = await fetchProfile(); @@ -57,18 +56,22 @@ export async function getStaticPaths() { }; } -export async function getStaticProps({ preview, previewData, params }) { - const { props, revalidate, notFound } = await getPostTypeStaticProps( - { slug: "explore" }, - postType, - preview, - previewData, - ); - if (notFound) { - return { - notFound, - }; - } +export async function getStaticProps({ params }) { + const props = {}; + const revalidate = true; + // const { props, revalidate, notFound } = await getPostTypeStaticProps( + // { slug: "explore" }, + // postType, + // preview, + // previewData, + // ); + // if (notFound) { + // console.error("Not found!!!"); + // return { + // props: {}, + // // notFound, + // }; + // } const blocks = await formatBlocksForSections(props?.post?.blocks); const { locations, preferredChildren } = await fetchProfile(); From 483029bc9d20fab5b4e7836116b0feb94dc38c82 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Tue, 21 May 2024 17:41:49 +0300 Subject: [PATCH 12/17] Revert "Pesayetu dev setup" This reverts commit 0befcd8baa17dee0ccf3d459665cb8bb26d2b65d. --- apps/pesayetu/next.config.js | 5 --- .../src/components/HURUmap/Tutorial/index.js | 2 +- apps/pesayetu/src/components/Page/Base.js | 3 +- .../src/components/ProjectOwner/index.js | 2 +- .../pesayetu/src/pages/explore/[[...slug]].js | 31 +++++++++---------- 5 files changed, 17 insertions(+), 26 deletions(-) diff --git a/apps/pesayetu/next.config.js b/apps/pesayetu/next.config.js index 9611749db..4fe83b790 100644 --- a/apps/pesayetu/next.config.js +++ b/apps/pesayetu/next.config.js @@ -41,11 +41,6 @@ module.exports = { }, async redirects() { return [ - { - source: "/", - destination: "/explore/ke", - permanent: true, - }, { source: "/data", destination: "/data/documents", diff --git a/apps/pesayetu/src/components/HURUmap/Tutorial/index.js b/apps/pesayetu/src/components/HURUmap/Tutorial/index.js index b1b9ef800..d6a991b04 100644 --- a/apps/pesayetu/src/components/HURUmap/Tutorial/index.js +++ b/apps/pesayetu/src/components/HURUmap/Tutorial/index.js @@ -63,7 +63,7 @@ function Tutorial({ children, defaultOpen, items, ...props }) { accentColor="#fff" maskClassName={classes.mask} highlightedMaskClassName={classes.highlightedMask} - steps={items?.map((item, index) => ({ + steps={items.map((item, index) => ({ selector: item?.selector, content: , }))} diff --git a/apps/pesayetu/src/components/Page/Base.js b/apps/pesayetu/src/components/Page/Base.js index 56c48082b..405e29fdc 100644 --- a/apps/pesayetu/src/components/Page/Base.js +++ b/apps/pesayetu/src/components/Page/Base.js @@ -14,8 +14,7 @@ import getNavigationMenu from "@/pesayetu/functions/menus/getNavigationMenu"; /** * Base page that can be used to build all other pages. */ -function BasePage({ children, menus, variant, post, ...props }) { - const seo = {}; +function BasePage({ children, menus, variant, post: { seo } = {}, ...props }) { const footerProps = getFooterMenu(menus?.footerMenu || []); const navigation = getNavigationMenu(menus?.primaryMenu || []); const { menuProps, socialLinks } = navigation; diff --git a/apps/pesayetu/src/components/ProjectOwner/index.js b/apps/pesayetu/src/components/ProjectOwner/index.js index 1dfdf20f5..3f68dd79d 100644 --- a/apps/pesayetu/src/components/ProjectOwner/index.js +++ b/apps/pesayetu/src/components/ProjectOwner/index.js @@ -62,7 +62,7 @@ function ProjectOwner({ >
- {name} + {name} {description} diff --git a/apps/pesayetu/src/pages/explore/[[...slug]].js b/apps/pesayetu/src/pages/explore/[[...slug]].js index ebe5e3b25..2bab12923 100644 --- a/apps/pesayetu/src/pages/explore/[[...slug]].js +++ b/apps/pesayetu/src/pages/explore/[[...slug]].js @@ -6,6 +6,7 @@ import ExplorePage from "@/pesayetu/components/ExplorePage"; import Tutorial from "@/pesayetu/components/HURUmap/Tutorial"; import Page from "@/pesayetu/components/Page"; import formatBlocksForSections from "@/pesayetu/functions/formatBlocksForSections"; +import getPostTypeStaticProps from "@/pesayetu/functions/postTypes/getPostTypeStaticProps"; import { fetchProfile, fetchProfileGeography } from "@/pesayetu/lib/hurumap"; export default function Explore(props) { @@ -42,7 +43,7 @@ Explore.defaultProps = { blocks: undefined, }; -// const postType = "page"; +const postType = "page"; export async function getStaticPaths() { const { locations } = await fetchProfile(); @@ -56,22 +57,18 @@ export async function getStaticPaths() { }; } -export async function getStaticProps({ params }) { - const props = {}; - const revalidate = true; - // const { props, revalidate, notFound } = await getPostTypeStaticProps( - // { slug: "explore" }, - // postType, - // preview, - // previewData, - // ); - // if (notFound) { - // console.error("Not found!!!"); - // return { - // props: {}, - // // notFound, - // }; - // } +export async function getStaticProps({ preview, previewData, params }) { + const { props, revalidate, notFound } = await getPostTypeStaticProps( + { slug: "explore" }, + postType, + preview, + previewData, + ); + if (notFound) { + return { + notFound, + }; + } const blocks = await formatBlocksForSections(props?.post?.blocks); const { locations, preferredChildren } = await fetchProfile(); From c2f65a6b048763ae1ede3705a2465ea0004863fe Mon Sep 17 00:00:00 2001 From: kilemensi Date: Tue, 28 May 2024 09:31:05 +0300 Subject: [PATCH 13/17] Add pesayetu to docker compose --- docker-compose.yml | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index add6a16e9..47ff7455e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,3 @@ -version: "3.8" - services: charterafrica: depends_on: @@ -29,6 +27,31 @@ services: ports: - 3000:3000 + pesayetu: + build: + context: . + dockerfile: Dockerfile.pesayetu + args: + WORDPRESS_URL: ${WORDPRESS_URL} + WORDPRESS_PREVIEW_SECRET: ${WORDPRESS_PREVIEW_SECRET} + WORDPRESS_APPLICATION_USERNAME: ${WORDPRESS_APPLICATION_USERNAME} + WORDPRESS_APPLICATION_PASSWORD: ${WORDPRESS_APPLICATION_PASSWORD} + JWT_SECRET_KEY: ${JWT_SECRET_KEY} + HURUMAP_API_URL: ${HURUMAP_API_URL} + environment: + WORDPRESS_URL: ${WORDPRESS_URL} + WORDPRESS_PREVIEW_SECRET: ${WORDPRESS_PREVIEW_SECRET} + WORDPRESS_APPLICATION_USERNAME: ${WORDPRESS_APPLICATION_USERNAME} + WORDPRESS_APPLICATION_PASSWORD: ${WORDPRESS_APPLICATION_PASSWORD} + JWT_SECRET_KEY: ${JWT_SECRET_KEY} + HURUMAP_API_URL: ${HURUMAP_API_URL} + S3_UPLOAD_KEY: ${S3_UPLOAD_KEY} + S3_UPLOAD_SECRET: ${S3_UPLOAD_SECRET} + S3_UPLOAD_BUCKET: ${S3_UPLOAD_BUCKET} + S3_UPLOAD_REGION: ${S3_UPLOAD_REGION} + ports: + - 3000:3000 + mongodb: image: mongo:6.0.13 environment: From 321b64ab773fa790396075564e161f2f8be48d95 Mon Sep 17 00:00:00 2001 From: kilemensi Date: Tue, 28 May 2024 09:32:18 +0300 Subject: [PATCH 14/17] run pesayetu from Makefile --- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 1c3ba1c13..0c0d1b0e9 100644 --- a/Makefile +++ b/Makefile @@ -14,4 +14,6 @@ mongodb: mongodb-keyfile: openssl rand -base64 741 > ./mongo-keyfile chmod 600 ./mongo-keyfile - \ No newline at end of file + +pesayetu: + BUILDKIT_PROGRESS=plain docker compose --env-file apps/pesayetu/.env.local up pesayetu --build From 0bfff0d9c2383c78def103f2a2d9e68b06b086c1 Mon Sep 17 00:00:00 2001 From: kilemensi Date: Tue, 28 May 2024 09:32:48 +0300 Subject: [PATCH 15/17] Improve stages and follow pnpm structure --- Dockerfile.pesayetu | 89 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 72 insertions(+), 17 deletions(-) diff --git a/Dockerfile.pesayetu b/Dockerfile.pesayetu index 912b051cc..c6e71c03b 100644 --- a/Dockerfile.pesayetu +++ b/Dockerfile.pesayetu @@ -1,36 +1,55 @@ -FROM node:18-alpine as node-alpine +FROM node:18.20.3-alpine as node # Always install security updated e.g. https://pythonspeed.com/articles/security-updates-in-docker/ # Update local cache so that other stages don't need to update cache RUN apk update \ && apk upgrade -FROM node-alpine as base +# =================================================== +# base: starting image to be used in all other stages +# =================================================== +FROM node as base # Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. RUN apk add --no-cache libc6-compat +WORKDIR /workspace + + +# =================================================== +# pnpm-base: starting image with pnpm activated. +# should be used in all "build" stages. +# =================================================== +FROM base as pnpm-base + ARG PNPM_VERSION=8.5.0 RUN corepack enable && corepack prepare pnpm@${PNPM_VERSION} --activate -WORKDIR /workspace +# ========================================================= +# desp: image with all dependencies (for the app) installed +# ========================================================= +FROM pnpm-base as deps COPY pnpm-lock.yaml . RUN pnpm fetch - -FROM base as builder - -WORKDIR /workspace - COPY *.yaml *.json ./ -COPY packages ./packages -COPY apps/pesayetu ./apps/pesayetu +COPY packages/commons-ui-core/package.json ./packages/commons-ui-core/package.json +COPY packages/commons-ui-next/package.json ./packages/commons-ui-next/package.json +# Next.js lints when doing production build +COPY packages/eslint-config-commons-ui/package.json ./packages/eslint-config-commons-ui/package.json +COPY apps/pesayetu/package.json ./apps/pesayetu/package.json # Use virtual store: https://pnpm.io/cli/fetch#usage-scenario -RUN pnpm install --recursive --offline --frozen-lockfile +RUN pnpm --filter "./apps/pesayetu" install --offline --frozen-lockfile + + +# ======================================================= +# builder: image that uses deps to build shippable output +# ======================================================= +FROM pnpm-base as builder ARG NEXT_TELEMETRY_DISABLED=1 \ # Needed by Next.js at build time @@ -59,12 +78,23 @@ ARG NEXT_TELEMETRY_DISABLED=1 \ JWT_SECRET_KEY \ HURUMAP_API_URL -RUN pnpm build --filter=pesayetu +COPY --from=deps /workspace/node_modules ./node_modules +COPY --from=deps /workspace/packages/commons-ui-core/node_modules ./packages/commons-ui-core/node_modules +COPY --from=deps /workspace/packages/eslint-config-commons-ui/node_modules ./packages/eslint-config-commons-ui/node_modules +COPY --from=deps /workspace/packages/commons-ui-next/node_modules ./packages/commons-ui-next/node_modules +COPY --from=deps /workspace/apps/pesayetu/node_modules ./apps/pesayetu/node_modules + +# Next.js lints when doing production build +COPY packages/eslint-config-commons-ui ./packages/eslint-config-commons-ui +COPY apps/pesayetu ./apps/pesayetu + +RUN pnpm --filter "./apps/pesayetu" build -FROM builder as runner -# Remember to remove local cache from runner -RUN rm -rf /var/cache/apk/* +# ============================== +# runner: final deployable image +# ============================== +FROM base as runner ARG NEXT_TELEMETRY_DISABLED \ NEXT_PUBLIC_APP_NAME \ @@ -92,8 +122,33 @@ ENV NODE_ENV=production \ PORT=${PORT} \ SENTRY_ENV=${SENTRY_ENV} -WORKDIR /workspace/apps/pesayetu +RUN set -ex \ + # Create a non-root user + && addgroup --system -g 1001 nodejs \ + && adduser --system -u 1001 -g 1001 nextjs \ + # Create nextjs cache dir w/ correct permissions + && mkdir -p ./apps/pesayetu/.next \ + && chown nextjs:nodejs ./apps/pesayetu/.next \ + # Delete system cached files we don't need anymore + && rm -rf /var/cache/apk/* + +# PNPM symlink some dependencies +COPY --from=builder --chown=nextjs:nodejs /workspace/node_modules ./node_modules +# Public assets +COPY --from=builder --chown=nextjs:nodejs /workspace/apps/pesayetu/public ./apps/pesayetu/public + +# Automatically leverage output traces to reduce image size +# https://nextjs.org/docs/advanced-features/output-file-tracing +COPY --from=builder --chown=nextjs:nodejs /workspace/apps/pesayetu/.next/standalone ./apps/pesayetu +COPY --from=builder --chown=nextjs:nodejs /workspace/apps/pesayetu/.next/static ./apps/pesayetu/.next/static + +USER nextjs EXPOSE ${PORT} -CMD ["pnpm", "start"] +# set hostname to localhost +ENV HOSTNAME "0.0.0.0" + +# 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/pesayetu/server.js"] From a7353c1c5da557ee7e99912b3e486a9f3ed952fb Mon Sep 17 00:00:00 2001 From: kilemensi Date: Tue, 28 May 2024 09:39:04 +0300 Subject: [PATCH 16/17] Reduce stories pages built to just main ones Instead of building alll stories (over 100) at build time, this PR reduces them down to main ones only i.e. only one depth from /stories. This effectively means only 2 pages are now build: i. /stories/news, and ii. /stories/insights --- apps/pesayetu/src/pages/stories/[[...slug]].js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/apps/pesayetu/src/pages/stories/[[...slug]].js b/apps/pesayetu/src/pages/stories/[[...slug]].js index fd7eead3e..7c4c629b9 100644 --- a/apps/pesayetu/src/pages/stories/[[...slug]].js +++ b/apps/pesayetu/src/pages/stories/[[...slug]].js @@ -108,7 +108,15 @@ Index.defaultProps = { }; export async function getStaticPaths() { - return getPostTypeStaticPaths(postType); + const { paths: allPaths = [] } = + (await getPostTypeStaticPaths(postType)) || {}; + // Generate static pages for main stories pages i.e. stories/news and stories/insights + const paths = allPaths.filter(({ params }) => params?.slug?.length === 1); + + return { + paths, + fallback: "blocking", + }; } export async function getStaticProps({ params, preview, previewData }) { From dd5816d5c529e34331a12be921035fd421e1a727 Mon Sep 17 00:00:00 2001 From: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> Date: Tue, 28 May 2024 11:35:59 +0300 Subject: [PATCH 17/17] Update workflow target branch Signed-off-by: Kipruto <43873157+kelvinkipruto@users.noreply.github.com> --- .github/workflows/pesayetu-deploy-dev.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pesayetu-deploy-dev.yml b/.github/workflows/pesayetu-deploy-dev.yml index d7c70c7c5..835044934 100644 --- a/.github/workflows/pesayetu-deploy-dev.yml +++ b/.github/workflows/pesayetu-deploy-dev.yml @@ -2,7 +2,7 @@ name: Pesayetu | Deploy | DEV on: push: - branches: [ft/pesayetu-deployment] + branches: [main] paths: - "apps/pesayetu/**" - "Dockerfile.pesayetu"