- Build-time (public):
NEXT_PUBLIC_CAPTCHA_KEY - Runtime (secret):
CAT_API_KEY,MJ_APIKEY_PUBLIC,MJ_APIKEY_PRIVATE,CAPTCHA_SECRET(and also setNEXT_PUBLIC_CAPTCHA_KEYso the app sees it at runtime).
- Copy
.env.exampleto.env.localand fill in values. - Run
npm run dev(Next.js loads.env.localautomatically).
- Build the image (inject only the public key):
docker build --build-arg NEXT_PUBLIC_CAPTCHA_KEY=... -t ghcr.io/ebox86/portfolio-website:latest . - Push the image to your registry (GHCR or Artifact Registry).
- Set runtime env vars on the Cloud Run service:
CAT_API_KEY,MJ_APIKEY_PUBLIC,MJ_APIKEY_PRIVATE,CAPTCHA_SECRET,NEXT_PUBLIC_CAPTCHA_KEY- From the CLI you can run:
./scripts/update-cloud-run-env.sh
(override SERVICE/REGION/PROJECT/ENV_FILE via env vars; defaults: serviceportfolio, regionus-east4, projectportfolio-website-403402, env file.env).
- From the CLI you can run:
- Deploy:
gcloud run deploy portfolio --region=us-central1 --image=ghcr.io/ebox86/portfolio-website:latest --allow-unauthenticated --set-env-vars CAT_API_KEY=...,MJ_APIKEY_PUBLIC=...,MJ_APIKEY_PRIVATE=...,CAPTCHA_SECRET=...,NEXT_PUBLIC_CAPTCHA_KEY=...
- Build and push a container image (same as above).
- Create a
Deploymentthat runs the container on port 8080 with env vars forCAT_API_KEY,MJ_APIKEY_PUBLIC,MJ_APIKEY_PRIVATE,CAPTCHA_SECRET,NEXT_PUBLIC_CAPTCHA_KEY. UseenvFrom+ aSecret/ConfigMapinstead of hardcoding. - Expose via a
Service(ClusterIP) and anIngress/Ingress Controller (NGINX, GKE Ingress, etc.). Example minimalService:apiVersion: v1 kind: Service metadata: name: portfolio-web spec: selector: app: portfolio-web ports: - port: 80 targetPort: 8080
- If the cluster sits behind a load balancer, terminate TLS at the ingress and route to the service.
Next.js can be packed for Lambda using @sls-next/serverless-component (Serverless Framework) or npx @vercel/node style adapters. High-level steps with Serverless Framework:
- Install tooling:
npm i -D serverless @sls-next/serverless-componentand add aserverless.yml. - Configure
serverless.yml:component: '@sls-next/serverless-component@3.7.0' inputs: domain: null runtime: nodejs18.x env: CAT_API_KEY: ${env:CAT_API_KEY} MJ_APIKEY_PUBLIC: ${env:MJ_APIKEY_PUBLIC} MJ_APIKEY_PRIVATE: ${env:MJ_APIKEY_PRIVATE} CAPTCHA_SECRET: ${env:CAPTCHA_SECRET} NEXT_PUBLIC_CAPTCHA_KEY: ${env:NEXT_PUBLIC_CAPTCHA_KEY}
- Export the env vars locally (or use AWS SSM/Secrets Manager) and deploy:
npx serverless. - The component creates Lambda@Edge/API Gateway + S3 for static assets; confirm the generated URL works and set your custom domain via Route 53/ACM if needed.
If you prefer containers on AWS, run the same image on Lambda (container runtime) or ECS/Fargate with an ALB; supply the env vars there.
