Skip to content

Commit

Permalink
💚 Use env vars at build time #2346
Browse files Browse the repository at this point in the history
  • Loading branch information
padms committed Aug 7, 2024
1 parent 7a007f0 commit 0bb8fd2
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/DEV-web.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ jobs:
dynatracePaaSToken: ${{ secrets.DYNATRACE_PAAS_TOKEN }}
dynatraceImage: ${{ secrets.DYNATRACE_PREPROD_IMAGE }}
archiveContentLink: ${{ vars.ARCHIVE_CONTENT_LINK }}
friendlyCaptchaSitekey: ${{ matrix.dataset == 'brazil' && vars.BRAZIL_FC_SITEKEY || vars.GLOBAL_FC_SITEKEY }}
friendlyCaptchaPuzzleEndpoint: ${{ matrix.dataset == 'brazil' && vars.BRAZIL_FC_PUZZLE_END_POINT || vars.GLOBAL_FC_PUZZLE_END_POINT }}
deployToBothClusters: true
environment: ${{ secrets.ENV }}
- uses: act10ns/slack@v2
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/PREPROD-webs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ jobs:
algoliaApiKey: ${{ secrets.ALGOLIA_SEARCH_API_KEY }}
environment: ${{ secrets.ENV }}
archiveContentLink: ${{ vars.ARCHIVE_CONTENT_LINK }}
friendlyCaptchaSitekey: ${{ vars.FC_SITEKEY}}
friendlyCaptchaPuzzleEndpoint: ${{ vars.FC_PUZZLE_END_POINT}}
- uses: act10ns/slack@v2
with:
status: ${{ job.status }}
Expand Down Expand Up @@ -145,6 +147,8 @@ jobs:
dynatraceImage: ${{ secrets.DYNATRACE_PREPROD_IMAGE }}
environment: ${{ secrets.ENV }}
archiveContentLink: ${{ vars.ARCHIVE_CONTENT_LINK }}
friendlyCaptchaSitekey: ${{ vars.FC_SITEKEY}}
friendlyCaptchaPuzzleEndpoint: ${{ vars.FC_PUZZLE_END_POINT}}
deployToBothClusters: true
- uses: act10ns/slack@v2
with:
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/deploy-websites/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ inputs:
deployToBothClusters:
description: 'Deploy app to both Radix clusters'
required: false
friendlyCaptchaSitekey:
description: 'Friendly captcha site key'
required: true
friendlyCaptchaPuzzleEndpoint:
description: 'Friendly captcha puzzle endpoint'
required: true
runs:
using: 'composite'
steps:
Expand Down Expand Up @@ -104,6 +110,8 @@ runs:
--build-arg ARG_DYNATRACE_IMAGE=${{ inputs.dynatraceImage || 'node:18-alpine' }} \
--build-arg ARG_ENV=${{ inputs.environment }} \
--build-arg ARG_ARCHIVE_CONTENT_LINK=${{ inputs.archiveContentLink }} \
--build-arg ARG_FRIENDLY_CAPTCHA_SITEKEY=${{ inputs.friendlyCaptchaSitekey}} \
--build-arg ARG_FRIENDLY_CAPTCHA_PUZZLE_ENDPOINT=${{ inputs.friendlyCaptchaPuzzleEndpoint}} \
--file web/Dockerfile \
--tag ${{ inputs.imageName }}:${{ env.IMAGE_TAG }} \
--tag ${{ inputs.imageName }}:${{ env.IMAGE_TAG_SHA }} \
Expand Down
8 changes: 8 additions & 0 deletions web/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@ ARG ARG_SANITY_PROJECT_ID
ARG ARG_ALGOLIA_APP_ID
ARG ARG_ALGOLIA_SEARCH_API_KEY
ARG ARG_ARCHIVE_CONTENT_LINK
ARG ARG_FRIENDLY_CAPTCHA_SITEKEY
ARG ARG_FRIENDLY_CAPTCHA_PUZZLE_ENDPOINT

