Skip to content

Commit

Permalink
Merge pull request #451 from hodcroftlab/hotfix-next-config
Browse files Browse the repository at this point in the history
fix: fix deployment type error and update env vars
  • Loading branch information
AdvancedCodingMonkey authored Dec 12, 2024
2 parents b92fce1 + ad241ea commit f31ec95
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 107 deletions.
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,6 @@ Emma B. Hodcroft. 2021. "CoVariants: SARS-CoV-2 Mutations and Variants of Intere
<img src="https://img.shields.io/website?url=https%3A%2F%2Fnextstrain%3Anextstrain%40master.covariants.org&logo=circle&logoColor=white&label=master.covariants.org" />
</a>

<a href="https://travis-ci.com/github/hodcroftlab/covariants/branches">
<img src="https://img.shields.io/travis/hodcroftlab/covariants/release?label=build%3Aproduction" alt="Build status for production" />
</a>
<a href="https://travis-ci.com/github/hodcroftlab/covariants/branches/master">
<img src="https://img.shields.io/travis/hodcroftlab/covariants/master?label=build%3Amaster" alt="Build status for master" />
</a>
</p>

<p align="center">
Expand Down
6 changes: 4 additions & 2 deletions web/.env.vercel
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ DEV_ENABLE_ESLINT=1
DEV_ENABLE_STYLELINT=1

PROD_ENABLE_SOURCE_MAPS=1
PROD_ENABLE_TYPE_CHECKS=0
PROD_ENABLE_ESLINT=0
PROD_ENABLE_TYPE_CHECKS=1
PROD_ENABLE_ESLINT=1
PROD_ENABLE_STYLELINT=0

ANALYZE=0
PROFILE=0

WATCH_POLL=0
26 changes: 12 additions & 14 deletions web/config/next/lib/getEnvVars.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { getbool, getenv } from '../../../lib/getenv'
import { getBoolOrThrow } from '../../../lib/getenv'
import { getDomain } from '../../../lib/getDomain'

