Skip to content

Commit

Permalink
Merge pull request #828 from CodeForAfrica/feat/civicsignalblog
Browse files Browse the repository at this point in the history
@/civicsignalblog
  • Loading branch information
kilemensi authored Aug 7, 2024
2 parents dd5c3d9 + 67d655c commit e81d714
Show file tree
Hide file tree
Showing 398 changed files with 17,978 additions and 44 deletions.
104 changes: 104 additions & 0 deletions .github/workflows/civicsignalblog-deploy-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: CivicSignal Blog | Deploy | PROD

on:
push:
branches: [main]

# This allows a subsequently queued workflow run to interrupt previous runs
concurrency:
group: "${{ github.workflow }} @ ${{ github.ref }}"
cancel-in-progress: true

env:
DOKKU_REMOTE_BRANCH: "master"
DOKKU_REMOTE_URL: "ssh://[email protected]/civicsignalblog-ui"
GIT_PUSH_FLAGS: "--force"
IMAGE_NAME: "codeforafrica/civicsignalblog-ui"
VERSION_FILE_NAME: "./apps/civisignalblog/package.json"
NEXT_PUBLIC_APP_URL: "https://blog.civicsignal.africa"
SENTRY_ENVIRONMENT: "production"

jobs:
deploy:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [20.16]
os: [ubuntu-latest]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

# Set up Node since it's required by version-check
# https://github.com/EndBug/version-check#github-workflow
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: Check if version is bumped
id: version-check
uses: EndBug/version-check@v2
with:
# Whether to search in every commit's diff.
# This is useful if you often do change the version without saying it
# in the commit message. If you always include the semver of the new
# version in your commit message when you bump versions then you can
# omit this.
diff-search: true
file-name: "${{ env.VERSION_FILE_NAME }}"

- name: Set up Docker Buildx
if: steps.version-check.outputs.changed == 'true'
uses: docker/setup-buildx-action@v3

- name: Cache Docker layers
if: steps.version-check.outputs.changed == 'true'
uses: actions/cache@v4
with:
key: ${{ runner.os }}-buildx-${{ github.sha }}
path: /tmp/.buildx-cache
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to DockerHub
if: steps.version-check.outputs.changed == 'true'
uses: docker/login-action@v3
with:
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
username: ${{ secrets.DOCKER_HUB_USERNAME }}

