diff --git a/binzx/otomi b/binzx/otomi index f05c2354b8..bd4157c42e 100755 --- a/binzx/otomi +++ b/binzx/otomi @@ -181,18 +181,20 @@ vars=( OTOMI_SERVER OTOMI_TAG OTOMI_USERNAME + OTOMI_NON_INTERACTIVE PROFILE STATIC_COLORS SHELL TESTING TRACE + VERBOSITY VAULT_TOKEN ) dump_vars "${vars[@]}" cat >>$tmp_env <>$tmp_env + echo "OTOMI_DEV=1" >>$tmp_env fi check_volume_path() { @@ -264,7 +266,7 @@ if [[ $calling_args == 'server'* ]]; then fi mkdir -p /tmp/otomi -if [ -n "$OTOMI_IN_DOCKER" ]; then +if [ -n "$IN_DOCKER" ]; then $cmd status=$? elif [[ $calling_args == *'--get-yargs-completions'* ]]; then diff --git a/src/common/envalid.ts b/src/common/envalid.ts index ba6f879c9a..a7591d909c 100644 --- a/src/common/envalid.ts +++ b/src/common/envalid.ts @@ -12,7 +12,7 @@ const cleanSpec = { GCLOUD_SERVICE_KEY: json({ default: undefined }), KUBE_VERSION_OVERRIDE: str({ default: undefined }), OTOMI_DEV: bool({ default: false }), - OTOMI_IN_DOCKER: bool({ default: false }), + IN_DOCKER: bool({ default: false }), OTOMI_IN_TERMINAL: bool({ default: true }), STATIC_COLORS: bool({ default: false }), TESTING: bool({ default: false }), diff --git a/src/common/gitea-push.ts b/src/common/gitea-push.ts index fd38ba56fa..dc644e3f76 100644 --- a/src/common/gitea-push.ts +++ b/src/common/gitea-push.ts @@ -3,7 +3,7 @@ import { $, cd, nothrow } from 'zx' import { terminal } from './debug' import { env } from './envalid' import { hfValues } from './hf' -import { waitTillAvailable } from './utils' +import { currDir, waitTillAvailable } from './utils' export const giteaPush = async (): Promise => { const debug = terminal('Gitea Push') @@ -15,22 +15,23 @@ export const giteaPush = async (): Promise => { } const stage = hfVals.charts?.['cert-manager']?.stage === 'staging' ? ' -c http.sslVerify=false' : ' ' debug.log(hfVals.cluster) - const clusterDomain = hfVals.cluster?.domainSuffix ?? debug.error('cluster.domainSuffix is not set') - process.exit(1) + const clusterDomain = hfVals.cluster?.domainSuffix + if (!clusterDomain) { + debug.error('cluster.domainSuffix is not set') + process.exit(1) + } const giteaUrl = `gitea.${clusterDomain}` await waitTillAvailable(giteaUrl) - const giteaPassword = - hfVals.charts?.gitea?.adminPassword ?? hfVals.otomi?.adminPassword ?? debug.error('otomi.adminPassword is not set') - process.exit(1) + const giteaPassword = hfVals.charts?.gitea?.adminPassword ?? hfVals.otomi?.adminPassword const giteaUser = 'otomi-admin' const giteaOrg = 'otomi' const giteaRepo = 'values' - const currDir = process.cwd() + const currDirVal = await currDir() - cd(`${env.ENV_DIR}`) + cd(env.ENV_DIR) try { if (!existsSync('.git')) { await $`git init` @@ -61,7 +62,7 @@ export const giteaPush = async (): Promise => { } catch (error) { debug.error(error) } finally { - cd(currDir) + cd(currDirVal) } } diff --git a/src/common/utils.ts b/src/common/utils.ts index 2be516a95e..a663c2a65f 100644 --- a/src/common/utils.ts +++ b/src/common/utils.ts @@ -17,7 +17,6 @@ export const parser = yargs(process.argv.slice(3)) export const getFilename = (path: string): string => fileURLToPath(path).split('/').pop()?.split('.')[0] as string export interface BasicArguments extends YargsArguments { - inDocker: boolean logLevel: string nonInteractive: boolean skipCleanup: boolean @@ -28,7 +27,6 @@ export interface BasicArguments extends YargsArguments { export const defaultBasicArguments: BasicArguments = { _: [], $0: 'defaultBasicArgs', - inDocker: true, logLevel: 'WARN', nonInteractive: true, skipCleanup: false, @@ -68,8 +66,11 @@ export const capitalize = (s: string): string => .join(' ')) || '' -export const loadYaml = (path: string): any => { - if (!existsSync(path)) throw new Error(`${path} does not exists`) +export const loadYaml = (path: string, opts?: { noError: boolean }): any => { + if (!existsSync(path)) { + if (opts?.noError) return null + throw new Error(`${path} does not exists`) + } return load(readFileSync(path, 'utf-8')) as any } diff --git a/src/common/yargs-opts.ts b/src/common/yargs-opts.ts index 3a4067ce33..5b103ce527 100644 --- a/src/common/yargs-opts.ts +++ b/src/common/yargs-opts.ts @@ -113,14 +113,13 @@ export const basicOptions: { [key: string]: Options } = { verbose: { alias: 'v', count: true, - coerce: (val: number) => - Math.min( - val, - Object.keys(logLevels) - .filter((logLevelVal) => !Number.isNaN(Number(logLevelVal))) - .map(Number) - .reduce((prev, curr) => Math.max(prev, curr)), - ), + coerce: (val: number) => { + const ll = Object.keys(logLevels) + .filter((logLevelVal) => !Number.isNaN(Number(logLevelVal))) + .map(Number) + .reduce((prev, curr) => Math.max(prev, curr)) + return Math.min(Math.max(val, Number(process.env.VERBOSITY || '0')), ll) + }, }, 'non-interactive': { alias: 'ni', @@ -137,11 +136,6 @@ export const basicOptions: { [key: string]: Options } = { default: false, hidden: true, }, - inDocker: { - boolean: true, - default: false, - hidden: true, - }, } export const helmOptions = (parser: Argv): Argv => parser.options(helmOpts) diff --git a/src/otomi.ts b/src/otomi.ts index e74ad7404d..bfce3a12a7 100755 --- a/src/otomi.ts +++ b/src/otomi.ts @@ -18,7 +18,7 @@ import { basicOptions } from './common/yargs-opts' const debug = terminal('global') const terminalScale = 0.75 const isAutoCompletion = process.argv.includes('--get-yargs-completions') -if (!env.OTOMI_IN_DOCKER && !isAutoCompletion) { +if (!env.IN_DOCKER && !isAutoCompletion) { debug.error(process.argv) debug.error('Please run this script using the `otomi` entry script') process.exit(1)