Skip to content

Commit 4865749

Browse files
authored
Merge pull request #1173 from CodeForAfrica/chore/trustlab_improve_setup
Improve `@/trustlab` setup
2 parents 4b9994f + 4b96aca commit 4865749

File tree

5 files changed

+34
-19
lines changed

5 files changed

+34
-19
lines changed

Dockerfile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,7 @@ COPY apps/trustlab ./apps/trustlab
954954
RUN --mount=type=secret,id=mongo_url,env=MONGO_URL \
955955
--mount=type=secret,id=payload_secret,env=PAYLOAD_SECRET \
956956
--mount=type=secret,id=sentry_auth_token,env=SENTRY_AUTH_TOKEN \
957+
--mount=type=secret,id=smtp_pass,env=SMTP_PASS \
957958
pnpm --filter trustlab build
958959

959960
#
@@ -962,11 +963,6 @@ RUN --mount=type=secret,id=mongo_url,env=MONGO_URL \
962963

963964
FROM base-runner AS trustlab-runner
964965

965-
# RUN set -ex \
966-
# # Create nextjs cache dir w/ correct permissions
967-
# && mkdir -p ./apps/trustlab/.next \
968-
# && chown nextjs:nodejs ./apps/trustlab/.next
969-
970966
# PNPM
971967
# symlink some dependencies
972968
COPY --from=trustlab-builder --link --chown=nextjs:nodejs /workspace/node_modules ./node_modules

apps/trustlab/src/payload/plugins/index.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ import { seoPlugin } from "@payloadcms/plugin-seo";
44
import { s3Storage } from "@payloadcms/storage-s3";
55
import * as Sentry from "@sentry/nextjs";
66

7+
const accessKeyId = process.env.S3_ACCESS_KEY_ID ?? "";
8+
const bucket = process.env.S3_BUCKET ?? "";
9+
const region = process.env.S3_REGION ?? "";
10+
const secretAccessKey = process.env.S3_SECRET_ACCESS_KEY ?? "";
11+
const s3Enabled = !!accessKeyId && !!region && !!secretAccessKey;
12+
713
const plugins = [
814
nestedDocsPlugin({
915
collections: ["pages"],
@@ -14,14 +20,15 @@ const plugins = [
1420
collections: {
1521
media: true,
1622
},
17-
bucket: process.env.S3_BUCKET ?? "",
23+
bucket,
1824
config: {
1925
credentials: {
20-
accessKeyId: process.env.S3_ACCESS_KEY_ID ?? "",
21-
secretAccessKey: process.env.S3_SECRET_ACCESS_KEY ?? "",
26+
accessKeyId,
27+
secretAccessKey,
2228
},
23-
region: process.env.S3_REGION ?? "",
29+
region,
2430
},
31+
enabled: s3Enabled,
2532
}),
2633
sentryPlugin({
2734
options: {

docker-compose.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,20 @@ services:
189189

190190
trustlab:
191191
build:
192+
# env_file attribute is for runtime
193+
# We need args to be available at build time & hence we need to
194+
# specify them here; they come from --env-file command-line argument(s)
192195
args:
196+
- NEXT_PUBLIC_APP_URL=${NEXT_PUBLIC_APP_URL}
193197
- SENTRY_ENVIRONMENT="local"
198+
- SMTP_HOST=${SMTP_HOST}
199+
- SMTP_USER=${SMTP_USER}
194200
context: .
195201
secrets:
196202
- mongo_url
197203
- payload_secret
198204
- sentry_auth_token
205+
- smtp_pass
199206
target: trustlab-runner
200207
env_file:
201208
- path: ./apps/trustlab/.env
@@ -266,5 +273,7 @@ secrets:
266273
environment: PAYLOAD_SECRET
267274
sentry_auth_token:
268275
environment: SENTRY_AUTH_TOKEN
276+
smtp_pass:
277+
environment: SMTP_PASS
269278
volumes:
270279
db_data:

jsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
"@/commons-ui/payload/*": ["./packages/commons-ui-payload/src/*"]
1515
}
1616
},
17-
"exclude": ["node_modules"]
17+
"exclude": ["node_modules", "**/node_modules/*"]
1818
}

scripts/dc.sh

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
#!/bin/bash
22

33
APP="$1"
4-
APP_ENV_FILE="./apps/${APP}/.env.local"
54
REPO_SHA=$(git log --pretty=format:'%h' --max-count=1)
6-
set -a
7-
source "${APP_ENV_FILE}" # Load the environment variables from the .env.local file
8-
set +a
95

10-
# Don't override IMAGE_TAG, BUILDKIT_PROGRESS, etc. if already set
11-
IMAGE_TAG=${IMAGE_TAG-${REPO_SHA}} \
12-
BUILDKIT_PROGRESS=${BUILDKIT_PROGRESS-plain} \
13-
docker compose --env-file "${APP_ENV_FILE}" \
14-
up "${APP}" --build
6+
# Don't override IMAGE_TAG and BUILDKIT_PROGRESS if already set.
7+
# `compose` now supports multiple `--env-file` args
8+
# see:
9+
# https://github.com/docker/compose/releases/tag/v2.17.0-rc.1
10+
# verify via:
11+
# `docker compose --env-file ./apps/trustlab/.env --env-file ./apps/trustlab/.env.local config --environment`
12+
IMAGE_TAG=${IMAGE_TAG:-${REPO_SHA}} \
13+
BUILDKIT_PROGRESS=${BUILDKIT_PROGRESS:-plain} \
14+
docker compose \
15+
--env-file "./apps/${APP}/.env" \
16+
--env-file "./apps/${APP}/.env.local" \
17+
up "${APP}"

0 commit comments

Comments
 (0)