export function getEnvVars() {
const BABEL_ENV = getenv('BABEL_ENV')
const NODE_ENV = getenv('NODE_ENV')
const ANALYZE = getbool('ANALYZE')
const PROFILE = getbool('PROFILE')
const NODE_ENV = process.env.NODE_ENV
const ANALYZE = getBoolOrThrow('ANALYZE')
const PROFILE = getBoolOrThrow('PROFILE')
const PRODUCTION = NODE_ENV === 'production'
const DOMAIN = getDomain()
const DOMAIN_STRIPPED = DOMAIN.replace('https://', '').replace('http://', '')
const WATCH_POLL = getbool('WATCH_POLL', false)
const WATCH_POLL = getBoolOrThrow('WATCH_POLL')

const common = {
BABEL_ENV,
NODE_ENV,
ANALYZE,
PROFILE,
Expand All @@ -25,18 +23,18 @@ export function getEnvVars() {
if (PRODUCTION) {
return {
...common,
ENABLE_SOURCE_MAPS: getbool('PROD_ENABLE_SOURCE_MAPS'),
ENABLE_ESLINT: getbool('PROD_ENABLE_ESLINT'),
ENABLE_TYPE_CHECKS: getbool('PROD_ENABLE_TYPE_CHECKS'),
ENABLE_STYLELINT: getbool('PROD_ENABLE_STYLELINT'),
ENABLE_SOURCE_MAPS: getBoolOrThrow('PROD_ENABLE_SOURCE_MAPS'),
ENABLE_ESLINT: getBoolOrThrow('PROD_ENABLE_ESLINT'),
ENABLE_TYPE_CHECKS: getBoolOrThrow('PROD_ENABLE_TYPE_CHECKS'),
ENABLE_STYLELINT: getBoolOrThrow('PROD_ENABLE_STYLELINT'),
}
}

return {
...common,
ENABLE_SOURCE_MAPS: true,
ENABLE_ESLINT: getbool('DEV_ENABLE_ESLINT'),
ENABLE_TYPE_CHECKS: getbool('DEV_ENABLE_TYPE_CHECKS'),
ENABLE_STYLELINT: getbool('DEV_ENABLE_STYLELINT'),
ENABLE_ESLINT: getBoolOrThrow('DEV_ENABLE_ESLINT'),
ENABLE_TYPE_CHECKS: getBoolOrThrow('DEV_ENABLE_TYPE_CHECKS'),
ENABLE_STYLELINT: getBoolOrThrow('DEV_ENABLE_STYLELINT'),
}
}
5 changes: 0 additions & 5 deletions web/lib/getBuildNumber.ts

This file was deleted.

5 changes: 0 additions & 5 deletions web/lib/getBuildUrl.ts

This file was deleted.

25 changes: 7 additions & 18 deletions web/lib/getDomain.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,26 @@
/* eslint-disable lodash/prefer-is-nil */
import isInteractive from 'is-interactive'

import { getenv } from './getenv'
import { getEnvOrThrow } from './getenv'

const WEB_PORT_DEV = getenv('WEB_PORT_DEV', null)
const WEB_PORT_PROD = getenv('WEB_PORT_PROD', null)
const WEB_PORT_DEV = process.env.WEB_PORT_DEV ?? ''
const WEB_PORT_PROD = process.env.WEB_PORT_PROD ?? ''
const devDomain = `http://localhost:${WEB_PORT_DEV}`
const prodDomain = `http://localhost:${WEB_PORT_PROD}`

const ENV_VARS = [
// prettier-ignore
'VERCEL_URL',
'NOW_URL',
'ZEIT_URL',
'DEPLOY_PRIME_URL',
'DEPLOY_URL',
'URL',
]

export function getenvFirst(vars: string[]) {
return vars.map((v) => getenv(v, null)).find((v) => v !== undefined && v !== null)
return vars.map((v) => process.env[v]).find((v) => v !== undefined)
}

export function listEnvVars(vars: string[]) {
return vars
.map((v) => {
let val = getenv(v, null)
if (val === null) {
val = ''
}
return `\n - ${v}=${val}`
})
.join('')
return vars.map((v) => `\n - ${v}=${process.env[v] ?? ''}`).join('')
}

export function devError() {
Expand All @@ -49,7 +38,7 @@ export function devError() {
}

export function getDomain() {
let DOMAIN = getenv('FULL_DOMAIN')
let DOMAIN = getEnvOrThrow('FULL_DOMAIN')

if (DOMAIN === 'autodetect') {
const interactive = isInteractive()
Expand All @@ -71,7 +60,7 @@ export function getDomain() {
DOMAIN = detectedDomain
}

if (!DOMAIN?.startsWith('http')) {
if (!DOMAIN.startsWith('http')) {
DOMAIN = `https://${DOMAIN}`
}

Expand Down
17 changes: 5 additions & 12 deletions web/lib/getGitBranch.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { execSync } from 'child_process'

import { getenv } from './getenv'

export function getGitCommitHashLocal() {
try {
return execSync('git rev-parse --abbrev-ref HEAD').toString().trim()
Expand All @@ -12,16 +10,11 @@ export function getGitCommitHashLocal() {

export function getGitBranch() {
return (
getenv('GIT_BRANCH', null) ??
getenv('BRANCH', null) ??
getenv('TRAVIS_BRANCH', null) ??
getenv('NOW_GITHUB_COMMIT_REF', null) ??
getenv('VERCEL_GITHUB_COMMIT_REF', null) ??
getenv('VERCEL_GITLAB_COMMIT_REF', null) ??
getenv('VERCEL_BITBUCKET_COMMIT_REF', null) ??
getenv('ZEIT_GITHUB_COMMIT_REF', null) ??
getenv('ZEIT_GITLAB_COMMIT_REF', null) ??
getenv('ZEIT_BITBUCKET_COMMIT_REF', null) ??
process.env.GIT_BRANCH ??
process.env.BRANCH ??
process.env.VERCEL_GITHUB_COMMIT_REF ??
process.env.VERCEL_GITLAB_COMMIT_REF ??
process.env.VERCEL_BITBUCKET_COMMIT_REF ??
getGitCommitHashLocal() ??
''
)
Expand Down
24 changes: 9 additions & 15 deletions web/lib/getGitCommitHash.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { execSync } from 'child_process'

import { getenv } from './getenv'

export function getGitCommitHashLocal() {
try {
return execSync('git rev-parse HEAD').toString().trim()
Expand All @@ -12,18 +10,14 @@ export function getGitCommitHashLocal() {

export function getGitCommitHash() {
return (
getenv('GIT_COMMIT', null) ??
getenv('GIT_COMMIT_HASH', null) ??
getenv('TRAVIS_COMMIT', null) ??
getenv('NOW_GITHUB_COMMIT_SHA', null) ??
getenv('GITHUB_SHA', null) ??
getenv('COMMIT_REF', null) ??
getenv('VERCEL_GITHUB_COMMIT_SHA', null) ??
getenv('VERCEL_GITLAB_COMMIT_SHA', null) ??
getenv('VERCEL_BITBUCKET_COMMIT_SHA', null) ??
getenv('ZEIT_GITHUB_COMMIT_SHA', null) ??
getenv('ZEIT_GITLAB_COMMIT_SHA', null) ??
getenv('ZEIT_BITBUCKET_COMMIT_SHA', null) ??
getGitCommitHashLocal()
process.env.GIT_COMMIT ??
process.env.GIT_COMMIT_HASH ??
process.env.GITHUB_SHA ??
process.env.COMMIT_REF ??
process.env.VERCEL_GITHUB_COMMIT_SHA ??
process.env.VERCEL_GITLAB_COMMIT_SHA ??
process.env.VERCEL_BITBUCKET_COMMIT_SHA ??
getGitCommitHashLocal() ??
''
)
}
18 changes: 5 additions & 13 deletions web/lib/getenv.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
import EnvVarError from './EnvVarError'

function getenv(key: string, defaultValue?: string | null) {
function getEnvOrThrow(key: string) {
const value = process.env[key]
if (!value) {
if (defaultValue !== undefined) {
return defaultValue
}

if (value === undefined) {
throw new EnvVarError(key, value)
}
return value
}

function getbool(key: string, defaultValue?: string) {
function getBoolOrThrow(key: string) {
const value = process.env[key]
if (!value) {
if (defaultValue !== undefined) {
return defaultValue
}

if (value === undefined) {
throw new EnvVarError(key, value)
}

return value === '1' || value === 'true' || value === 'yes'
}

export { getenv, getbool }
export { getBoolOrThrow, getEnvOrThrow }
15 changes: 2 additions & 13 deletions web/next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import remarkMath from 'remark-math'

import { findModuleRoot } from './lib/findModuleRoot'
import { getGitBranch } from './lib/getGitBranch'
import { getBuildNumber } from './lib/getBuildNumber'
import { getBuildUrl } from './lib/getBuildUrl'
import { getGitCommitHash } from './lib/getGitCommitHash'
import { getEnvVars } from './config/next/lib/getEnvVars'

Expand All @@ -33,8 +31,7 @@ import withWebpackWatchPoll from './config/next/withWebpackWatchPoll'
import withUrlAsset from './config/next/withUrlAsset'

const {
// BABEL_ENV,
// NODE_ENV,
NODE_ENV,
// ANALYZE,
PROFILE,
PRODUCTION,
Expand All @@ -54,8 +51,6 @@ const { pkg, moduleRoot } = findModuleRoot()
const clientEnv = {
BRANCH_NAME,
PACKAGE_VERSION: pkg.version ?? '',
BUILD_NUMBER: getBuildNumber(),
TRAVIS_BUILD_WEB_URL: getBuildUrl(),
COMMIT_HASH: getGitCommitHash(),
DOMAIN,
DOMAIN_STRIPPED,
Expand All @@ -64,7 +59,7 @@ const clientEnv = {
console.info(`Client-side Environment:\n${JSON.stringify(clientEnv, null, 2)}`)

const nextConfig: NextConfig = {
distDir: `.build/${process.env.NODE_ENV}/web`,
distDir: `.build/${NODE_ENV}/web`,
pageExtensions: ['js', 'jsx', 'ts', 'tsx', 'md', 'mdx', 'all-contributorsrc'],
onDemandEntries: {
maxInactiveAge: 60 * 1000,
Expand All @@ -81,12 +76,6 @@ const nextConfig: NextConfig = {
devIndicators: {
buildActivity: false,
},
typescript: {
ignoreBuildErrors: true,
},
eslint: {
ignoreDuringBuilds: true,
},
compiler: {
styledComponents: true,
},
Expand Down
7 changes: 3 additions & 4 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
"scripts": {
"data": "cd .. && python3 scripts/convert_to_web_app_json.py",
"dev": "nodemon --config config/nodemon/dev.json",
"dev:start": "yarn install && yarn cross-env NODE_ENV=development BABEL_ENV=development next dev --port 3000 || cd .",
"prod:build": "yarn next:build && yarn next:export",
"dev:start": "yarn install && yarn next dev || cd .",
"prod:build": "yarn next build && yarn next:export",
"prod:build:vercel": "cp .env.vercel .env && yarn install && yarn prod:build && cp .next/routes-manifest.json .build/production/web/",
"prod:build:profile": "PROFILE=1 yarn next:build --profile && yarn next:export",
"next:build": "cross-env NODE_ENV=production BABEL_ENV=production next build",
"prod:build:profile": "PROFILE=1 yarn next build --profile && yarn next:export",
"next:export": "cp .next/robots.txt .build/production/web/robots.txt",
"prod:start": "yarn prod:build && yarn prod:serve || cd .",
"prod:serve": "yarn serve .build/production/web --listen 8080",
Expand Down

0 comments on commit f31ec95

Please sign in to comment.