Skip to content

Commit 1ec19aa

Browse files
committed
fix (deployment): resolving buildtime env vars issue (WIP)
1 parent a7f0b91 commit 1ec19aa

File tree

3 files changed

+53
-7
lines changed

3 files changed

+53
-7
lines changed

src/client/Dockerfile

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,32 @@
44
FROM node:20-slim AS builder
55
WORKDIR /app
66

7+
# ---- MODIFIED SECTION ----
8+
# Declare all build-time arguments that your application needs.
9+
# Anything prefixed with NEXT_PUBLIC_ is needed for the client-side bundle.
10+
# Others are needed for server-side logic during the build (if any).
11+
ARG NEXT_PUBLIC_APP_SERVER_URL
12+
ARG AUTH0_SECRET
13+
ARG AUTH0_BASE_URL # This is a legacy var in the template, you have APP_BASE_URL
14+
ARG APP_BASE_URL
15+
ARG AUTH0_ISSUER_BASE_URL
16+
ARG AUTH0_CLIENT_ID
17+
ARG AUTH0_CLIENT_SECRET
18+
ARG AUTH0_AUDIENCE
19+
ARG AUTH0_SCOPE
20+
21+
# Set them as environment variables for the build process
22+
ENV NEXT_PUBLIC_APP_SERVER_URL=$NEXT_PUBLIC_APP_SERVER_URL
23+
ENV AUTH0_SECRET=$AUTH0_SECRET
24+
ENV AUTH0_BASE_URL=$AUTH0_BASE_URL
25+
ENV APP_BASE_URL=$APP_BASE_URL
26+
ENV AUTH0_ISSUER_BASE_URL=$AUTH0_ISSUER_BASE_URL
27+
ENV AUTH0_CLIENT_ID=$AUTH0_CLIENT_ID
28+
ENV AUTH0_CLIENT_SECRET=$AUTH0_CLIENT_SECRET
29+
ENV AUTH0_AUDIENCE=$AUTH0_AUDIENCE
30+
ENV AUTH0_SCOPE=$AUTH0_SCOPE
31+
# --------------------------
32+
733
# Copy package.json and lock file to leverage Docker cache
834
COPY package.json ./
935
RUN npm install
@@ -12,7 +38,7 @@ RUN npm install
1238
COPY . .
1339

1440
# Build the Next.js application for production
15-
# This creates the .next/standalone folder
41+
# This command will now have access to all the ENV vars
1642
RUN npm run build
1743

1844

@@ -33,5 +59,6 @@ COPY --from=builder /app/.next/static ./.next/static
3359
# Expose the port the app will run on
3460
EXPOSE 3000
3561

62+
# The runner stage will get its env vars from the docker-compose 'env_file'
3663
# The command to start the optimized Next.js server
3764
CMD ["node", "server.js"]

src/client/docker-compose.yaml

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
1-
# src/client/docker-compose.yml
1+
# src/client/docker-compose.yaml
22

33
services:
44
sentient-client:
5-
# Build the image from the Dockerfile in the current directory
6-
build: .
5+
build:
6+
context: .
7+
# ---- MODIFIED SECTION ----
8+
# Pass variables from the .env file as build arguments
9+
# This makes them available during `npm run build`
10+
args:
11+
- NEXT_PUBLIC_APP_SERVER_URL=${NEXT_PUBLIC_APP_SERVER_URL}
12+
- AUTH0_SECRET=${AUTH0_SECRET}
13+
- AUTH0_BASE_URL=${AUTH0_BASE_URL}
14+
- APP_BASE_URL=${APP_BASE_URL}
15+
- AUTH0_ISSUER_BASE_URL=${AUTH0_ISSUER_BASE_URL}
16+
- AUTH0_CLIENT_ID=${AUTH0_CLIENT_ID}
17+
- AUTH0_CLIENT_SECRET=${AUTH0_CLIENT_SECRET}
18+
- AUTH0_AUDIENCE=${AUTH0_AUDIENCE}
19+
- AUTH0_SCOPE=${AUTH0_SCOPE}
20+
# -------------------------
721
container_name: sentient-client
8-
# Always restart the container unless it is explicitly stopped
922
restart: unless-stopped
10-
# Map port 3000 on the VM to port 3000 inside the container
1123
ports:
1224
- "3000:3000"
13-
# Load environment variables from a .env file in the same directory
25+
# This loads the SAME .env file into the RUNNING container
26+
# for server-side code to use at runtime.
1427
env_file:
1528
- .env

src/client/next.config.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
// src/client/next.config.js
2+
13
/** @type {import('next').NextConfig} */
24
const nextConfig = {
35
images: {
46
unoptimized: true
7+
},
8+
// Add this section to keep console logs in production builds
9+
compiler: {
10+
removeConsole: false
511
}
612
}
713

0 commit comments

Comments
 (0)