freeCodeCamp/client/tools/read-env.ts

81 lines
2.3 KiB
TypeScript
Raw Normal View History

import path from 'path';
import { config } from 'dotenv';
const envPath = path.resolve(__dirname, '../../.env');
const { error } = config({ path: envPath });
feat: add Docker build (#41187) * feat(docker): build and use client and api images * feat: always use .env dotenv fails without throwing if the .env file is missing and never overwrites variables if they already exist. As such, we can use it in build pipelines. * fix: remove quotes from env vars dotenv normalises quoted and unquoted strings (X=x, X='x' and X="x") all become the same .env object {X: 'x'}. However, Docker's env_file does not (the three cases are distinct). As a result, we should use unquoted strings for consistency. * fix: provide custom warning when .env is missing * feat(docker): include client-config * fix(docker): remove build packages from api image * fix(docker): run script from correct dir * fix(docker): correct permissions and dests * fix(docker): consolidate run steps This is standard practice, but did not have a noticable affect on the image size * fix(docker): clean the npm cache Prior to this step the image was 1.11GB uncompressed and we got a modest saving, 1.09GB after. * refactor(docker): regexless COPY directives * feat(docker): use alpine This shrinks the image down to 259MB * fix(docker): update build scripts * fix: correct the server Dockerfile RUNs * DEBUG: expose mysql port for seeding * chore: update client Dockerfile's node versions * fix: remove executable permissions from index.js It's not a cli, so I don't think it needs to be executable. * chore: update node and remove stale comments * feat: use ENTRYPOINT + CMD to allow runtime config * fix: add CURRICULUM_LOCALE arg * feat: allow client port configuration * feat: allow api port to be configured * refactor: use unique variable names for ports * fix: add default CLIENT_PORT * refactor: clean up
2021-04-20 13:59:31 +00:00
if (error) {
console.warn(`
----------------------------------------------------
Warning: .env file not found.
----------------------------------------------------
Please copy sample.env to .env
You can ignore this warning if using a different way
to setup this environment.
----------------------------------------------------
`);
}
const {
HOME_LOCATION: homeLocation,
API_LOCATION: apiLocation,
FORUM_LOCATION: forumLocation,
NEWS_LOCATION: newsLocation,
RADIO_LOCATION: radioLocation,
CLIENT_LOCALE: clientLocale,
CURRICULUM_LOCALE: curriculumLocale,
ALGOLIA_APP_ID: algoliaAppId,
2020-03-13 09:25:57 +00:00
ALGOLIA_API_KEY: algoliaAPIKey,
STRIPE_PUBLIC_KEY: stripePublicKey,
PAYPAL_CLIENT_ID: paypalClientId,
PATREON_CLIENT_ID: patreonClientId,
DEPLOYMENT_ENV: deploymentEnv,
SHOW_UPCOMING_CHANGES: showUpcomingChanges,
SHOW_NEW_CURRICULUM: showNewCurriculum,
GROWTHBOOK_URI: growthbookUri
} = process.env;
const locations = {
homeLocation,
apiLocation,
forumLocation,
newsLocation,
radioLocation: !radioLocation
? 'https://coderadio.freecodecamp.org'
: radioLocation
};
export default Object.assign(locations, {
clientLocale,
curriculumLocale,
deploymentEnv,
environment: process.env.FREECODECAMP_NODE_ENV || 'development',
algoliaAppId:
!algoliaAppId || algoliaAppId === 'app_id_from_algolia_dashboard'
? ''
: algoliaAppId,
algoliaAPIKey:
!algoliaAPIKey || algoliaAPIKey === 'api_key_from_algolia_dashboard'
? ''
2020-03-13 09:25:57 +00:00
: algoliaAPIKey,
stripePublicKey:
!stripePublicKey || stripePublicKey === 'pk_from_stripe_dashboard'
? null
: stripePublicKey,
2020-03-13 09:25:57 +00:00
paypalClientId:
!paypalClientId || paypalClientId === 'id_from_paypal_dashboard'
? null
: paypalClientId,
patreonClientId:
!patreonClientId || patreonClientId === 'id_from_patreon_dashboard'
? null
: patreonClientId,
showUpcomingChanges: showUpcomingChanges === 'true',
showNewCurriculum: showNewCurriculum === 'true',
growthbookUri:
!growthbookUri || growthbookUri === 'api_URI_from_Growthbook_dashboard'
? null
: growthbookUri
});