From 1d073af31ae2b2c0eda3850ecf672b86139bee88 Mon Sep 17 00:00:00 2001 From: Paulo Castro Date: Thu, 28 May 2020 18:03:40 +0100 Subject: [PATCH] v12 preparations: Add feature switch for '--nogitignore' Connects-to: #1770 Change-type: patch --- lib/actions/push.ts | 11 ++++++++--- lib/utils/compose.js | 8 ++++++-- lib/utils/helpers.ts | 7 ------- lib/utils/messages.ts | 22 +++++++++++++++++++++- lib/utils/patterns.ts | 4 ++-- lib/utils/version.ts | 32 ++++++++++++++++++++++++++++++++ 6 files changed, 69 insertions(+), 15 deletions(-) create mode 100644 lib/utils/version.ts diff --git a/lib/actions/push.ts b/lib/actions/push.ts index 6c0ef8cd..9be77c2f 100644 --- a/lib/actions/push.ts +++ b/lib/actions/push.ts @@ -26,6 +26,7 @@ import { validateDotLocalUrl, validateIPAddress, } from '../utils/validation'; +import { isV12 } from '../utils/version'; enum BuildTarget { Cloud, @@ -265,7 +266,9 @@ export const push: CommandDefinition< { signature: 'nogitignore', alias: 'G', - description: stripIndent` + description: isV12() + ? 'No-op and deprecated since balena CLI v12.0.0. See "balena help push".' + : stripIndent` Disregard all .gitignore files, and consider only the .dockerignore file (if any) at the source directory. This will be the default behavior in an upcoming major version release. For more information, see 'balena help push'. @@ -303,6 +306,8 @@ export const push: CommandDefinition< }, ); + const nogitignore = !!options.nogitignore || isV12(); + const buildTarget = getBuildTarget(appOrDevice); switch (buildTarget) { case BuildTarget.Cloud: @@ -349,7 +354,7 @@ export const push: CommandDefinition< source, auth: token, baseUrl, - nogitignore: !!options.nogitignore, + nogitignore, sdk, opts, }; @@ -373,7 +378,7 @@ export const push: CommandDefinition< dockerfilePath, registrySecrets, nocache: options.nocache || false, - nogitignore: options.nogitignore || false, + nogitignore, noParentCheck: options['noparent-check'] || false, nolive: options.nolive || false, detached: options.detached || false, diff --git a/lib/utils/compose.js b/lib/utils/compose.js index a496794a..64f499f7 100644 --- a/lib/utils/compose.js +++ b/lib/utils/compose.js @@ -34,6 +34,7 @@ export const appendProjectOptions = opts => export function appendOptions(opts) { const Logger = require('./logger'); + const { isV12 } = require('./version'); return appendProjectOptions(opts).concat([ { signature: 'emulated', @@ -54,7 +55,9 @@ export function appendOptions(opts) { }, { signature: 'nogitignore', - description: stripIndent` + description: isV12() + ? `No-op and deprecated since balena CLI v12.0.0. See "balena help ${Logger.command}".` + : stripIndent` Disregard all .gitignore files, and consider only the .dockerignore file (if any) at the source directory. This will be the default behavior in an upcoming major version release. For more information, see 'balena help ${Logger.command}'. @@ -91,12 +94,13 @@ Source files are not modified.`, */ export function generateOpts(options) { const fs = require('mz/fs'); + const { isV12 } = require('./version'); return fs.realpath(options.source || '.').then(projectPath => ({ projectName: options.projectName, projectPath, inlineLogs: !!options.logs, dockerfilePath: options.dockerfile, - nogitignore: !!options.nogitignore, + nogitignore: !!options.nogitignore || isV12(), noParentCheck: options['noparent-check'], })); } diff --git a/lib/utils/helpers.ts b/lib/utils/helpers.ts index cc10e94c..d459ebaa 100644 --- a/lib/utils/helpers.ts +++ b/lib/utils/helpers.ts @@ -25,9 +25,6 @@ import * as ShellEscape from 'shell-escape'; import { ExpectedError } from '../errors'; import { getBalenaSdk, getChalk, getVisuals } from './lazy'; -import * as semver from 'semver'; -import { version } from '../../package.json'; - export function getGroupDefaults(group: { options: Array<{ name: string; default?: string }>; }): { [name: string]: string | number | undefined } { @@ -468,7 +465,3 @@ export function getProxyConfig(): ProxyConfig | undefined { } } } - -export function isVersionGTE(v: string) { - return semver.gte(process.env.BALENA_CLI_VERSION_OVERRIDE || version, v); -} diff --git a/lib/utils/messages.ts b/lib/utils/messages.ts index 18298dc6..1b7c0b3e 100644 --- a/lib/utils/messages.ts +++ b/lib/utils/messages.ts @@ -15,6 +15,8 @@ * limitations under the License. */ +import { isV12 } from './version'; + const DEBUG_MODE = !!process.env.DEBUG; export const reachingOut = `\ @@ -67,7 +69,7 @@ If the --registry-secrets option is not specified, and a secrets.yml or secrets.json file exists in the balena directory (usually $HOME/.balena), this file will be used instead.`; -export const dockerignoreHelp = `\ +const dockerignoreHelpV11 = `\ DOCKERIGNORE AND GITIGNORE FILES By default, both '.dockerignore' and '.gitignore' files are taken into account in order to prevent files from being sent to the balenaCloud builder or Docker @@ -102,3 +104,21 @@ If necessary, the effect of the '**/.git' pattern may be modified by adding For documentation on pattern format, see: - https://docs.docker.com/engine/reference/builder/#dockerignore-file - https://www.npmjs.com/package/@balena/dockerignore`; + +const dockerignoreHelpV12 = + `DOCKERIGNORE AND GITIGNORE FILES +The balena CLI will use a '.dockerignore' file (if any) at the source directory +in order to decide which source files to exclude from the "build context" sent +to balenaCloud, Docker or balenaEngine. Previous balena CLI releases (before +v12.0.0) also took '.gitignore' files into account, but this is no longer the +case. This allows files to be used for an image build even if they are listed +in '.gitignore'. + +A few "hardcoded" dockerignore patterns are also used and "merged" (in memory) +with the patterns found in the '.dockerignore' file (if any), in the following +order: +` + dockerignoreHelpV11.substring(dockerignoreHelpV11.indexOf('\n **/.git')); + +export const dockerignoreHelp = isV12() + ? dockerignoreHelpV12 + : dockerignoreHelpV11; diff --git a/lib/utils/patterns.ts b/lib/utils/patterns.ts index e76e68d6..868ab982 100644 --- a/lib/utils/patterns.ts +++ b/lib/utils/patterns.ts @@ -21,9 +21,9 @@ import _ = require('lodash'); import _form = require('resin-cli-form'); import { exitWithExpectedError, instanceOf, NotLoggedInError } from '../errors'; -import { isVersionGTE } from './helpers'; import { getBalenaSdk, getVisuals } from './lazy'; import validation = require('./validation'); +import { isV12 } from './version'; const getForm = _.once((): typeof _form => require('resin-cli-form')); @@ -81,7 +81,7 @@ export function authenticate(options: {}): Bluebird { export async function checkLoggedIn(): Promise { const balena = getBalenaSdk(); if (!(await balena.auth.isLoggedIn())) { - if (isVersionGTE('12.0.0')) { + if (isV12()) { throw new NotLoggedInError(stripIndent` Login required: use the “balena login” command to log in. `); diff --git a/lib/utils/version.ts b/lib/utils/version.ts new file mode 100644 index 00000000..1ca510db --- /dev/null +++ b/lib/utils/version.ts @@ -0,0 +1,32 @@ +/** + * @license + * Copyright 2018-2020 Balena Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import * as semver from 'semver'; +import { version } from '../../package.json'; + +export function isVersionGTE(v: string): boolean { + return semver.gte(process.env.BALENA_CLI_VERSION_OVERRIDE || version, v); +} + +let v12: boolean; + +export function isV12(): boolean { + if (v12 === undefined) { + v12 = isVersionGTE('12.0.0'); + } + return v12; +}