Skip to content

Commit

Permalink
added bypass-download flag (#651)
Browse files Browse the repository at this point in the history
* bump

* for cr

* after cr

* for approval

* without resolveDemoStepImage function

* without resolveDemoStepImage function

* fixed parameter

* bump

* added bypass-download flag

* added bypass-download flag

* changed the description

* removed redundant comment

* fixing CR-4318

* fixed

* correction in cluster acceptance tests

* for review

* removed redundant line

* binLocation corrections

* after review

Co-authored-by: roi.kramer <[email protected]>
  • Loading branch information
elad-codefresh and roi-codefresh authored Apr 25, 2021
1 parent 9cffb3d commit 7077622
Show file tree
Hide file tree
Showing 12 changed files with 111 additions and 70 deletions.
1 change: 0 additions & 1 deletion lib/binary/downloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ class Downloader {
}
logger.debug(`${component.name} component upgrade is required, downloading.`);


const binary = `${name}_${remoteVersion}_${osType}`;
const version = component.version.prefix ? `${component.version.prefix}${remoteVersion}` : remoteVersion;
const url = _buildDownloadURL({ name, version, binary });
Expand Down
3 changes: 2 additions & 1 deletion lib/interface/cli/commands/cluster/create.cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const command = new Command({
serviceaccount,
'kube-context': contextName,
'behind-firewall': behindFirewall,
'bypass-download': bypassDownload,
name,
} = argv;
let {
Expand All @@ -53,7 +54,7 @@ const command = new Command({
if (terminateProcess === undefined) {
terminateProcess = true;
}
const binLocation = await downloadSteveDore();
const binLocation = await downloadSteveDore(undefined, bypassDownload);
const componentRunner = new Runner(binLocation);
const commands = [
'create',
Expand Down
9 changes: 7 additions & 2 deletions lib/interface/cli/commands/components/update.cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@ const command = new Command({
.env('CF_ARG_') // this means that every process.env.CF_ARG_* will be passed to argv
.option('location', {
describe: 'Override download folder location',
})
.option('bypass-download', {
describe: 'Will bypass the attempt to download the installer. Instead, will immediately attempt to use the binary from the components folder',
default: false,
type: 'boolean',
}),
handler: async (argv) => {
console.log('Updating components');
const { location } = argv;
await helper.downloadRelatedComponents(location);
const { location, bypassDownload } = argv;
await helper.downloadRelatedComponents(location, bypassDownload);
},
});

Expand Down
4 changes: 2 additions & 2 deletions lib/interface/cli/commands/gitops/common/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ class GitopsInstaller {
// eslint-disable-next-line class-methods-use-this
async install(argv) {
let { httpProxy, httpsProxy } = argv;
const { kubeConfigPath, provider, argoHost, argoUsername, argoPassword } = argv;
const { kubeConfigPath, provider, argoHost, argoUsername, argoPassword, bypassDownload } = argv;

const binLocation = await downloadProvider({ provider });
const binLocation = await downloadProvider({ provider }, bypassDownload);
const componentRunner = new Runner(binLocation);

const commands = [
Expand Down
4 changes: 2 additions & 2 deletions lib/interface/cli/commands/gitops/common/uninstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ const _ = require('lodash');
class GitopsUninstaller {
// eslint-disable-next-line class-methods-use-this
async uninstall(provider, argv) {
const { 'kube-config-path': kubeConfigPath } = argv;
const binLocation = await downloadProvider({ provider });
const { 'kube-config-path': kubeConfigPath, 'bypass-download': bypassDownload } = argv;
const binLocation = await downloadProvider({ provider }, bypassDownload);
const componentRunner = new Runner(binLocation);

const commands = [
Expand Down
3 changes: 2 additions & 1 deletion lib/interface/cli/commands/gitops/common/upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ class GitopsUpgrader {
'kube-namespace': kubeNamespace,
'kube-context-name': kubeContextName,
'in-cluster': inCluster,
'bypass-download': bypassDownload,
} = argv;

const binLocation = await downloadProvider({ provider });
const binLocation = await downloadProvider({ provider }, bypassDownload);
const componentRunner = new Runner(binLocation);

const commands = [
Expand Down
2 changes: 2 additions & 0 deletions lib/interface/cli/commands/hybrid/InstallationPlan.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class InstallationPlan {
exitOnError = true,
condition = true,
executeOnDryRun = false,
bypassDownload,
}) {
if (!this.completedSteps[name]) {
this.state.pendingSteps.push({
Expand All @@ -78,6 +79,7 @@ class InstallationPlan {
exitOnError,
condition,
executeOnDryRun,
bypassDownload,
status: STEP_STATUSES.PENDING,
});
}
Expand Down
118 changes: 64 additions & 54 deletions lib/interface/cli/commands/hybrid/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,18 @@ async function getRecommendedKubeNamespace(kubeconfigPath, kubeContextName) {
return name;
}

async function downloadVeonona(location = CODEFRESH_PATH) {
async function bypassDownloadSuccess(shouldBypass, localDir, localBin) {
if (shouldBypass) {
const newLocation = path.join(process.cwd(), INSTALLATION_DEFAULTS.COMPONENTS_FOLDER, localDir, localBin);
if (await pathExists(newLocation)) {
return true;
}
}
return false;
}

async function attemptDownload(location, component) {
console.log('Downloading installer');
const downloader = new Downloader({
progress: new cliProgress.SingleBar(
{
Expand All @@ -360,76 +371,66 @@ async function downloadVeonona(location = CODEFRESH_PATH) {
),
location,
});
const [error] = await to(downloader.download(components.venona));

return await to(downloader.download(component));
}

async function downloadVeonona(location = CODEFRESH_PATH, bypassDownload = false) {
if (await bypassDownloadSuccess(bypassDownload, components.venona.local.dir, components.venona.local.binary)) {
return path.resolve(process.cwd(), INSTALLATION_DEFAULTS.COMPONENTS_FOLDER);
}

const [error] = await attemptDownload(location, components.venona);
if (error) {
const newLocation = path.join(process.cwd(), INSTALLATION_DEFAULTS.COMPONENTS_FOLDER, components.venona.local.dir, components.venona.local.binary);
if (await pathExists(newLocation)) {
console.log('Failed to download installer, using binary from components folder');
if (await bypassDownloadSuccess(!bypassDownload, components.venona.local.dir, components.venona.local.binary)) {
return path.resolve(process.cwd(), INSTALLATION_DEFAULTS.COMPONENTS_FOLDER);
}
console.log('Failed to download component, aborting');

console.log('Failed to find component, aborting');
throw error;
}

return location;
}

async function downloadProvider({ provider, location = CODEFRESH_PATH }) {
const downloader = new Downloader({
progress: new cliProgress.SingleBar(
{
stopOnComplete: true,
format: CommonProgressFormat,
},
cliProgress.Presets.shades_classic,
),
location,
});
const [error] = await to(downloader.download(components.gitops[provider]));
async function downloadProvider({ provider, location = CODEFRESH_PATH }, bypassDownload = false) {
if (await bypassDownloadSuccess(bypassDownload, localSettings.dir, localSettings.binary)) {
return path.resolve(process.cwd(), INSTALLATION_DEFAULTS.COMPONENTS_FOLDER);
}

const [error] = await attemptDownload(location, components.gitops[provider]);
if (error) {
const localSettings = components.gitops[provider].local;
const newLocation = path.join(process.cwd(), INSTALLATION_DEFAULTS.COMPONENTS_FOLDER, localSettings.dir, localSettings.binary);
if (await pathExists(newLocation)) {
console.log('Failed to download installer, using binary from components folder');
if (await bypassDownloadSuccess(!bypassDownload, localSettings.dir, localSettings.binary)) {
return path.resolve(process.cwd(), INSTALLATION_DEFAULTS.COMPONENTS_FOLDER);
}
console.log('Failed to download component, aborting');

console.log('Failed to find component, aborting');
throw error;
}
return location;
}

async function downloadSteveDore(location = CODEFRESH_PATH) {
const downloader = new Downloader({
progress: new cliProgress.SingleBar(
{
stopOnComplete: true,
format: CommonProgressFormat,
},
cliProgress.Presets.shades_classic,
),
location,
});
const [error] = await to(downloader.download(components.stevedore));
async function downloadSteveDore(location = CODEFRESH_PATH, bypassDownload = false) {
if (await bypassDownloadSuccess(bypassDownload, components.stevedore.local.dir, components.stevedore.local.binary)) {
return path.resolve(process.cwd(), INSTALLATION_DEFAULTS.COMPONENTS_FOLDER);
}

const [error] = await attemptDownload(location, components.stevedore);
if (error) {
const newLocation = path.join(
process.cwd(),
INSTALLATION_DEFAULTS.COMPONENTS_FOLDER,
components.stevedore.local.dir, components.stevedore.local.binary,
);
if (await pathExists(newLocation)) {
console.log('Failed to download installer, using binary from components folder');
if (await bypassDownloadSuccess(!bypassDownload, components.stevedore.local.dir, components.stevedore.local.binary)) {
return path.resolve(process.cwd(), INSTALLATION_DEFAULTS.COMPONENTS_FOLDER);
}
console.log('Failed to download component, aborting');

console.log('Failed to find component, aborting');
throw error;
}
return location;
}

async function downloadHybridComponents(location) {
await downloadVeonona(location);
async function downloadHybridComponents(location, bypassDownload = false) {
await downloadVeonona(location, bypassDownload);
console.log(`Kubernetes components installer downloaded successfully to ${location} `);
await downloadSteveDore(location);
await downloadSteveDore(location, bypassDownload);
console.log(`Kubernetes registrator installer downloaded successfully ${location}`);
}

Expand All @@ -444,8 +445,9 @@ async function runClusterAcceptanceTests({
valuesFile, // --values
setValue, // --set-value
setFile, // --set-file
bypassDownload, // --bypass-download
}) {
const binLocation = await downloadVeonona();
const binLocation = await downloadVeonona(undefined, bypassDownload);
const componentRunner = new Runner(binLocation);
const cmd = ['test', '--log-formtter', DefaultLogFormatter];
if (apiHost) {
Expand Down Expand Up @@ -491,7 +493,7 @@ async function runClusterAcceptanceTests({
}

async function runUpgrade({ kubeNamespace, kubeContextName }) {
const binLocation = await downloadVeonona();
const binLocation = await downloadVeonona(undefined, bypassDownload);
const componentRunner = new Runner(binLocation);
const cmd = ['upgrade', '--log-formtter', DefaultLogFormatter];
if (kubeNamespace) {
Expand All @@ -514,6 +516,7 @@ async function installAgent({
token, // --agentToken
kubeNodeSelector, // --kube-node-selector
dryRun, // --dryRun
bypassDownload, // --bypass-download
inCluster, // -inCluster
tolerations, // --tolerations
venonaVersion, // --venona-version
Expand All @@ -526,7 +529,7 @@ async function installAgent({
setValue, // --set-value
setFile, // --set-file
}) {
const binLocation = await downloadVeonona();
const binLocation = await downloadVeonona(undefined, bypassDownload);
const componentRunner = new Runner(binLocation);
const cmd = [
'install',
Expand Down Expand Up @@ -557,6 +560,11 @@ async function installAgent({
if (dryRun) {
cmd.push('--dry-run');
}

if (bypassDownload) {
cmd.push(`--bypass-download=${bypassDownload}`);
}

if (inCluster) {
cmd.push('--in-cluster');
}
Expand Down Expand Up @@ -600,6 +608,7 @@ async function installRuntime({
kubeNamespace, // --kube-namespace
dockerRegistry, // --docker-registry
dryRun, // --dryRun
bypassDownload, // --bypass-download
inCluster, // -inCluster
kubeConfigPath, // --kube-config-path
verbose, // --verbose
Expand All @@ -612,7 +621,7 @@ async function installRuntime({
storageClassName, // --storage-class
logFormatting = DefaultLogFormatter, // --log-formtter
}) {
const binLocation = await downloadVeonona();
const binLocation = await downloadVeonona(undefined, bypassDownload);
const componentRunner = new Runner(binLocation);
const cmd = [
'install',
Expand Down Expand Up @@ -693,7 +702,7 @@ async function installAppProxy({
envVars, // --envVars
dryRun, // --dry-run
}) {
const binLocation = await downloadVeonona();
const binLocation = await downloadVeonona(undefined, bypassDownload);
const componentRunner = new Runner(binLocation);
const cmd = [
'install',
Expand Down Expand Up @@ -764,7 +773,7 @@ async function unInstallAppProxy({
valuesFile, // --values
setValue, // --set-value
}) {
const binLocation = await downloadVeonona();
const binLocation = await downloadVeonona(undefined, bypassDownload);
const componentRunner = new Runner(binLocation);
const cmd = [
'uninstall',
Expand Down Expand Up @@ -805,7 +814,7 @@ async function upgradeAppProxy({
valuesFile, // --values
setValue, // --set-value
}) {
const binLocation = await downloadVeonona();
const binLocation = await downloadVeonona(undefined, bypassDownload);
const componentRunner = new Runner(binLocation);
const cmd = [
'upgrade',
Expand Down Expand Up @@ -853,8 +862,9 @@ async function attachRuntime({
setValue, // --set-value
setFile, // --set-file
dryRun,
bypassDownload,
}) {
const binLocation = await downloadVeonona();
const binLocation = await downloadVeonona(undefined, bypassDownload);
const componentRunner = new Runner(binLocation);
const cmd = [
'attach',
Expand Down
11 changes: 11 additions & 0 deletions lib/interface/cli/commands/hybrid/init.cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,11 @@ const initCmd = new Command({
describe: 'Will save all of the manifests to be deployed on the cluster to: ./manifests/',
default: false,
type: 'boolean',
})
.option('bypass-download', {
describe: 'Will bypass the attempt to download the installer. Instead, will immediately attempt to use the binary from the components folder',
default: false,
type: 'boolean',
})
.example('codefresh runner init --values values.yaml (see values file example here: '
+ 'https://github.com/codefresh-io/venona/blob/release-1.0/venonactl/example/values-example.yaml)'),
Expand Down Expand Up @@ -267,6 +272,7 @@ const initCmd = new Command({
userVolumeMounts,
userVolumes,
'dry-run': dryRun,
'bypass-download': bypassDownload
} = _argv;
let {
'kube-context-name': kubeContextName,
Expand Down Expand Up @@ -474,6 +480,7 @@ const initCmd = new Command({
valuesFile,
setValue,
setFile,
bypassDownload,
},
installationEvent: installationProgress.events.ACCEPTANCE_TESTS_RAN,
condition: !skipClusterTest,
Expand Down Expand Up @@ -526,6 +533,7 @@ const initCmd = new Command({
setValue, // --set-value
setFile, // --set-file
dryRun,
bypassDownload,
});
},
installationEvent: installationProgress.events.AGENT_INSTALLED,
Expand Down Expand Up @@ -696,6 +704,7 @@ const initCmd = new Command({
setFile,
storageClassName,
dryRun,
bypassDownload,
});
},
installationEvent: installationProgress.events.RUNTIME_INSTALLED,
Expand Down Expand Up @@ -785,6 +794,7 @@ const initCmd = new Command({
verbose, // --verbose
runtimeName: installationPlan.getContext('runtimeName'), // --runtimeName
dryRun,
bypassDownload,
valuesFile,
setValue,
setFile,
Expand All @@ -808,6 +818,7 @@ const initCmd = new Command({
'set-value': setValue,
'set-file': setFile,
'dry-run': dryRun,
'bypass-download': bypassDownload,
token: _.get(sdk, 'config.context.token'),
verbose,
noExit: true, // to prevent if from calling inner: process.exit()
Expand Down
Loading

0 comments on commit 7077622

Please sign in to comment.