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-01-24 01:21:51 +00:00
|
|
|
// tslint:disable-next-line:no-var-requires
|
|
|
|
require('../config-tests'); // required for side effects
|
2020-01-15 19:41:47 +00:00
|
|
|
|
2020-01-24 01:21:51 +00:00
|
|
|
import { fs } from 'mz';
|
2020-01-15 19:41:47 +00:00
|
|
|
import * as path from 'path';
|
|
|
|
|
|
|
|
import { BalenaAPIMock } from '../balena-api-mock';
|
2020-02-15 20:18:00 +00:00
|
|
|
import { ExpectedTarStreamFiles, testDockerBuildStream } from '../docker-build';
|
2020-01-24 01:21:51 +00:00
|
|
|
import { DockerMock, dockerResponsePath } from '../docker-mock';
|
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-02-15 20:18:00 +00:00
|
|
|
|
|
|
|
const commonResponseLines = {
|
2020-01-24 01:21:51 +00:00
|
|
|
'build-POST.json': [
|
|
|
|
'[Info] Building for armv7hf/raspberrypi3',
|
|
|
|
'[Info] Docker Desktop detected (daemon architecture: "x86_64")',
|
|
|
|
'[Info] Docker itself will determine and enable architecture emulation if required,',
|
|
|
|
'[Info] without balena-cli intervention and regardless of the --emulated option.',
|
|
|
|
'[Build] main Image size: 1.14 MB',
|
|
|
|
'[Info] Creating release...',
|
|
|
|
'[Info] Pushing images to registry...',
|
|
|
|
'[Info] Saving release...',
|
|
|
|
'[Success] Deploy succeeded!',
|
|
|
|
'[Success] Release: 09f7c3e1fdec609be818002299edfc2a',
|
|
|
|
],
|
|
|
|
};
|
2020-01-15 19:41:47 +00:00
|
|
|
|
2020-02-15 20:18:00 +00:00
|
|
|
const commonQueryParams = [
|
|
|
|
['t', '${tag}'],
|
|
|
|
['buildargs', '{}'],
|
|
|
|
['labels', ''],
|
|
|
|
];
|
|
|
|
|
2020-01-15 19:41:47 +00:00
|
|
|
describe('balena deploy', function() {
|
|
|
|
let api: BalenaAPIMock;
|
|
|
|
let docker: DockerMock;
|
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();
|
|
|
|
docker = new DockerMock();
|
|
|
|
api.expectGetWhoAmI({ optional: true, persist: true });
|
|
|
|
api.expectGetMixpanel({ optional: true });
|
|
|
|
api.expectGetDeviceTypes();
|
|
|
|
api.expectGetApplication();
|
|
|
|
api.expectPatchRelease();
|
|
|
|
api.expectPostRelease();
|
|
|
|
api.expectGetRelease();
|
|
|
|
api.expectGetUser();
|
|
|
|
api.expectGetService({ serviceName: 'main' });
|
|
|
|
api.expectPostService404();
|
|
|
|
api.expectGetAuth();
|
|
|
|
api.expectPostImage();
|
|
|
|
api.expectPostImageIsPartOfRelease();
|
|
|
|
api.expectPostImageLabel();
|
|
|
|
api.expectPatchImage();
|
|
|
|
|
|
|
|
docker.expectGetPing();
|
|
|
|
docker.expectGetInfo();
|
2020-02-15 20:18:00 +00:00
|
|
|
docker.expectGetVersion({ persist: true });
|
2020-01-15 19:41:47 +00:00
|
|
|
docker.expectPostImagesTag();
|
|
|
|
docker.expectPostImagesPush();
|
|
|
|
docker.expectDeleteImages();
|
|
|
|
});
|
|
|
|
|
|
|
|
this.afterEach(() => {
|
|
|
|
// Check all expected api calls have been made and clean up.
|
|
|
|
api.done();
|
|
|
|
docker.done();
|
|
|
|
});
|
|
|
|
|
2020-02-01 00:29:51 +00:00
|
|
|
it('should create the expected --build 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-01-15 19:41:47 +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-01-15 19:41:47 +00:00
|
|
|
};
|
2020-01-24 01:21:51 +00:00
|
|
|
const responseFilename = 'build-POST.json';
|
|
|
|
const responseBody = await fs.readFile(
|
|
|
|
path.join(dockerResponsePath, responseFilename),
|
|
|
|
'utf8',
|
|
|
|
);
|
2020-02-15 20:18:00 +00:00
|
|
|
const expectedResponseLines = [
|
|
|
|
...commonResponseLines[responseFilename],
|
2020-02-15 20:20:56 +00:00
|
|
|
`[Info] No "docker-compose.yml" file found at "${projectPath}"`,
|
|
|
|
`[Info] Creating default composition with source: "${projectPath}"`,
|
2020-02-05 22:26:55 +00:00
|
|
|
];
|
2020-02-15 20:18:00 +00:00
|
|
|
if (isWindows) {
|
|
|
|
expectedResponseLines.push(
|
2020-02-05 22:26:55 +00:00
|
|
|
`[Warn] CRLF (Windows) line endings detected in file: ${path.join(
|
|
|
|
projectPath,
|
|
|
|
'src',
|
|
|
|
'windows-crlf.sh',
|
|
|
|
)}`,
|
2020-02-15 20:18:00 +00:00
|
|
|
'[Warn] Windows-format line endings were detected in some files. Consider using the `--convert-eol` option.',
|
2020-02-05 22:26:55 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-02-15 20:18:00 +00:00
|
|
|
await testDockerBuildStream({
|
|
|
|
commandLine: `deploy testApp --build --source ${projectPath}`,
|
|
|
|
dockerMock: docker,
|
|
|
|
expectedFilesByService: { main: expectedFiles },
|
|
|
|
expectedQueryParamsByService: { main: commonQueryParams },
|
|
|
|
expectedResponseLines,
|
|
|
|
projectPath,
|
|
|
|
responseBody,
|
|
|
|
responseCode: 200,
|
|
|
|
services: ['main'],
|
|
|
|
});
|
2020-01-15 19:41:47 +00:00
|
|
|
});
|
|
|
|
});
|