Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simplify env vars and better debug output #3203

Merged
merged 5 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions .github/workflows/env.yaml

This file was deleted.

17 changes: 1 addition & 16 deletions apps/web/.env
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
# Uncomment the next line to test a local API / Auth
#NEXT_PUBLIC_ENV=local
NEXT_PUBLIC_ENV=staging
NEXT_PUBLIC_SERLO_DOMAIN_PRODUCTION=serlo.org
NEXT_PUBLIC_SERLO_DOMAIN_STAGING=serlo-staging.dev
NEXT_PUBLIC_SERLO_DOMAIN_LOCAL=serlo.localhost:4567
# empty string if not on vercel
NEXT_PUBLIC_VERCEL_URL=
# empty string if not on vercel
NEXT_PUBLIC_COMMIT_SHA=
HYDRA_CLIENT_ID_STAGING=frontend
HYDRA_CLIENT_SECRET_STAGING=YjgwZThhZDk0MTYxMTA4ODY1NzYxZmJk
HYDRA_HOST_STAGING=https://hydra.${NEXT_PUBLIC_SERLO_DOMAIN_STAGING}
HYDRA_CLIENT_ID_LOCAL=frontend.serlo.org
HYDRA_CLIENT_SECRET_LOCAL=frontend.serlo.org
HYDRA_HOST_LOCAL=http://localhost:4444
KRATOS_HOST_STAGING=https://kratos.${NEXT_PUBLIC_SERLO_DOMAIN_STAGING}
KRATOS_HOST_LOCAL=http://localhost:4433
NEXT_PUBLIC_ENV=staging
9 changes: 0 additions & 9 deletions apps/web/.env.production

This file was deleted.

33 changes: 1 addition & 32 deletions apps/web/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,42 +2,11 @@ declare namespace NodeJS {
interface ProcessEnv {
// Environment to use
NEXT_PUBLIC_ENV: 'production' | 'staging' | 'local'
// Serlo domain for production environment
NEXT_PUBLIC_SERLO_DOMAIN_PRODUCTION: string
// Serlo domain to be used in staging environment
NEXT_PUBLIC_SERLO_DOMAIN_STAGING: string
// Sentry DSN (defined in preview & production)
NEXT_PUBLIC_SENTRY_DSN: string | undefined
// Google Analytics Tracking ID (defined in production)
NEXT_PUBLIC_GA_TRACKING_ID: string | undefined
// The GitHub SHA of the commit the deployment was triggered by (defined in preview & production)
NEXT_PUBLIC_COMMIT_SHA: string | undefined
NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA: string | undefined
// The public facing url of the deployment (defined in preview & production)
NEXT_PUBLIC_VERCEL_URL: string | undefined

// Hydra client id for production environment (defined in preview & production, only exposed to server)
HYDRA_CLIENT_ID_PRODUCTION: string | undefined
// Hydra client id for staging environment (only exposed to server)
HYDRA_CLIENT_ID_STAGING: string
// Hydra client id for local environment (only exposed to server)
HYDRA_CLIENT_ID_LOCAL: string
// Hydra client secret for production environment (defined in preview & production, only exposed to server)
HYDRA_CLIENT_SECRET_PRODUCTION: string | undefined
// Hydra client secret for staging environment (only exposed to server)
HYDRA_CLIENT_SECRET_STAGING: string
// Hydra client secret for local environment (only exposed to server)
HYDRA_CLIENT_SECRET_LOCAL: string
// Hydra host for production environment (defined in preview & production, only exposed to server)
HYDRA_HOST_PRODUCTION: string | undefined
// Hydra host for staging environment (only exposed to server)
HYDRA_HOST_STAGING: string
// Hydra host for local environment (only exposed to server)
HYDRA_HOST_LOCAL: string
// Kratos host for production environment (defined in preview & production, only exposed to server)
KRATOS_HOST_PRODUCTION: string | undefined
// Kratos host for staging environment (only exposed to server)
KRATOS_HOST_STAGING: string
// Kratos host for local environment (only exposed to server)
KRATOS_HOST_LOCAL: string
}
}
22 changes: 21 additions & 1 deletion apps/web/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,30 @@ import bundleAnalyzer from '@next/bundle-analyzer'
import path from 'path'
import { fileURLToPath } from 'url'

