diff --git a/docs/index.md b/docs/index.md index ad9ee7f..e285e36 100644 --- a/docs/index.md +++ b/docs/index.md @@ -21,7 +21,6 @@ - `/deploy` - yargs - nodejs-lib/fs - - js-yaml - simple-git - got - `/testing` diff --git a/resources/backendCfg.schema.json b/resources/backendCfg.schema.json index 698d2d2..40f6ff0 100644 --- a/resources/backendCfg.schema.json +++ b/resources/backendCfg.schema.json @@ -17,8 +17,6 @@ ".*": { "type": "string" } } }, - "serviceWithBranchName": { "type": "boolean", "default": true }, - "prodBranch": { "type": "string" }, "files": { "type": "array", "items": { "type": "string" } diff --git a/src/admin/adminMiddleware.ts b/src/admin/adminMiddleware.ts index 3cb5d2e..e42ecdb 100644 --- a/src/admin/adminMiddleware.ts +++ b/src/admin/adminMiddleware.ts @@ -1,5 +1,5 @@ -import fs from 'node:fs' import { _memoFn, AppError } from '@naturalcycles/js-lib' +import { fs2 } from '@naturalcycles/nodejs-lib' import ejs from 'ejs' import { BackendRequestHandler } from '../server/server.model' import { BaseAdminService } from './base.admin.service' @@ -101,7 +101,7 @@ export function loginHtml(firebaseServiceCfg: FirebaseSharedServiceCfg): Backend const getLoginHtml = _memoFn((cfg: LoginHtmlCfg) => { console.log(`reading login.html`) - const tmpl = fs.readFileSync(`${__dirname}/login.html`, 'utf8') + const tmpl = fs2.readText(`${__dirname}/login.html`) return ejs.render(tmpl, cfg) }) diff --git a/src/deploy/backend.cfg.util.ts b/src/deploy/backend.cfg.util.ts index f875d64..84112ab 100644 --- a/src/deploy/backend.cfg.util.ts +++ b/src/deploy/backend.cfg.util.ts @@ -4,31 +4,14 @@ import { resourcesDir } from '../paths.cnst' export interface BackendCfg { gaeProject: string - gaeProjectByBranch?: StringMap /** * @example default */ gaeService: string - gaeServiceByBranch?: StringMap - /** - * @default true - * - * If true - service name will look like ${branchName}--${gaeService}, similar to Netlify. - * If false - ${gaeService}. - * - * Prod branch NEVER includes branchName in service name. - */ - serviceWithBranchName?: boolean - - /** - * @example prod - */ - prodBranch: string - /** * List of file patterns to include in deployment. */ @@ -61,7 +44,6 @@ export function getBackendCfg(projectDir: string = '.'): BackendCfg { requireFileToExist(backendCfgYamlPath) const backendCfg: BackendCfg = { - serviceWithBranchName: true, ...fs2.readYaml(backendCfgYamlPath), } diff --git a/src/deploy/deploy.model.ts b/src/deploy/deploy.model.ts index cd9b0ae..b5e17a6 100644 --- a/src/deploy/deploy.model.ts +++ b/src/deploy/deploy.model.ts @@ -8,7 +8,6 @@ export interface DeployInfo { serviceUrl: string gitRev: string gitBranch: string - prod: boolean /** * Unix timestamp of deployInfo.json being generated. diff --git a/src/deploy/deploy.util.ts b/src/deploy/deploy.util.ts index c775946..ee76a14 100644 --- a/src/deploy/deploy.util.ts +++ b/src/deploy/deploy.util.ts @@ -1,7 +1,5 @@ -import fs from 'node:fs' import { _assert, _mapValues, _merge, _truncate, localTimeNow } from '@naturalcycles/js-lib' -import { dimGrey, white } from '@naturalcycles/nodejs-lib' -import yaml from 'js-yaml' +import { dimGrey, fs2, white } from '@naturalcycles/nodejs-lib' import { BackendCfg } from './backend.cfg.util' import { AppYaml, DeployInfo } from './deploy.model' @@ -29,12 +27,9 @@ export async function createAndSaveDeployInfo( targetDir: string, ): Promise { const deployInfo = await createDeployInfo(backendCfg) - const deployInfoPath = `${targetDir}/deployInfo.json` - - fs.writeFileSync(deployInfoPath, JSON.stringify(deployInfo, null, 2)) + fs2.writeJson(deployInfoPath, deployInfo, { spaces: 2 }) console.log(`saved ${dimGrey(deployInfoPath)}`) - return deployInfo } @@ -54,18 +49,14 @@ export async function createDeployInfo( gaeProjectByBranch = {}, gaeService, gaeServiceByBranch = {}, - serviceWithBranchName, - prodBranch, branchesWithTimestampVersions = [], } = backendCfg gaeProject = gaeProjectByBranch[gitBranch] || gaeProject - gaeService = validateGAEServiceName(gaeServiceByBranch[gitBranch] || gaeService) - - const prod = gitBranch === prodBranch - - if (!prod && serviceWithBranchName && !gaeServiceByBranch[gitBranch]) { + if (gaeServiceByBranch[gitBranch]) { + gaeService = validateGAEServiceName(gaeServiceByBranch[gitBranch]!) + } else { gaeService = validateGAEServiceName([gitBranch, gaeService].join('--')) } @@ -99,7 +90,6 @@ export async function createDeployInfo( serviceUrl, gitBranch, gitRev, - prod, ts: now.unix(), } @@ -116,12 +106,9 @@ export function createAndSaveAppYaml( appYamlPassEnv = '', ): AppYaml { const appYaml = createAppYaml(backendCfg, deployInfo, projectDir, appYamlPassEnv) - const appYamlPath = `${targetDir}/app.yaml` - - fs.writeFileSync(appYamlPath, yaml.dump(appYaml)) + fs2.writeYaml(appYamlPath, appYaml) console.log(`saved ${dimGrey(appYamlPath)}`) - return appYaml } @@ -144,15 +131,15 @@ export function createAppYaml( // Check existing app.yaml const appYamlPath = `${projectDir}/app.yaml` - if (fs.existsSync(appYamlPath)) { + if (fs2.pathExists(appYamlPath)) { console.log(`merging-in ${dimGrey(appYamlPath)}`) - _merge(appYaml, yaml.load(fs.readFileSync(appYamlPath, 'utf8'))) + _merge(appYaml, fs2.readYaml(appYamlPath)) } const appEnvYamlPath = `${projectDir}/app.${APP_ENV}.yaml` - if (fs.existsSync(appEnvYamlPath)) { + if (fs2.pathExists(appEnvYamlPath)) { console.log(`merging-in ${dimGrey(appEnvYamlPath)}`) - _merge(appYaml, yaml.load(fs.readFileSync(appEnvYamlPath, 'utf8'))) + _merge(appYaml, fs2.readYaml(appEnvYamlPath)) } // appYamlPassEnv diff --git a/src/deploy/deployGae.ts b/src/deploy/deployGae.ts index 174276f..6a31001 100644 --- a/src/deploy/deployGae.ts +++ b/src/deploy/deployGae.ts @@ -89,12 +89,12 @@ export async function undeployGae(branch: string): Promise { const projectDir = '.' const backendCfg = getBackendCfg(projectDir) - const { gaeProject, gaeService, gaeVersion, prod } = await createDeployInfo(backendCfg, branch) + const { gaeProject, gaeService, gaeVersion } = await createDeployInfo(backendCfg, branch) - if (prod) { - console.log(`undeployGae (branch: ${branch}): not removing prod version (safety check)`) - return - } + // if (prod) { + // console.log(`undeployGae (branch: ${branch}): not removing prod version (safety check)`) + // return + // } console.log( `undeployGae (branch: ${branch}): going to remove ${gaeProject}/${gaeService}/${gaeVersion}`, diff --git a/src/server/deployInfo.util.test.ts b/src/server/deployInfo.util.test.ts index 0ddef86..b46c0e0 100644 --- a/src/server/deployInfo.util.test.ts +++ b/src/server/deployInfo.util.test.ts @@ -5,7 +5,6 @@ test('getDeployInfo non-existing file', () => { const deployInfo = getDeployInfo('') expect(deployInfo).toMatchObject({ gaeProject: '', - prod: false, }) getDeployInfo('') // should not log again due to memoFn @@ -15,6 +14,5 @@ test('getDeployInfo existing file', () => { const deployInfo = getDeployInfo(`${srcDir}/test/deploy`) expect(deployInfo).toMatchObject({ gaeProject: 'test-project', - prod: false, }) }) diff --git a/src/server/deployInfo.util.ts b/src/server/deployInfo.util.ts index 2156554..5052916 100644 --- a/src/server/deployInfo.util.ts +++ b/src/server/deployInfo.util.ts @@ -1,11 +1,11 @@ -import fs from 'node:fs' import { _memoFn } from '@naturalcycles/js-lib' +import { fs2 } from '@naturalcycles/nodejs-lib' import type { DeployInfo } from '../deploy' export const getDeployInfo = _memoFn((projectDir: string): DeployInfo => { const deployInfoPath = `${projectDir}/deployInfo.json` try { - return JSON.parse(fs.readFileSync(deployInfoPath, 'utf8')) + return fs2.readJson(deployInfoPath) } catch { // console.error(`cannot read ${deployInfoPath}, returning empty version`) return getDeployInfoStub() @@ -21,7 +21,6 @@ function getDeployInfoStub(stub = ''): DeployInfo { versionUrl: stub, gitBranch: stub, gitRev: stub, - prod: false, ts: Math.floor(Date.now() / 1000), } } diff --git a/src/server/serverStatusMiddleware.ts b/src/server/serverStatusMiddleware.ts index 074f51b..b17bd7e 100644 --- a/src/server/serverStatusMiddleware.ts +++ b/src/server/serverStatusMiddleware.ts @@ -16,7 +16,7 @@ export function getServerStatusData( projectDir: string = process.cwd(), extra?: any, ): Record { - const { gitRev, gitBranch, prod, ts } = getDeployInfo(projectDir) + const { gitRev, gitBranch, ts } = getDeployInfo(projectDir) const t = localTime(ts) const deployBuildTime = t.toPretty() const buildInfo = [t.toStringCompact(), gitBranch, gitRev].filter(Boolean).join('_') @@ -25,7 +25,6 @@ export function getServerStatusData( started: getStartedStr(), deployBuildTime, APP_ENV, - prod, buildInfo, GAE_APPLICATION, GAE_SERVICE,