2020-01-15 19:41:47 +00:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright 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.
|
|
|
|
*/
|
|
|
|
|
2020-02-15 20:07:09 +00:00
|
|
|
import { expect } from 'chai';
|
2020-06-23 10:57:57 +00:00
|
|
|
import { promises as fs } from 'fs';
|
2020-01-15 19:41:47 +00:00
|
|
|
import * as path from 'path';
|
|
|
|
|
|
|
|
import { BalenaAPIMock } from '../balena-api-mock';
|
2020-01-24 01:21:51 +00:00
|
|
|
import { BuilderMock, builderResponsePath } from '../builder-mock';
|
2020-05-01 11:18:11 +00:00
|
|
|
import { expectStreamNoCRLF, testPushBuildStream } from '../docker-build';
|
|
|
|
import { cleanOutput, runCommand } from '../helpers';
|
2020-01-15 19:41:47 +00:00
|
|
|
import {
|
2020-05-01 11:18:11 +00:00
|
|
|
addRegSecretsEntries,
|
2020-02-15 20:18:00 +00:00
|
|
|
ExpectedTarStreamFiles,
|
2021-07-15 13:41:38 +00:00
|
|
|
getDockerignoreWarn1,
|
|
|
|
getDockerignoreWarn2,
|
2020-05-01 11:18:11 +00:00
|
|
|
setupDockerignoreTestData,
|
|
|
|
} from '../projects';
|
2020-01-15 19:41:47 +00:00
|
|
|
|
|
|
|
const repoPath = path.normalize(path.join(__dirname, '..', '..'));
|
|
|
|
const projectsPath = path.join(repoPath, 'tests', 'test-data', 'projects');
|
2020-01-24 01:21:51 +00:00
|
|
|
|
2020-02-15 20:18:00 +00:00
|
|
|
const commonResponseLines = {
|
2020-01-24 01:21:51 +00:00
|
|
|
'build-POST-v3.json': [
|
|
|
|
'[Info] Starting build for testApp, user gh_user',
|
|
|
|
'[Info] Dashboard link: https://dashboard.balena-cloud.com/apps/1301645/devices',
|
|
|
|
'[Info] Building on arm01',
|
|
|
|
'[Info] Pulling previous images for caching purposes...',
|
|
|
|
'[Success] Successfully pulled cache images',
|
|
|
|
'[main] Step 1/4 : FROM busybox',
|
|
|
|
'[main] ---> 76aea0766768',
|
|
|
|
'[main] Step 2/4 : COPY ./src/start.sh /start.sh',
|
|
|
|
'[main] ---> b563ad6a0801',
|
|
|
|
'[main] Step 3/4 : RUN chmod a+x /start.sh',
|
|
|
|
'[main] ---> Running in 10d4ddc40bfc',
|
|
|
|
'[main] Removing intermediate container 10d4ddc40bfc',
|
|
|
|
'[main] ---> 82e98871a32c',
|
|
|
|
'[main] Step 4/4 : CMD ["/start.sh"]',
|
|
|
|
'[main] ---> Running in 0682894e13eb',
|
|
|
|
'[main] Removing intermediate container 0682894e13eb',
|
|
|
|
'[main] ---> 889ccb6afc7c',
|
|
|
|
'[main] Successfully built 889ccb6afc7c',
|
|
|
|
'[Info] Uploading images',
|
|
|
|
'[Success] Successfully uploaded images',
|
|
|
|
'[Info] Built on arm01',
|
|
|
|
'[Success] Release successfully created!',
|
|
|
|
'[Info] Release: 05a24b5b034c9f95f25d4d74f0593bea (id: 1220245)',
|
|
|
|
'[Info] ┌─────────┬────────────┬────────────┐',
|
|
|
|
'[Info] │ Service │ Image Size │ Build Time │',
|
|
|
|
'[Info] ├─────────┼────────────┼────────────┤',
|
|
|
|
'[Info] │ main │ 1.32 MB │ 11 seconds │',
|
|
|
|
'[Info] └─────────┴────────────┴────────────┘',
|
|
|
|
],
|
|
|
|
};
|
|
|
|
|
2020-02-15 20:18:00 +00:00
|
|
|
const commonQueryParams = [
|
2021-02-04 06:41:49 +00:00
|
|
|
['slug', 'gh_user/testApp'],
|
2020-02-15 20:18:00 +00:00
|
|
|
['dockerfilePath', ''],
|
|
|
|
['emulated', 'false'],
|
|
|
|
['nocache', 'false'],
|
|
|
|
['headless', 'false'],
|
|
|
|
];
|
2020-01-15 19:41:47 +00:00
|
|
|
|
2020-06-24 23:01:53 +00:00
|
|
|
const hr =
|
|
|
|
'----------------------------------------------------------------------';
|
|
|
|
|
2020-06-15 22:53:07 +00:00
|
|
|
describe('balena push', function () {
|
2020-01-15 19:41:47 +00:00
|
|
|
let api: BalenaAPIMock;
|
|
|
|
let builder: BuilderMock;
|
2020-02-15 20:18:00 +00:00
|
|
|
const isWindows = process.platform === 'win32';
|
2020-01-24 01:21:51 +00:00
|
|
|
|
2020-01-15 19:41:47 +00:00
|
|
|
this.beforeEach(() => {
|
|
|
|
api = new BalenaAPIMock();
|
|
|
|
builder = new BuilderMock();
|
|
|
|
api.expectGetWhoAmI({ optional: true, persist: true });
|
|
|
|
api.expectGetMixpanel({ optional: true });
|
2020-12-18 15:56:47 +00:00
|
|
|
api.expectGetApplication();
|
2020-01-15 19:41:47 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
this.afterEach(() => {
|
|
|
|
// Check all expected api calls have been made and clean up.
|
|
|
|
api.done();
|
|
|
|
builder.done();
|
|
|
|
});
|
|
|
|
|
2020-05-01 11:18:11 +00:00
|
|
|
this.beforeAll(async () => {
|
|
|
|
await setupDockerignoreTestData();
|
|
|
|
});
|
|
|
|
|
|
|
|
this.afterAll(async () => {
|
|
|
|
await setupDockerignoreTestData({ cleanup: true });
|
|
|
|
});
|
|
|
|
|
2020-01-24 01:21:51 +00:00
|
|
|
it('should create the expected tar stream (single container)', async () => {
|
2020-01-15 19:41:47 +00:00
|
|
|
const projectPath = path.join(projectsPath, 'no-docker-compose', 'basic');
|
2020-02-15 20:18:00 +00:00
|
|
|
const expectedFiles: ExpectedTarStreamFiles = {
|
2020-06-20 22:05:59 +00:00
|
|
|
'src/.dockerignore': { fileSize: 16, type: 'file' },
|
2020-01-15 19:41:47 +00:00
|
|
|
'src/start.sh': { fileSize: 89, type: 'file' },
|
2020-06-03 13:41:12 +00:00
|
|
|
'src/windows-crlf.sh': {
|
2020-06-20 22:05:59 +00:00
|
|
|
fileSize: isWindows ? 68 : 70,
|
|
|
|
testStream: isWindows ? expectStreamNoCRLF : undefined,
|
2020-06-03 13:41:12 +00:00
|
|
|
type: 'file',
|
|
|
|
},
|
2020-02-01 00:29:51 +00:00
|
|
|
Dockerfile: { fileSize: 88, type: 'file' },
|
2020-01-24 01:21:51 +00:00
|
|
|
'Dockerfile-alt': { fileSize: 30, type: 'file' },
|
2020-01-15 19:41:47 +00:00
|
|
|
};
|
2020-05-01 11:18:11 +00:00
|
|
|
const regSecretsPath = await addRegSecretsEntries(expectedFiles);
|
2020-01-24 01:21:51 +00:00
|
|
|
const responseFilename = 'build-POST-v3.json';
|
2020-01-15 19:41:47 +00:00
|
|
|
const responseBody = await fs.readFile(
|
2020-01-24 01:21:51 +00:00
|
|
|
path.join(builderResponsePath, responseFilename),
|
2020-01-15 19:41:47 +00:00
|
|
|
'utf8',
|
|
|
|
);
|
2020-06-20 22:05:59 +00:00
|
|
|
const expectedResponseLines = [
|
|
|
|
...commonResponseLines[responseFilename],
|
2021-07-15 13:41:38 +00:00
|
|
|
...getDockerignoreWarn1(
|
|
|
|
[path.join(projectPath, 'src', '.dockerignore')],
|
|
|
|
'push',
|
|
|
|
),
|
2020-06-20 22:05:59 +00:00
|
|
|
];
|
2020-02-15 20:18:00 +00:00
|
|
|
if (isWindows) {
|
2020-06-03 13:41:12 +00:00
|
|
|
const fname = path.join(projectPath, 'src', 'windows-crlf.sh');
|
2020-06-20 22:05:59 +00:00
|
|
|
expectedResponseLines.push(
|
|
|
|
`[Info] Converting line endings CRLF -> LF for file: ${fname}`,
|
|
|
|
);
|
2020-02-05 22:26:55 +00:00
|
|
|
}
|
|
|
|
|
2020-02-15 20:18:00 +00:00
|
|
|
await testPushBuildStream({
|
|
|
|
builderMock: builder,
|
2020-12-18 15:56:47 +00:00
|
|
|
commandLine: `push testApp --source ${projectPath} -R ${regSecretsPath}`,
|
2020-02-15 20:18:00 +00:00
|
|
|
expectedFiles,
|
|
|
|
expectedQueryParams: commonQueryParams,
|
|
|
|
expectedResponseLines,
|
|
|
|
projectPath,
|
|
|
|
responseBody,
|
|
|
|
responseCode: 200,
|
|
|
|
});
|
2020-01-24 01:21:51 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should create the expected tar stream (alternative Dockerfile)', async () => {
|
|
|
|
const projectPath = path.join(projectsPath, 'no-docker-compose', 'basic');
|
2020-02-15 20:18:00 +00:00
|
|
|
const expectedFiles: ExpectedTarStreamFiles = {
|
2020-06-20 22:05:59 +00:00
|
|
|
'src/.dockerignore': { fileSize: 16, type: 'file' },
|
2020-01-24 01:21:51 +00:00
|
|
|
'src/start.sh': { fileSize: 89, type: 'file' },
|
2020-02-01 00:29:51 +00:00
|
|
|
'src/windows-crlf.sh': { fileSize: 70, type: 'file' },
|
|
|
|
Dockerfile: { fileSize: 88, type: 'file' },
|
2020-01-24 01:21:51 +00:00
|
|
|
'Dockerfile-alt': { fileSize: 30, type: 'file' },
|
|
|
|
};
|
2020-05-01 11:18:11 +00:00
|
|
|
const regSecretsPath = await addRegSecretsEntries(expectedFiles);
|
2020-01-24 01:21:51 +00:00
|
|
|
const responseFilename = 'build-POST-v3.json';
|
|
|
|
const responseBody = await fs.readFile(
|
|
|
|
path.join(builderResponsePath, responseFilename),
|
|
|
|
'utf8',
|
|
|
|
);
|
2020-06-20 22:05:59 +00:00
|
|
|
const expectedResponseLines = [
|
|
|
|
...commonResponseLines[responseFilename],
|
2021-07-15 13:41:38 +00:00
|
|
|
...getDockerignoreWarn1(
|
|
|
|
[path.join(projectPath, 'src', '.dockerignore')],
|
|
|
|
'push',
|
|
|
|
),
|
2020-06-20 22:05:59 +00:00
|
|
|
];
|
2020-06-15 22:53:07 +00:00
|
|
|
const expectedQueryParams = commonQueryParams.map((i) =>
|
2020-02-15 20:18:00 +00:00
|
|
|
i[0] === 'dockerfilePath' ? ['dockerfilePath', 'Dockerfile-alt'] : i,
|
|
|
|
);
|
2020-01-24 01:21:51 +00:00
|
|
|
|
2020-02-15 20:18:00 +00:00
|
|
|
await testPushBuildStream({
|
|
|
|
builderMock: builder,
|
2020-06-16 23:38:03 +00:00
|
|
|
commandLine: `push testApp -s ${projectPath} -R ${regSecretsPath} --dockerfile Dockerfile-alt --noconvert-eol`,
|
2020-02-15 20:18:00 +00:00
|
|
|
expectedFiles,
|
|
|
|
expectedQueryParams,
|
2020-06-20 22:05:59 +00:00
|
|
|
expectedResponseLines,
|
2020-02-15 20:18:00 +00:00
|
|
|
projectPath,
|
2020-01-24 01:21:51 +00:00
|
|
|
responseBody,
|
2020-02-15 20:18:00 +00:00
|
|
|
responseCode: 200,
|
2020-01-24 01:21:51 +00:00
|
|
|
});
|
2020-01-15 19:41:47 +00:00
|
|
|
});
|
2020-02-01 00:29:51 +00:00
|
|
|
|
2020-06-03 13:41:12 +00:00
|
|
|
it('should create the expected tar stream (single container, --[no]convert-eol)', async () => {
|
2020-02-01 00:29:51 +00:00
|
|
|
const projectPath = path.join(projectsPath, 'no-docker-compose', 'basic');
|
2020-02-15 20:18:00 +00:00
|
|
|
const expectedFiles: ExpectedTarStreamFiles = {
|
2020-06-20 22:05:59 +00:00
|
|
|
'src/.dockerignore': { fileSize: 16, type: 'file' },
|
2020-02-01 00:29:51 +00:00
|
|
|
'src/start.sh': { fileSize: 89, type: 'file' },
|
|
|
|
'src/windows-crlf.sh': {
|
2020-06-20 22:05:59 +00:00
|
|
|
fileSize: 70,
|
2020-02-01 00:29:51 +00:00
|
|
|
type: 'file',
|
|
|
|
},
|
|
|
|
Dockerfile: { fileSize: 88, type: 'file' },
|
|
|
|
'Dockerfile-alt': { fileSize: 30, type: 'file' },
|
|
|
|
};
|
2020-05-01 11:18:11 +00:00
|
|
|
const regSecretsPath = await addRegSecretsEntries(expectedFiles);
|
2020-02-01 00:29:51 +00:00
|
|
|
const responseFilename = 'build-POST-v3.json';
|
|
|
|
const responseBody = await fs.readFile(
|
|
|
|
path.join(builderResponsePath, responseFilename),
|
|
|
|
'utf8',
|
|
|
|
);
|
2020-06-20 22:05:59 +00:00
|
|
|
const expectedResponseLines = [
|
|
|
|
...commonResponseLines[responseFilename],
|
2021-07-15 13:41:38 +00:00
|
|
|
...getDockerignoreWarn1(
|
|
|
|
[path.join(projectPath, 'src', '.dockerignore')],
|
|
|
|
'push',
|
|
|
|
),
|
2020-06-20 22:05:59 +00:00
|
|
|
];
|
2020-02-15 20:18:00 +00:00
|
|
|
if (isWindows) {
|
2020-06-03 13:41:12 +00:00
|
|
|
const fname = path.join(projectPath, 'src', 'windows-crlf.sh');
|
2020-06-20 22:05:59 +00:00
|
|
|
expectedResponseLines.push(
|
|
|
|
`[Warn] CRLF (Windows) line endings detected in file: ${fname}`,
|
|
|
|
'[Warn] Windows-format line endings were detected in some files, but were not converted due to `--noconvert-eol` option.',
|
|
|
|
);
|
2020-02-15 20:18:00 +00:00
|
|
|
}
|
2020-02-01 00:29:51 +00:00
|
|
|
|
2020-02-15 20:18:00 +00:00
|
|
|
await testPushBuildStream({
|
|
|
|
builderMock: builder,
|
2020-06-20 22:05:59 +00:00
|
|
|
commandLine: `push testApp -s ${projectPath} -R ${regSecretsPath} --noconvert-eol`,
|
2020-05-01 11:18:11 +00:00
|
|
|
expectedFiles,
|
|
|
|
expectedQueryParams: commonQueryParams,
|
|
|
|
expectedResponseLines,
|
|
|
|
projectPath,
|
|
|
|
responseBody,
|
|
|
|
responseCode: 200,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-06-16 23:38:03 +00:00
|
|
|
it('should create the expected tar stream (single container, --gitignore)', async () => {
|
|
|
|
const projectPath = path.join(
|
|
|
|
projectsPath,
|
|
|
|
'no-docker-compose',
|
|
|
|
'dockerignore1',
|
|
|
|
);
|
|
|
|
const expectedFiles: ExpectedTarStreamFiles = {
|
|
|
|
'.balena/balena.yml': { fileSize: 12, type: 'file' },
|
|
|
|
'.dockerignore': { fileSize: 438, type: 'file' },
|
|
|
|
'.gitignore': { fileSize: 20, type: 'file' },
|
|
|
|
'.git/bar.txt': { fileSize: 4, type: 'file' },
|
|
|
|
'.git/foo.txt': { fileSize: 4, type: 'file' },
|
|
|
|
'c.txt': { fileSize: 1, type: 'file' },
|
|
|
|
Dockerfile: { fileSize: 13, type: 'file' },
|
|
|
|
'src/.balena/balena.yml': { fileSize: 16, type: 'file' },
|
|
|
|
'src/.gitignore': { fileSize: 10, type: 'file' },
|
|
|
|
'vendor/.git/vendor-git-contents': { fileSize: 20, type: 'file' },
|
|
|
|
// When --gitignore (-g) is provided for v11 compatibility, the old
|
|
|
|
// `zeit/dockerignore` npm package is still used but it is broken on
|
|
|
|
// Windows (reason why we created `@balena/dockerignore`).
|
|
|
|
...(isWindows
|
|
|
|
? {
|
|
|
|
'src/src-b.txt': { fileSize: 5, type: 'file' },
|
|
|
|
'dot.git/bar.txt': { fileSize: 4, type: 'file' },
|
|
|
|
'dot.git/foo.txt': { fileSize: 4, type: 'file' },
|
|
|
|
'vendor/dot.git/vendor-git-contents': {
|
|
|
|
fileSize: 20,
|
|
|
|
type: 'file',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
: {}),
|
|
|
|
};
|
2020-05-29 16:05:35 +00:00
|
|
|
|
2020-06-16 23:38:03 +00:00
|
|
|
const regSecretsPath = await addRegSecretsEntries(expectedFiles);
|
|
|
|
const responseFilename = 'build-POST-v3.json';
|
|
|
|
const responseBody = await fs.readFile(
|
|
|
|
path.join(builderResponsePath, responseFilename),
|
|
|
|
'utf8',
|
|
|
|
);
|
|
|
|
const expectedResponseLines = [
|
2020-06-20 22:05:59 +00:00
|
|
|
...[
|
2020-06-24 23:01:53 +00:00
|
|
|
`[Warn] ${hr}`,
|
2020-06-20 22:05:59 +00:00
|
|
|
'[Warn] Using file ignore patterns from:',
|
|
|
|
`[Warn] * ${path.join(projectPath, '.dockerignore')}`,
|
|
|
|
`[Warn] * ${path.join(projectPath, '.gitignore')}`,
|
|
|
|
`[Warn] * ${path.join(projectPath, 'src', '.gitignore')}`,
|
|
|
|
'[Warn] .gitignore files are being considered because the --gitignore option was used.',
|
|
|
|
'[Warn] This option is deprecated and will be removed in the next major version release.',
|
|
|
|
"[Warn] For more information, see 'balena help push'.",
|
2020-06-24 23:01:53 +00:00
|
|
|
`[Warn] ${hr}`,
|
2020-06-20 22:05:59 +00:00
|
|
|
],
|
2020-06-16 23:38:03 +00:00
|
|
|
...commonResponseLines[responseFilename],
|
|
|
|
];
|
2020-05-01 11:18:11 +00:00
|
|
|
|
2020-06-16 23:38:03 +00:00
|
|
|
await testPushBuildStream({
|
|
|
|
builderMock: builder,
|
2020-07-24 12:25:46 +00:00
|
|
|
commandLine: `push testApp -s ${projectPath} -R ${regSecretsPath} -g`,
|
2020-06-16 23:38:03 +00:00
|
|
|
expectedFiles,
|
|
|
|
expectedQueryParams: commonQueryParams,
|
|
|
|
expectedResponseLines,
|
|
|
|
projectPath,
|
|
|
|
responseBody,
|
|
|
|
responseCode: 200,
|
|
|
|
});
|
|
|
|
});
|
2020-05-01 11:18:11 +00:00
|
|
|
|
|
|
|
it('should create the expected tar stream (single container, --nogitignore)', async () => {
|
|
|
|
const projectPath = path.join(
|
|
|
|
projectsPath,
|
|
|
|
'no-docker-compose',
|
|
|
|
'dockerignore1',
|
|
|
|
);
|
|
|
|
const expectedFiles: ExpectedTarStreamFiles = {
|
|
|
|
'.balena/balena.yml': { fileSize: 12, type: 'file' },
|
|
|
|
'.dockerignore': { fileSize: 438, type: 'file' },
|
|
|
|
'.gitignore': { fileSize: 20, type: 'file' },
|
|
|
|
'.git/foo.txt': { fileSize: 4, type: 'file' },
|
|
|
|
'a.txt': { fileSize: 1, type: 'file' },
|
|
|
|
'c.txt': { fileSize: 1, type: 'file' },
|
|
|
|
Dockerfile: { fileSize: 13, type: 'file' },
|
|
|
|
'src/.balena/balena.yml': { fileSize: 16, type: 'file' },
|
|
|
|
'src/.gitignore': { fileSize: 10, type: 'file' },
|
|
|
|
'src/src-a.txt': { fileSize: 5, type: 'file' },
|
|
|
|
'src/src-c.txt': { fileSize: 5, type: 'file' },
|
|
|
|
'vendor/.git/vendor-git-contents': { fileSize: 20, type: 'file' },
|
|
|
|
};
|
|
|
|
const regSecretsPath = await addRegSecretsEntries(expectedFiles);
|
|
|
|
const responseFilename = 'build-POST-v3.json';
|
|
|
|
const responseBody = await fs.readFile(
|
|
|
|
path.join(builderResponsePath, responseFilename),
|
|
|
|
'utf8',
|
|
|
|
);
|
|
|
|
|
|
|
|
await testPushBuildStream({
|
|
|
|
builderMock: builder,
|
2020-12-18 15:56:47 +00:00
|
|
|
commandLine: `push testApp -s ${projectPath} -R ${regSecretsPath}`,
|
2020-05-01 11:18:11 +00:00
|
|
|
expectedFiles,
|
|
|
|
expectedQueryParams: commonQueryParams,
|
|
|
|
expectedResponseLines: commonResponseLines[responseFilename],
|
|
|
|
projectPath,
|
|
|
|
responseBody,
|
|
|
|
responseCode: 200,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-06-03 13:41:12 +00:00
|
|
|
// NOTE: if this test or other tests involving symbolic links fail on Windows
|
|
|
|
// (with a mismatched fileSize 13 vs 5 for 'symlink-a.txt'), ensure that the
|
|
|
|
// `core.symlinks` property is set to `true` in the `.git/config` file. Ref:
|
|
|
|
// https://git-scm.com/docs/git-config#Documentation/git-config.txt-coresymlinks
|
2020-06-16 23:38:03 +00:00
|
|
|
it('should create the expected tar stream (single container, symbolic links, --gitignore)', async () => {
|
2020-05-01 11:18:11 +00:00
|
|
|
const projectPath = path.join(
|
|
|
|
projectsPath,
|
|
|
|
'no-docker-compose',
|
|
|
|
'dockerignore2',
|
|
|
|
);
|
|
|
|
const expectedFiles: ExpectedTarStreamFiles = {
|
2020-06-24 23:01:53 +00:00
|
|
|
'.dockerignore': { fileSize: 33, type: 'file' },
|
2020-05-01 11:18:11 +00:00
|
|
|
'b.txt': { fileSize: 1, type: 'file' },
|
|
|
|
Dockerfile: { fileSize: 13, type: 'file' },
|
2020-06-24 23:01:53 +00:00
|
|
|
'lib/.dockerignore': { fileSize: 10, type: 'file' },
|
|
|
|
'lib/src-b.txt': { fileSize: 5, type: 'file' },
|
2020-05-01 11:18:11 +00:00
|
|
|
'src/src-b.txt': { fileSize: 5, type: 'file' },
|
|
|
|
'symlink-a.txt': { fileSize: 5, type: 'file' },
|
2020-06-24 23:01:53 +00:00
|
|
|
...(isWindows
|
|
|
|
? {
|
|
|
|
'lib/src-a.txt': { fileSize: 5, type: 'file' },
|
|
|
|
'src/src-a.txt': { fileSize: 5, type: 'file' },
|
|
|
|
}
|
|
|
|
: {}),
|
2020-05-01 11:18:11 +00:00
|
|
|
};
|
|
|
|
const regSecretsPath = await addRegSecretsEntries(expectedFiles);
|
|
|
|
const responseFilename = 'build-POST-v3.json';
|
|
|
|
const responseBody = await fs.readFile(
|
|
|
|
path.join(builderResponsePath, responseFilename),
|
|
|
|
'utf8',
|
|
|
|
);
|
2020-06-24 23:01:53 +00:00
|
|
|
const expectedResponseLines = isWindows
|
|
|
|
? [
|
|
|
|
`[Warn] ${hr}`,
|
|
|
|
'[Warn] Using file ignore patterns from:',
|
|
|
|
`[Warn] * ${path.join(projectPath, '.dockerignore')}`,
|
|
|
|
'[Warn] The --gitignore option was used, but no .gitignore files were found.',
|
|
|
|
'[Warn] The --gitignore option is deprecated and will be removed in the next major',
|
|
|
|
'[Warn] version release. It prevents the use of a better dockerignore parser and',
|
|
|
|
'[Warn] filter library that fixes several issues on Windows and improves compatibility',
|
|
|
|
"[Warn] with 'docker build'. For more information, see 'balena help push'.",
|
|
|
|
`[Warn] ${hr}`,
|
|
|
|
...commonResponseLines[responseFilename],
|
|
|
|
]
|
|
|
|
: commonResponseLines[responseFilename];
|
2020-05-01 11:18:11 +00:00
|
|
|
|
|
|
|
await testPushBuildStream({
|
|
|
|
builderMock: builder,
|
2020-07-24 12:25:46 +00:00
|
|
|
commandLine: `push testApp -s ${projectPath} -R ${regSecretsPath} --gitignore`,
|
2020-05-01 11:18:11 +00:00
|
|
|
expectedFiles,
|
|
|
|
expectedQueryParams: commonQueryParams,
|
2020-06-24 23:01:53 +00:00
|
|
|
expectedResponseLines,
|
2020-05-01 11:18:11 +00:00
|
|
|
projectPath,
|
|
|
|
responseBody,
|
|
|
|
responseCode: 200,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-06-24 23:01:53 +00:00
|
|
|
it('should create the expected tar stream (single container, --multi-dockerignore)', async () => {
|
2020-05-01 11:18:11 +00:00
|
|
|
const projectPath = path.join(
|
|
|
|
projectsPath,
|
|
|
|
'no-docker-compose',
|
|
|
|
'dockerignore2',
|
|
|
|
);
|
|
|
|
const expectedFiles: ExpectedTarStreamFiles = {
|
2020-06-24 23:01:53 +00:00
|
|
|
'.dockerignore': { fileSize: 33, type: 'file' },
|
2020-05-01 11:18:11 +00:00
|
|
|
'b.txt': { fileSize: 1, type: 'file' },
|
|
|
|
Dockerfile: { fileSize: 13, type: 'file' },
|
2020-06-24 23:01:53 +00:00
|
|
|
'lib/.dockerignore': { fileSize: 10, type: 'file' },
|
|
|
|
'lib/src-b.txt': { fileSize: 5, type: 'file' },
|
2020-05-01 11:18:11 +00:00
|
|
|
'src/src-b.txt': { fileSize: 5, type: 'file' },
|
|
|
|
'symlink-a.txt': { fileSize: 5, type: 'file' },
|
|
|
|
};
|
|
|
|
const regSecretsPath = await addRegSecretsEntries(expectedFiles);
|
|
|
|
const responseFilename = 'build-POST-v3.json';
|
|
|
|
const responseBody = await fs.readFile(
|
|
|
|
path.join(builderResponsePath, responseFilename),
|
|
|
|
'utf8',
|
|
|
|
);
|
2020-06-24 23:01:53 +00:00
|
|
|
const expectedResponseLines: string[] = [
|
2021-07-15 13:41:38 +00:00
|
|
|
...getDockerignoreWarn2(
|
|
|
|
[path.join(projectPath, 'lib', '.dockerignore')],
|
|
|
|
'push',
|
|
|
|
),
|
2020-06-24 23:01:53 +00:00
|
|
|
...commonResponseLines[responseFilename],
|
|
|
|
];
|
2020-05-01 11:18:11 +00:00
|
|
|
|
|
|
|
await testPushBuildStream({
|
|
|
|
builderMock: builder,
|
2020-07-24 12:25:46 +00:00
|
|
|
commandLine: `push testApp -s ${projectPath} -R ${regSecretsPath} -m`,
|
2020-02-15 20:18:00 +00:00
|
|
|
expectedFiles,
|
|
|
|
expectedQueryParams: commonQueryParams,
|
|
|
|
expectedResponseLines,
|
|
|
|
projectPath,
|
2020-02-01 00:29:51 +00:00
|
|
|
responseBody,
|
2020-02-15 20:18:00 +00:00
|
|
|
responseCode: 200,
|
2020-02-01 00:29:51 +00:00
|
|
|
});
|
2020-02-15 20:18:00 +00:00
|
|
|
});
|
2020-02-01 00:29:51 +00:00
|
|
|
|
2020-02-15 20:18:00 +00:00
|
|
|
it('should create the expected tar stream (docker-compose)', async () => {
|
|
|
|
const projectPath = path.join(projectsPath, 'docker-compose', 'basic');
|
|
|
|
const expectedFiles: ExpectedTarStreamFiles = {
|
2020-05-01 11:18:11 +00:00
|
|
|
'.balena/balena.yml': { fileSize: 197, type: 'file' },
|
|
|
|
'.dockerignore': { fileSize: 22, type: 'file' },
|
2020-10-19 23:00:53 +00:00
|
|
|
'docker-compose.yml': { fileSize: 332, type: 'file' },
|
2020-02-15 20:18:00 +00:00
|
|
|
'service1/Dockerfile.template': { fileSize: 144, type: 'file' },
|
|
|
|
'service1/file1.sh': { fileSize: 12, type: 'file' },
|
|
|
|
'service2/Dockerfile-alt': { fileSize: 40, type: 'file' },
|
2020-06-24 23:01:53 +00:00
|
|
|
'service2/.dockerignore': { fileSize: 12, type: 'file' },
|
2020-02-15 20:18:00 +00:00
|
|
|
'service2/file2-crlf.sh': {
|
|
|
|
fileSize: isWindows ? 12 : 14,
|
|
|
|
testStream: isWindows ? expectStreamNoCRLF : undefined,
|
|
|
|
type: 'file',
|
|
|
|
},
|
2020-06-24 23:01:53 +00:00
|
|
|
'service2/src/file1.sh': { fileSize: 12, type: 'file' },
|
2020-02-15 20:18:00 +00:00
|
|
|
};
|
2020-05-01 11:18:11 +00:00
|
|
|
const regSecretsPath = await addRegSecretsEntries(expectedFiles);
|
2020-02-15 20:18:00 +00:00
|
|
|
const responseFilename = 'build-POST-v3.json';
|
|
|
|
const responseBody = await fs.readFile(
|
|
|
|
path.join(builderResponsePath, responseFilename),
|
|
|
|
'utf8',
|
2020-02-01 00:29:51 +00:00
|
|
|
);
|
2020-02-15 20:18:00 +00:00
|
|
|
const expectedResponseLines: string[] = [
|
|
|
|
...commonResponseLines[responseFilename],
|
2021-07-15 13:41:38 +00:00
|
|
|
...getDockerignoreWarn1(
|
|
|
|
[path.join(projectPath, 'service2', '.dockerignore')],
|
|
|
|
'push',
|
|
|
|
),
|
2020-02-15 20:18:00 +00:00
|
|
|
];
|
|
|
|
if (isWindows) {
|
|
|
|
expectedResponseLines.push(
|
2020-02-05 22:26:55 +00:00
|
|
|
`[Info] Converting line endings CRLF -> LF for file: ${path.join(
|
|
|
|
projectPath,
|
2020-02-15 20:18:00 +00:00
|
|
|
'service2',
|
|
|
|
'file2-crlf.sh',
|
2020-02-05 22:26:55 +00:00
|
|
|
)}`,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-02-15 20:18:00 +00:00
|
|
|
await testPushBuildStream({
|
|
|
|
builderMock: builder,
|
2020-07-24 12:25:46 +00:00
|
|
|
commandLine: `push testApp -s ${projectPath} -R ${regSecretsPath}`,
|
2020-02-15 20:18:00 +00:00
|
|
|
expectedFiles,
|
|
|
|
expectedQueryParams: commonQueryParams,
|
|
|
|
expectedResponseLines,
|
|
|
|
projectPath,
|
|
|
|
responseBody,
|
|
|
|
responseCode: 200,
|
|
|
|
});
|
2020-02-01 00:29:51 +00:00
|
|
|
});
|
2020-06-24 23:01:53 +00:00
|
|
|
|
|
|
|
it('should create the expected tar stream (docker-compose, --multi-dockerignore)', async () => {
|
|
|
|
const projectPath = path.join(projectsPath, 'docker-compose', 'basic');
|
|
|
|
const expectedFiles: ExpectedTarStreamFiles = {
|
|
|
|
'.balena/balena.yml': { fileSize: 197, type: 'file' },
|
|
|
|
'.dockerignore': { fileSize: 22, type: 'file' },
|
2020-10-19 23:00:53 +00:00
|
|
|
'docker-compose.yml': { fileSize: 332, type: 'file' },
|
2020-06-24 23:01:53 +00:00
|
|
|
'service1/Dockerfile.template': { fileSize: 144, type: 'file' },
|
|
|
|
'service1/file1.sh': { fileSize: 12, type: 'file' },
|
|
|
|
'service1/test-ignore.txt': { fileSize: 12, type: 'file' },
|
|
|
|
'service2/Dockerfile-alt': { fileSize: 40, type: 'file' },
|
|
|
|
'service2/.dockerignore': { fileSize: 12, type: 'file' },
|
|
|
|
'service2/file2-crlf.sh': {
|
|
|
|
fileSize: isWindows ? 12 : 14,
|
|
|
|
testStream: isWindows ? expectStreamNoCRLF : undefined,
|
|
|
|
type: 'file',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const regSecretsPath = await addRegSecretsEntries(expectedFiles);
|
|
|
|
const responseFilename = 'build-POST-v3.json';
|
|
|
|
const responseBody = await fs.readFile(
|
|
|
|
path.join(builderResponsePath, responseFilename),
|
|
|
|
'utf8',
|
|
|
|
);
|
|
|
|
const expectedResponseLines: string[] = [
|
|
|
|
...commonResponseLines[responseFilename],
|
|
|
|
...[
|
|
|
|
`[Info] ${hr}`,
|
|
|
|
'[Info] The --multi-dockerignore option is being used, and a .dockerignore file was',
|
|
|
|
'[Info] found at the project source (root) directory. Note that this file will not',
|
|
|
|
'[Info] be used to filter service subdirectories. See "balena help push".',
|
|
|
|
`[Info] ${hr}`,
|
|
|
|
],
|
|
|
|
];
|
|
|
|
if (isWindows) {
|
|
|
|
expectedResponseLines.push(
|
|
|
|
`[Info] Converting line endings CRLF -> LF for file: ${path.join(
|
|
|
|
projectPath,
|
|
|
|
'service2',
|
|
|
|
'file2-crlf.sh',
|
|
|
|
)}`,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
await testPushBuildStream({
|
|
|
|
builderMock: builder,
|
2020-07-24 12:25:46 +00:00
|
|
|
commandLine: `push testApp -s ${projectPath} -R ${regSecretsPath} -m`,
|
2020-06-24 23:01:53 +00:00
|
|
|
expectedFiles,
|
|
|
|
expectedQueryParams: commonQueryParams,
|
|
|
|
expectedResponseLines,
|
|
|
|
projectPath,
|
|
|
|
responseBody,
|
|
|
|
responseCode: 200,
|
|
|
|
});
|
|
|
|
});
|
2020-01-15 19:41:47 +00:00
|
|
|
});
|
2020-02-15 20:07:09 +00:00
|
|
|
|
2020-06-15 22:53:07 +00:00
|
|
|
describe('balena push: project validation', function () {
|
2020-07-09 14:39:33 +00:00
|
|
|
let api: BalenaAPIMock;
|
|
|
|
|
|
|
|
this.beforeEach(() => {
|
|
|
|
api = new BalenaAPIMock();
|
|
|
|
api.expectGetMixpanel({ optional: true });
|
|
|
|
});
|
|
|
|
|
|
|
|
this.afterEach(() => {
|
|
|
|
// Check all expected api calls have been made and clean up.
|
|
|
|
api.done();
|
|
|
|
});
|
|
|
|
|
2020-02-15 20:07:09 +00:00
|
|
|
it('should raise ExpectedError if the project folder is not a directory', async () => {
|
|
|
|
const projectPath = path.join(
|
|
|
|
projectsPath,
|
|
|
|
'docker-compose',
|
|
|
|
'basic',
|
|
|
|
'docker-compose.yml',
|
|
|
|
);
|
|
|
|
const expectedErrorLines = [
|
|
|
|
`Could not access source folder: "${projectPath}"`,
|
|
|
|
];
|
|
|
|
|
|
|
|
const { out, err } = await runCommand(
|
2020-06-16 23:38:03 +00:00
|
|
|
`push testApp --source ${projectPath} --gitignore`,
|
2020-02-15 20:07:09 +00:00
|
|
|
);
|
2020-06-15 22:53:04 +00:00
|
|
|
expect(cleanOutput(err, true)).to.include.members(expectedErrorLines);
|
2020-02-15 20:07:09 +00:00
|
|
|
expect(out).to.be.empty;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should raise ExpectedError if a Dockerfile cannot be found', async () => {
|
|
|
|
const projectPath = path.join(
|
|
|
|
projectsPath,
|
|
|
|
'docker-compose',
|
|
|
|
'basic',
|
|
|
|
'service2',
|
|
|
|
);
|
|
|
|
const expectedErrorLines = [
|
|
|
|
'Error: no "Dockerfile[.*]", "docker-compose.yml" or "package.json" file',
|
|
|
|
`found in source folder "${projectPath}"`,
|
|
|
|
];
|
|
|
|
|
|
|
|
const { out, err } = await runCommand(
|
|
|
|
`push testApp --source ${projectPath}`,
|
|
|
|
);
|
2020-06-15 22:53:04 +00:00
|
|
|
expect(cleanOutput(err, true)).to.include.members(expectedErrorLines);
|
2020-02-15 20:07:09 +00:00
|
|
|
expect(out).to.be.empty;
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should log a warning if a docker-compose.yml exists in a parent folder', async () => {
|
|
|
|
const projectPath = path.join(
|
|
|
|
projectsPath,
|
|
|
|
'docker-compose',
|
|
|
|
'basic',
|
|
|
|
'service1',
|
|
|
|
);
|
2020-06-20 22:05:59 +00:00
|
|
|
const expectedErrorLines = [
|
|
|
|
'Error: "docker-compose.y[a]ml" file found in parent directory: please check that',
|
|
|
|
"the correct source folder was specified. (Suppress with '--noparent-check'.)",
|
|
|
|
];
|
2020-02-15 20:07:09 +00:00
|
|
|
|
|
|
|
const { out, err } = await runCommand(
|
|
|
|
`push testApp --source ${projectPath} --nolive`,
|
|
|
|
);
|
2020-06-15 22:53:04 +00:00
|
|
|
expect(cleanOutput(err, true)).to.include.members(expectedErrorLines);
|
2020-06-20 22:05:59 +00:00
|
|
|
expect(out).to.be.empty;
|
2020-02-15 20:07:09 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should suppress a parent folder check with --noparent-check', async () => {
|
|
|
|
const projectPath = path.join(
|
|
|
|
projectsPath,
|
|
|
|
'docker-compose',
|
|
|
|
'basic',
|
|
|
|
'service1',
|
|
|
|
);
|
|
|
|
const expectedErrorLines = [
|
|
|
|
'The --nolive flag is only valid when pushing to a local mode device',
|
|
|
|
];
|
|
|
|
|
|
|
|
const { out, err } = await runCommand(
|
|
|
|
`push testApp --source ${projectPath} --nolive --noparent-check`,
|
|
|
|
);
|
2020-06-15 22:53:04 +00:00
|
|
|
expect(cleanOutput(err, true)).to.include.members(expectedErrorLines);
|
2020-02-15 20:07:09 +00:00
|
|
|
expect(out).to.be.empty;
|
|
|
|
});
|
|
|
|
});
|