// check and display env variables
console.log(
'current active environment (staging or production):',
'[NEXT_PUBLIC_ENV] selected environment (staging or production):',
process.env.NEXT_PUBLIC_ENV
)
console.log(
'[NEXT_PUBLIC_SENTRY_DSN] sentry dsn:',
process.env.NEXT_PUBLIC_SENTRY_DSN ?? '---'
)
console.log(
'[NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA] commit sha:',
process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA ?? '---'
)
console.log(
'[NEXT_PUBLIC_VERCEL_URL] deployment url:',
process.env.NEXT_PUBLIC_VERCEL_URL ?? '---'
)
console.log(
'[DATABASE_URL] planetscale integration:',
process.env.DATABASE_URL &&
process.env.DATABASE_URL.includes('serlo_planetscale')
? 'available'
: 'not available'
)

/**
* @type {import('next').NextConfig}
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/auth/cookie/cookie-domain.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const COOKIE_DOMAINS = {
production: process.env.NEXT_PUBLIC_SERLO_DOMAIN_PRODUCTION,
staging: process.env.NEXT_PUBLIC_SERLO_DOMAIN_STAGING,
production: 'serlo.org',
staging: 'serlo-staging.dev',
local: 'localhost',
}

Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/helper/urls/serlo-domain.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const serloDomain =
process.env.NEXT_PUBLIC_ENV === 'production'
? process.env.NEXT_PUBLIC_SERLO_DOMAIN_PRODUCTION
: process.env.NEXT_PUBLIC_SERLO_DOMAIN_STAGING
? 'serlo.org'
: 'serlo-staging.dev'
4 changes: 2 additions & 2 deletions apps/web/src/pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const sentryLoader = `
window.Sentry.init({
environment: "${process.env.NEXT_PUBLIC_ENV}",
release: "frontend@${
process.env.NEXT_PUBLIC_COMMIT_SHA?.substring(0, 7) ?? ''
process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA?.substring(0, 7) ?? ''
}",
beforeSend(event, hint) {
/* ignore safari warning in JsonLd component */
Expand Down Expand Up @@ -108,7 +108,7 @@ export default class MyDocument extends Document {
/>
)}
{process.env.NEXT_PUBLIC_SENTRY_DSN !== undefined &&
process.env.NEXT_PUBLIC_COMMIT_SHA !== undefined && (
process.env.NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA !== undefined && (
<script
dangerouslySetInnerHTML={{
__html: sentryLoader,
Expand Down
10 changes: 5 additions & 5 deletions apps/web/src/pages/api/.ory/[...paths].ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { createApiHandler, config } from '@ory/integrations/next-edge'
export { config }

const COOKIE_DOMAINS = {
production: process.env.NEXT_PUBLIC_SERLO_DOMAIN_PRODUCTION,
staging: process.env.NEXT_PUBLIC_SERLO_DOMAIN_STAGING,
production: 'serlo.org',
staging: 'serlo-staging.dev',
local: 'localhost',
}

Expand All @@ -16,9 +16,9 @@ export const COOKIE_DOMAIN =
: COOKIE_DOMAINS['local']

const KRATOS_HOSTS = {
production: process.env.KRATOS_HOST_PRODUCTION,
staging: process.env.KRATOS_HOST_STAGING,
local: process.env.KRATOS_HOST_LOCAL,
production: 'https://kratos.serlo.org',
staging: 'https://kratos.serlo-staging.dev',
local: 'http://localhost:4433',
}

// if env is not set, it's a production build running on localhost, use staging as default
Expand Down
Loading