- name: Build Docker image
if: steps.version-check.outputs.changed == 'true'
uses: docker/build-push-action@v5
with:
build-args: |
MONGODB_URL=${{ secrets.CIVICSIGNALBLOG_MONGO_URL }}
NEXT_PUBLIC_APP_URL=${{ env.NEXT_PUBLIC_APP_URL }}
PAYLOAD_SECRET=${{ secrets.CIVICSIGNALBLOG_PAYLOAD_SECRET }}
SENTRY_AUTH_TOKEN=${{ secrets.SENTRY_AUTH_TOKEN }}
SENTRY_ENVIRONMENT=${{ env.SENTRY_ENVIRONMENT }}
SENTRY_ORG=${{ secrets.SENTRY_ORG }}
SENTRY_PROJECT=${{ secrets.CIVICSIGNALBLOG_SENTRY_PROJECT }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
context: .
target: civicsignalblog-runner
push: true
tags: "${{ env.IMAGE_NAME }}:${{ steps.version-check.outputs.version }}"

- name: Move cache
if: steps.version-check.outputs.changed == 'true'
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- name: Push to Dokku
if: steps.version-check.outputs.changed == 'true'
uses: dokku/[email protected]
with:
deploy_docker_image: ${{ env.IMAGE_NAME }}:${{ steps.version-check.outputs.version }}
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
git_remote_url: ${{ env.DOKKU_REMOTE_URL }}
168 changes: 139 additions & 29 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -320,27 +320,27 @@ CMD ["node", "apps/climatemappedafrica/server.js"]


# ============================================================================
# Code for Africa
# CivicSignal Blog
# ============================================================================

#
# codeforafrica-desp: image with all codeforafrica dependencies
# civicsignalblog-desp: image with all codeforafrica dependencies
# -------------------------------------------------------------

FROM base-deps AS codeforafrica-deps
FROM base-deps AS civicsignalblog-deps

# TODO(kilemensi): Figure out why this is needed
COPY packages/commons-ui-testing-library/package.json ./packages/commons-ui-testing-library/package.json

COPY apps/codeforafrica/package.json ./apps/codeforafrica/package.json
COPY apps/civicsignalblog/package.json ./apps/civicsignalblog/package.json

RUN pnpm --filter "./apps/codeforafrica/" install --offline --frozen-lockfile
RUN pnpm --filter "./apps/civicsignalblog/" install --offline --frozen-lockfile

#
# codeforafrica-builder: image that uses deps to build shippable output
# civicsignalblog-builder: image that uses deps to build shippable output
# ---------------------------------------------------------------------

FROM base-builder AS codeforafrica-builder
FROM base-builder AS civicsignalblog-builder

ARG NEXT_TELEMETRY_DISABLED \
# Next.js / Payload (build time)
Expand All @@ -352,8 +352,8 @@ ARG NEXT_TELEMETRY_DISABLED \
# Payload (runtime)
# TODO(koech): Standadise naming of Mongo DB URL. Our options:
# - MONGODB_URL (codeforafrica)
# - MONGO_URL (charterafrica, roboshield)
MONGODB_URL \
# - MONGO_URL (charterafrica, civicsignalblog, roboshield)
MONGO_URL \
PAYLOAD_SECRET \
# Sentry (build time)
SENTRY_AUTH_TOKEN \
Expand All @@ -362,32 +362,32 @@ ARG NEXT_TELEMETRY_DISABLED \
SENTRY_PROJECT

# This is in app-builder instead of base-builder just incase app-deps adds deps
COPY --from=codeforafrica-deps /workspace/node_modules ./node_modules
COPY --from=civicsignalblog-deps /workspace/node_modules ./node_modules

COPY --from=codeforafrica-deps /workspace/apps/codeforafrica/node_modules ./apps/codeforafrica/node_modules
COPY --from=civicsignalblog-deps /workspace/apps/civicsignalblog/node_modules ./apps/civicsignalblog/node_modules

COPY apps/codeforafrica ./apps/codeforafrica/
COPY apps/civicsignalblog ./apps/civicsignalblog/

# When building Next.js app, Next.js needs to connect to local Payload
ENV PAYLOAD_PUBLIC_APP_URL=http://localhost:3000
RUN pnpm --filter "./apps/codeforafrica/" build-next
RUN pnpm --filter "./apps/civicsignalblog/" build-next

# When building Payload app, Payload needs to have final app URL
ENV PAYLOAD_PUBLIC_APP_URL=${NEXT_PUBLIC_APP_URL}
RUN pnpm --filter "./apps/codeforafrica/" build-payload
RUN pnpm --filter "./apps/civicsignalblog/" build-payload

#
# codeforafrica-runner: final deployable image
# civicsignalblog-runner: final deployable image
# --------------------------------------------

FROM base-runner AS codeforafrica-runner
FROM base-runner AS civicsignalblog-runner

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

# TODO(koech): Standadise naming of GA MEASUREMENT ID. Our options:
# - GA_MEASUREMENT_ID (charterafrica, codeforafrica)
# - GA_MEASUREMENT_ID (charterafrica, civicsignalblog, codeforafrica)
# - GOOGLE_ANALYTICS_ID (pesayetu, roboshield, vpnmanager)
# This is only needed at runtime
ENV NEXT_PUBLIC_APP_LOGO_URL=${NEXT_PUBLIC_APP_LOGO_URL} \
Expand All @@ -396,39 +396,149 @@ ENV NEXT_PUBLIC_APP_LOGO_URL=${NEXT_PUBLIC_APP_LOGO_URL} \

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

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

# Since we can't use output: "standalone", copy all app's dependencies
COPY --from=codeforafrica-builder --chown=nextjs:nodejs /workspace/apps/codeforafrica/node_modules ./apps/codeforafrica/node_modules
COPY --from=codeforafrica-builder --chown=nextjs:nodejs /workspace/apps/codeforafrica/next.config.js ./apps/codeforafrica/next.config.js
COPY --from=codeforafrica-builder --chown=nextjs:nodejs /workspace/apps/codeforafrica/.env ./apps/codeforafrica/.env
COPY --from=codeforafrica-builder --chown=nextjs:nodejs /workspace/apps/codeforafrica/migrations ./apps/codeforafrica/migrations
COPY --from=civicsignalblog-builder --chown=nextjs:nodejs /workspace/apps/civicsignalblog/node_modules ./apps/civicsignalblog/node_modules
COPY --from=civicsignalblog-builder --chown=nextjs:nodejs /workspace/apps/civicsignalblog/next.config.js ./apps/civicsignalblog/next.config.js
COPY --from=civicsignalblog-builder --chown=nextjs:nodejs /workspace/apps/civicsignalblog/.env ./apps/civicsignalblog/.env
COPY --from=civicsignalblog-builder --chown=nextjs:nodejs /workspace/apps/civicsignalblog/migrations ./apps/civicsignalblog/migrations
# Next.js
# Public assets
COPY --from=codeforafrica-builder --chown=nextjs:nodejs /workspace/apps/codeforafrica/public ./apps/codeforafrica/public
COPY --from=civicsignalblog-builder --chown=nextjs:nodejs /workspace/apps/civicsignalblog/public ./apps/civicsignalblog/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=codeforafrica-builder --chown=nextjs:nodejs /workspace/apps/codeforafrica/.next ./apps/codeforafrica/.next
COPY --from=civicsignalblog-builder --chown=nextjs:nodejs /workspace/apps/civicsignalblog/.next ./apps/civicsignalblog/.next

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

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

USER nextjs

# Custom server to run Payload and Next.js in the same app
CMD ["node", "dist/server.js"]


# ============================================================================
# Code for Africa
# ============================================================================

#
# codeforafrica-desp: image with all codeforafrica dependencies
# -------------------------------------------------------------

FROM base-deps AS codeforafrica-deps

# TODO(kilemensi): Figure out why this is needed
COPY packages/commons-ui-testing-library/package.json ./packages/commons-ui-testing-library/package.json

COPY apps/codeforafrica/package.json ./apps/codeforafrica/package.json

RUN pnpm --filter "./apps/codeforafrica/" install --offline --frozen-lockfile

#
# codeforafrica-builder: image that uses deps to build shippable output
# ---------------------------------------------------------------------

FROM base-builder AS codeforafrica-builder

ARG NEXT_TELEMETRY_DISABLED \
# Next.js / Payload (build time)
PORT \
# Next.js (runtime)
NEXT_PUBLIC_APP_NAME="Code for Africa" \
NEXT_PUBLIC_APP_URL \
NEXT_PUBLIC_SENTRY_DSN \
# Payload (runtime)
# TODO(koech): Standadise naming of Mongo DB URL. Our options:
# - MONGODB_URL (codeforafrica)
# - MONGO_URL (charterafrica, roboshield)
MONGODB_URL \
PAYLOAD_SECRET \
# Sentry (build time)
SENTRY_AUTH_TOKEN \
SENTRY_ENVIRONMENT \
SENTRY_ORG \
SENTRY_PROJECT

# This is in app-builder instead of base-builder just incase app-deps adds deps
COPY --from=codeforafrica-deps /workspace/node_modules ./node_modules

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

COPY apps/codeforafrica ./apps/codeforafrica/

# When building Next.js app, Next.js needs to connect to local Payload
ENV PAYLOAD_PUBLIC_APP_URL=http://localhost:3000
RUN pnpm --filter "./apps/codeforafrica/" build-next

# When building Payload app, Payload needs to have final app URL
ENV PAYLOAD_PUBLIC_APP_URL=${NEXT_PUBLIC_APP_URL}
RUN pnpm --filter "./apps/codeforafrica/" build-payload

#
# codeforafrica-runner: final deployable image
# --------------------------------------------

FROM base-runner AS codeforafrica-runner

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

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

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

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

# Since we can't use output: "standalone", copy all app's dependencies
COPY --from=codeforafrica-builder --chown=nextjs:nodejs /workspace/apps/codeforafrica/node_modules ./apps/codeforafrica/node_modules
COPY --from=codeforafrica-builder --chown=nextjs:nodejs /workspace/apps/codeforafrica/next.config.js ./apps/codeforafrica/next.config.js
COPY --from=codeforafrica-builder --chown=nextjs:nodejs /workspace/apps/codeforafrica/.env ./apps/codeforafrica/.env
COPY --from=codeforafrica-builder --chown=nextjs:nodejs /workspace/apps/codeforafrica/migrations ./apps/codeforafrica/migrations
# Next.js
# Public assets
COPY --from=codeforafrica-builder --chown=nextjs:nodejs /workspace/apps/codeforafrica/public ./apps/codeforafrica/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=codeforafrica-builder --chown=nextjs:nodejs /workspace/apps/codeforafrica/.next ./apps/codeforafrica/.next

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

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

USER nextjs

# Custom server to run Payload and Next.js in the same app
CMD ["node", "dist/server.js"]


# ============================================================================
# PesaYetu
# ============================================================================
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ COMPOSE_BUILD_ENV=BUILDKIT_PROGRESS=plain
charterafrica:
$(COMPOSE_BUILD_ENV) $(COMPOSE) --env-file apps/charterafrica/.env.local up charterafrica --build

civicsignalblog:
$(COMPOSE_BUILD_ENV) $(COMPOSE) --env-file apps/civicsignalblog/.env.local up civicsignalblog --build

codeforafrica:
$(COMPOSE_BUILD_ENV) $(COMPOSE) --env-file apps/codeforafrica/.env.local up codeforafrica --build

Expand Down
11 changes: 11 additions & 0 deletions apps/civicsignalblog/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
MIGRATIONS_DIR=./migrations
NEXT_PUBLIC_APP_DIRECTORY="apps/civicsignal/"
NEXT_PUBLIC_APP_NAME="Code for Africa"
NEXT_PUBLIC_APP_URL="https://blog.civicsignal.africa"
NEXT_PUBLIC_GOOGLE_ANALYTICS_ID="G-NXX5DBEHXC"
NEXT_PUBLIC_IMAGE_DOMAINS=""
NEXT_PUBLIC_IMAGE_UNOPTIMIZED="true"
NEXT_PUBLIC_VERCEL_URL=${VERCEL_URL}
SENTRY_ENVIRONMENT=local
SENTRY_ORG=code-for-africa
SENTRY_PROJECT=civicsignal
Loading

0 comments on commit e81d714

Please sign in to comment.