feat(docker): Prep master for docker deploys
This commit is contained in:
committed by
mrugesh mohapatra
parent
9e4583b1f3
commit
d79f9f4899
@ -2,37 +2,26 @@ const fs = require('fs');
|
||||
const path = require('path');
|
||||
const debug = require('debug');
|
||||
|
||||
const envPath = path.resolve(__dirname, '../../.env');
|
||||
require('dotenv').config({ path: envPath });
|
||||
const env = require('../../config/env');
|
||||
|
||||
const { getChallengesForLang } = require('../../curriculum/getChallenges');
|
||||
const { createPathMigrationMap } = require('./seed/createPathMigrationMap');
|
||||
|
||||
const { createRedirects } = require('./createRedirects');
|
||||
|
||||
const log = debug('fcc:tools:ensure-env');
|
||||
const {
|
||||
HOME_LOCATION: home,
|
||||
API_LOCATION: api,
|
||||
FORUM_LOCATION: forum,
|
||||
FORUM_PROXY_LOCATION: forumProxy,
|
||||
LOCALE: locale,
|
||||
NODE_ENV: NODE_ENV
|
||||
} = process.env;
|
||||
|
||||
const locations = {
|
||||
homeLocation: home,
|
||||
apiLocation: api,
|
||||
forumLocation: forum,
|
||||
forumProxyLocation: forumProxy
|
||||
};
|
||||
const { NODE_ENV } = process.env;
|
||||
|
||||
const { homeLocation: home, apiLocation: api, forumLocation: forum, locale } = env;
|
||||
|
||||
const apiPath = path.resolve(__dirname, '../../api-server');
|
||||
const clientPath = path.resolve(__dirname, '../../client');
|
||||
const clientStaticPath = path.resolve(clientPath, 'static');
|
||||
const globalConfigPath = path.resolve(__dirname, '../../config');
|
||||
const env = Object.assign(locations, {locale});
|
||||
|
||||
if (NODE_ENV === 'production') {
|
||||
const redirects = createRedirects({ api, home, forum, forumProxy });
|
||||
const redirects = createRedirects({ api, home, forum });
|
||||
fs.writeFile(`${clientStaticPath}/_redirects`, redirects, function(err) {
|
||||
if (err) {
|
||||
log('Error');
|
||||
@ -44,13 +33,23 @@ if (NODE_ENV === 'production') {
|
||||
log(`ignoring creation of redirect file in ${NODE_ENV}`);
|
||||
}
|
||||
|
||||
fs.access(`${apiPath}/server/resources/pathMigration.json`, err => {
|
||||
if (err) {
|
||||
const migrationMapPath = `${apiPath}/server/resources/pathMigration.json`;
|
||||
fs.access(migrationMapPath, err => {
|
||||
if (err && NODE_ENV !== 'production') {
|
||||
log('creating pathMigration');
|
||||
return fs.writeFileSync(
|
||||
`${apiPath}/server/resources/pathMigration.json`,
|
||||
'{}'
|
||||
);
|
||||
return fs.writeFileSync(migrationMapPath, '{}');
|
||||
}
|
||||
if (NODE_ENV === 'production') {
|
||||
return getChallengesForLang(locale)
|
||||
.then(createPathMigrationMap)
|
||||
.then(map => {
|
||||
fs.writeFileSync(migrationMapPath, JSON.stringify(map));
|
||||
log('pathMigration has been written');
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
log('pathMigration present');
|
||||
return null;
|
||||
|
Reference in New Issue
Block a user