ENV NEXT_PUBLIC_SANITY_DATASET ${ARG_SANITY_DATASET}
ENV NEXT_PUBLIC_SANITY_PROJECT_ID ${ARG_SANITY_PROJECT_ID}
ENV SANITY_API_TOKEN ${ARG_SANITY_API_TOKEN}
ENV NEXT_PUBLIC_ALGOLIA_APP_ID ${ARG_ALGOLIA_APP_ID}
ENV NEXT_PUBLIC_ALGOLIA_SEARCH_API_KEY ${ARG_ALGOLIA_SEARCH_API_KEY}
ENV NEXT_PUBLIC_ARCHIVE_CONTENT_LINK ${ARG_ARCHIVE_CONTENT_LINK}
ENV NEXT_PUBLIC_FRIENDLY_CAPTCHA_SITEKEY ${ARG_FRIENDLY_CAPTCHA_SITEKEY}
ENV NEXT_PUBLIC_FRIENDLY_CAPTCHA_PUZZLE_ENDPOINT ${ARG_FRIENDLY_CAPTCHA_PUZZLE_ENDPOINT}

# https://nextjs.org/telemetry
ENV NEXT_TELEMETRY_DISABLED 1
Expand All @@ -53,11 +57,15 @@ ARG ARG_ENV
ARG ARG_SANITY_DATASET
ARG ARG_ALGOLIA_APP_ID
ARG ARG_ALGOLIA_SEARCH_API_KEY
ARG ARG_FRIENDLY_CAPTCHA_SITEKEY
ARG ARG_FRIENDLY_CAPTCHA_PUZZLE_ENDPOINT

ENV ENV ${ARG_ENV}
ENV NEXT_PUBLIC_SANITY_DATASET ${ARG_SANITY_DATASET}
ENV NEXT_PUBLIC_ALGOLIA_APP_ID ${ARG_ALGOLIA_APP_ID}
ENV NEXT_PUBLIC_ALGOLIA_SEARCH_API_KEY ${ARG_ALGOLIA_SEARCH_API_KEY}
ENV NEXT_PUBLIC_FRIENDLY_CAPTCHA_SITEKEY ${ARG_FRIENDLY_CAPTCHA_SITEKEY}
ENV NEXT_PUBLIC_FRIENDLY_CAPTCHA_PUZZLE_ENDPOINT ${ARG_FRIENDLY_CAPTCHA_PUZZLE_ENDPOINT}

ENV PORT 3000
ENV USER nextjs
Expand Down
5 changes: 5 additions & 0 deletions web/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,8 @@ export const algolia = {
applicationId: process.env.NEXT_PUBLIC_ALGOLIA_APP_ID || '',
searchApiKey: process.env.NEXT_PUBLIC_ALGOLIA_SEARCH_API_KEY || '',
}

export const friendlyCaptcha = {
siteKey: process.env.NEXT_PUBLIC_FRIENDLY_CAPTCHA_SITEKEY || '',
puzzleEndpoint: process.env.NEXT_PUBLIC_FRIENDLY_CAPTCHA_PUZZLE_ENDPOINT || '',
}
6 changes: 3 additions & 3 deletions web/pageComponents/topicPages/Form/FriendlyCaptcha.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useEffect, useRef } from 'react'
import { WidgetInstance } from 'friendly-challenge'
import { friendlyCaptcha } from '../../../lib/config'

const FriendlyCaptcha = ({ doneCallback, errorCallback }) => {
const sitekey = process.env.NEXT_PUBLIC_FRIENDLY_CAPTCHA_SITEKEY
const puzzleEndpoint = process.env.NEXT_PUBLIC_FRIENDLY_CAPTCHA_PUZZLE_ENDPOINT
const puzzleEndpoint = friendlyCaptcha.puzzleEndpoint
const container = useRef()
const widget = useRef()
useEffect(() => {
Expand All @@ -17,7 +17,7 @@ const FriendlyCaptcha = ({ doneCallback, errorCallback }) => {
}
}, [container, doneCallback, errorCallback, puzzleEndpoint])

return <div ref={container} className="frc-captcha" data-sitekey={sitekey} />
return <div ref={container} className="frc-captcha" data-sitekey={friendlyCaptcha.siteKey} />
}

export default FriendlyCaptcha

0 comments on commit 0bb8fd2

Please sign in to comment.