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: