2020-01-15 19:41:47 +00:00
|
|
|
/**
|
|
|
|
* @license
|
2021-05-14 23:58:15 +00:00
|
|
|
* Copyright 2020-2021 Balena Ltd.
|
2020-01-15 19:41:47 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2022-06-28 12:22:42 +00:00
|
|
|
import type { Request as ReleaseRequest } from '@balena/compose/dist/release';
|
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-10-19 23:00:53 +00:00
|
|
|
import * as _ from 'lodash';
|
2021-05-19 22:12:49 +00:00
|
|
|
import * as nock from 'nock';
|
2020-01-15 19:41:47 +00:00
|
|
|
import * as path from 'path';
|
2020-05-21 13:51:10 +00:00
|
|
|
import * as sinon from 'sinon';
|
2020-01-15 19:41:47 +00:00
|
|
|
|
2021-06-25 23:42:07 +00:00
|
|
|
import { BalenaAPIMock } from '../nock/balena-api-mock';
|
2020-06-03 13:41:12 +00:00
|
|
|
import { expectStreamNoCRLF, testDockerBuildStream } from '../docker-build';
|
2021-06-25 23:42:07 +00:00
|
|
|
import { DockerMock, dockerResponsePath } from '../nock/docker-mock';
|
2020-05-21 13:51:10 +00:00
|
|
|
import { cleanOutput, runCommand, switchSentry } from '../helpers';
|
2020-06-24 23:01:53 +00:00
|
|
|
import {
|
|
|
|
ExpectedTarStreamFiles,
|
|
|
|
ExpectedTarStreamFilesByService,
|
2021-07-15 13:41:38 +00:00
|
|
|
getDockerignoreWarn1,
|
2021-11-22 01:14:56 +00:00
|
|
|
getDockerignoreWarn3,
|
2020-06-24 23:01:53 +00:00
|
|
|
} 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-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.',
|
2020-06-24 23:01:53 +00:00
|
|
|
// '[Build] main Step 1/4 : FROM busybox',
|
2020-01-24 01:21:51 +00:00
|
|
|
'[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 = [
|
2021-07-28 13:19:57 +00:00
|
|
|
['platform', 'linux/arm/v7'],
|
2020-02-15 20:18:00 +00:00
|
|
|
['t', '${tag}'],
|
|
|
|
['buildargs', '{}'],
|
|
|
|
['labels', ''],
|
|
|
|
];
|
|
|
|
|
2020-10-19 23:00:53 +00:00
|
|
|
const commonComposeQueryParams = {
|
|
|
|
t: '${tag}',
|
|
|
|
buildargs: {
|
|
|
|
MY_VAR_1: 'This is a variable',
|
|
|
|
MY_VAR_2: 'Also a variable',
|
|
|
|
},
|
|
|
|
labels: '',
|
|
|
|
};
|
2020-06-24 23:01:53 +00:00
|
|
|
|
2021-07-28 13:19:57 +00:00
|
|
|
const commonComposeQueryParamsArmV7 = {
|
|
|
|
...commonComposeQueryParams,
|
|
|
|
platform: 'linux/arm/v7',
|
|
|
|
};
|
|
|
|
|
2020-06-15 22:53:07 +00:00
|
|
|
describe('balena deploy', function () {
|
2020-01-15 19:41:47 +00:00
|
|
|
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 });
|
2021-08-30 22:10:54 +00:00
|
|
|
api.expectGetApplication({ expandArchitecture: true });
|
2020-01-15 19:41:47 +00:00
|
|
|
api.expectGetRelease();
|
2020-07-31 14:35:20 +00:00
|
|
|
api.expectGetUser();
|
2020-01-15 19:41:47 +00:00
|
|
|
api.expectGetService({ serviceName: 'main' });
|
2020-08-04 13:17:51 +00:00
|
|
|
api.expectPostService409();
|
2020-01-15 19:41:47 +00:00
|
|
|
api.expectGetAuth();
|
|
|
|
api.expectPostImage();
|
|
|
|
api.expectPostImageIsPartOfRelease();
|
|
|
|
|
2020-06-24 23:01:53 +00:00
|
|
|
docker.expectGetImages();
|
2020-01-15 19:41:47 +00:00
|
|
|
docker.expectGetPing();
|
2020-03-06 21:19:24 +00:00
|
|
|
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-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-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}"`,
|
2021-07-15 13:41:38 +00:00
|
|
|
...getDockerignoreWarn1(
|
|
|
|
[path.join(projectPath, 'src', '.dockerignore')],
|
|
|
|
'deploy',
|
|
|
|
),
|
2020-02-05 22:26:55 +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
|
|
|
}
|
|
|
|
|
2021-05-19 22:12:49 +00:00
|
|
|
api.expectPostRelease({});
|
2020-05-21 13:51:10 +00:00
|
|
|
api.expectPatchImage({});
|
|
|
|
api.expectPatchRelease({});
|
2020-06-24 23:01:53 +00:00
|
|
|
api.expectPostImageLabel();
|
2021-07-28 13:19:57 +00:00
|
|
|
docker.expectGetManifestBusybox();
|
2020-05-21 13:51:10 +00:00
|
|
|
|
|
|
|
await testDockerBuildStream({
|
2021-12-18 23:27:59 +00:00
|
|
|
commandLine: `deploy testApp --build --source ${projectPath}`,
|
2020-05-21 13:51:10 +00:00
|
|
|
dockerMock: docker,
|
|
|
|
expectedFilesByService: { main: expectedFiles },
|
|
|
|
expectedQueryParamsByService: { main: commonQueryParams },
|
|
|
|
expectedResponseLines,
|
|
|
|
projectPath,
|
|
|
|
responseBody,
|
|
|
|
responseCode: 200,
|
|
|
|
services: ['main'],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-05-19 22:12:49 +00:00
|
|
|
it('should handle the contract and final status for a final (non-draft) release', async () => {
|
|
|
|
const projectPath = path.join(
|
|
|
|
projectsPath,
|
|
|
|
'no-docker-compose',
|
|
|
|
'with-contract',
|
|
|
|
);
|
|
|
|
const expectedFiles: ExpectedTarStreamFiles = {
|
|
|
|
'src/start.sh': { fileSize: 30, type: 'file' },
|
|
|
|
Dockerfile: { fileSize: 88, type: 'file' },
|
2021-08-26 14:05:50 +00:00
|
|
|
'balena.yml': { fileSize: 55, type: 'file' },
|
2021-05-19 22:12:49 +00:00
|
|
|
};
|
|
|
|
const responseFilename = 'build-POST.json';
|
|
|
|
const responseBody = await fs.readFile(
|
|
|
|
path.join(dockerResponsePath, responseFilename),
|
|
|
|
'utf8',
|
|
|
|
);
|
|
|
|
const expectedResponseLines = [
|
|
|
|
...commonResponseLines[responseFilename],
|
|
|
|
`[Info] No "docker-compose.yml" file found at "${projectPath}"`,
|
|
|
|
`[Info] Creating default composition with source: "${projectPath}"`,
|
|
|
|
];
|
|
|
|
|
|
|
|
api.expectPostRelease({
|
|
|
|
inspectRequest: (_uri: string, requestBody: nock.Body) => {
|
2021-08-26 14:05:50 +00:00
|
|
|
const body = requestBody.valueOf() as Partial<ReleaseRequest>;
|
|
|
|
expect(body.contract).to.be.equal(
|
|
|
|
'{"name":"testContract","type":"sw.application","version":"1.5.2"}',
|
|
|
|
);
|
2021-05-19 22:12:49 +00:00
|
|
|
expect(body.is_final).to.be.true;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
api.expectPatchImage({});
|
|
|
|
api.expectPatchRelease({});
|
|
|
|
api.expectPostImageLabel();
|
2021-07-28 13:19:57 +00:00
|
|
|
docker.expectGetManifestBusybox();
|
2021-05-19 22:12:49 +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'],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should handle the contract and final status for a draft release', async () => {
|
|
|
|
const projectPath = path.join(
|
|
|
|
projectsPath,
|
|
|
|
'no-docker-compose',
|
|
|
|
'with-contract',
|
|
|
|
);
|
|
|
|
const expectedFiles: ExpectedTarStreamFiles = {
|
|
|
|
'src/start.sh': { fileSize: 30, type: 'file' },
|
|
|
|
Dockerfile: { fileSize: 88, type: 'file' },
|
2021-08-26 14:05:50 +00:00
|
|
|
'balena.yml': { fileSize: 55, type: 'file' },
|
2021-05-19 22:12:49 +00:00
|
|
|
};
|
|
|
|
const responseFilename = 'build-POST.json';
|
|
|
|
const responseBody = await fs.readFile(
|
|
|
|
path.join(dockerResponsePath, responseFilename),
|
|
|
|
'utf8',
|
|
|
|
);
|
|
|
|
const expectedResponseLines = [
|
|
|
|
...commonResponseLines[responseFilename],
|
|
|
|
`[Info] No "docker-compose.yml" file found at "${projectPath}"`,
|
|
|
|
`[Info] Creating default composition with source: "${projectPath}"`,
|
|
|
|
];
|
|
|
|
|
|
|
|
api.expectPostRelease({
|
|
|
|
inspectRequest: (_uri: string, requestBody: nock.Body) => {
|
2021-08-26 14:05:50 +00:00
|
|
|
const body = requestBody.valueOf() as Partial<ReleaseRequest>;
|
|
|
|
expect(body.contract).to.be.equal(
|
|
|
|
'{"name":"testContract","type":"sw.application","version":"1.5.2"}',
|
|
|
|
);
|
2021-05-19 22:12:49 +00:00
|
|
|
expect(body.semver).to.be.equal('1.5.2');
|
|
|
|
expect(body.is_final).to.be.false;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
api.expectPatchImage({});
|
|
|
|
api.expectPatchRelease({});
|
|
|
|
api.expectPostImageLabel();
|
2021-07-28 13:19:57 +00:00
|
|
|
docker.expectGetManifestBusybox();
|
2021-05-19 22:12:49 +00:00
|
|
|
|
|
|
|
await testDockerBuildStream({
|
|
|
|
commandLine: `deploy testApp --build --draft --source ${projectPath}`,
|
|
|
|
dockerMock: docker,
|
|
|
|
expectedFilesByService: { main: expectedFiles },
|
|
|
|
expectedQueryParamsByService: { main: commonQueryParams },
|
|
|
|
expectedResponseLines,
|
|
|
|
projectPath,
|
|
|
|
responseBody,
|
|
|
|
responseCode: 200,
|
|
|
|
services: ['main'],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-05-21 13:51:10 +00:00
|
|
|
it('should update a release with status="failed" on error (single container)', async () => {
|
2020-06-20 22:05:59 +00:00
|
|
|
let sentryStatus: boolean | undefined;
|
2020-05-21 13:51:10 +00:00
|
|
|
const projectPath = path.join(projectsPath, 'no-docker-compose', 'basic');
|
|
|
|
const expectedFiles: ExpectedTarStreamFiles = {
|
2020-06-20 22:05:59 +00:00
|
|
|
'src/.dockerignore': { fileSize: 16, type: 'file' },
|
2020-05-21 13:51:10 +00:00
|
|
|
'src/start.sh': { fileSize: 89, type: 'file' },
|
|
|
|
'src/windows-crlf.sh': { fileSize: 70, type: 'file' },
|
|
|
|
Dockerfile: { fileSize: 88, type: 'file' },
|
|
|
|
'Dockerfile-alt': { fileSize: 30, type: 'file' },
|
|
|
|
};
|
|
|
|
const responseFilename = 'build-POST.json';
|
|
|
|
const responseBody = await fs.readFile(
|
|
|
|
path.join(dockerResponsePath, responseFilename),
|
|
|
|
'utf8',
|
|
|
|
);
|
|
|
|
const expectedResponseLines = ['[Error] Deploy failed'];
|
|
|
|
const errMsg = 'Patch Image Error';
|
|
|
|
const expectedErrorLines = [errMsg];
|
2020-06-15 22:53:04 +00:00
|
|
|
// The SDK should produce an "unexpected" BalenaRequestError, which
|
|
|
|
// causes the CLI to call process.exit() with process.exitCode = 1
|
|
|
|
const expectedExitCode = 1;
|
2020-05-21 13:51:10 +00:00
|
|
|
|
2021-05-19 22:12:49 +00:00
|
|
|
api.expectPostRelease({});
|
2021-07-28 13:19:57 +00:00
|
|
|
docker.expectGetManifestBusybox();
|
2021-05-19 22:12:49 +00:00
|
|
|
|
2020-05-21 13:51:10 +00:00
|
|
|
// Mock this patch HTTP request to return status code 500, in which case
|
|
|
|
// the release status should be saved as "failed" rather than "success"
|
|
|
|
api.expectPatchImage({
|
|
|
|
replyBody: errMsg,
|
|
|
|
statusCode: 500,
|
|
|
|
inspectRequest: (_uri, requestBody) => {
|
|
|
|
const imageBody = requestBody as Partial<
|
2022-06-28 12:22:42 +00:00
|
|
|
import('@balena/compose/dist/release/models').ImageModel
|
2020-05-21 13:51:10 +00:00
|
|
|
>;
|
|
|
|
expect(imageBody.status).to.equal('success');
|
|
|
|
},
|
|
|
|
});
|
|
|
|
// Check that the CLI patches the release with status="failed"
|
|
|
|
api.expectPatchRelease({
|
|
|
|
inspectRequest: (_uri, requestBody) => {
|
|
|
|
const releaseBody = requestBody as Partial<
|
2022-06-28 12:22:42 +00:00
|
|
|
import('@balena/compose/dist/release/models').ReleaseModel
|
2020-05-21 13:51:10 +00:00
|
|
|
>;
|
|
|
|
expect(releaseBody.status).to.equal('failed');
|
|
|
|
},
|
|
|
|
});
|
2020-06-24 23:01:53 +00:00
|
|
|
api.expectPostImageLabel();
|
2020-05-21 13:51:10 +00:00
|
|
|
|
2020-06-20 22:05:59 +00:00
|
|
|
try {
|
|
|
|
sentryStatus = await switchSentry(false);
|
|
|
|
sinon.stub(process, 'exit');
|
|
|
|
|
|
|
|
await testDockerBuildStream({
|
2021-12-18 23:27:59 +00:00
|
|
|
commandLine: `deploy testApp --build --source ${projectPath} --noconvert-eol`,
|
2020-06-20 22:05:59 +00:00
|
|
|
dockerMock: docker,
|
|
|
|
expectedFilesByService: { main: expectedFiles },
|
|
|
|
expectedQueryParamsByService: { main: commonQueryParams },
|
|
|
|
expectedErrorLines,
|
|
|
|
expectedExitCode,
|
|
|
|
expectedResponseLines,
|
|
|
|
projectPath,
|
|
|
|
responseBody,
|
|
|
|
responseCode: 200,
|
|
|
|
services: ['main'],
|
|
|
|
});
|
|
|
|
} finally {
|
|
|
|
await switchSentry(sentryStatus);
|
2021-07-20 13:57:00 +00:00
|
|
|
// @ts-expect-error
|
2020-06-20 22:05:59 +00:00
|
|
|
process.exit.restore();
|
|
|
|
}
|
2020-01-15 19:41:47 +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 service1Dockerfile = (
|
|
|
|
await fs.readFile(
|
|
|
|
path.join(projectPath, 'service1', 'Dockerfile.template'),
|
|
|
|
'utf8',
|
|
|
|
)
|
|
|
|
).replace('%%BALENA_MACHINE_NAME%%', 'raspberrypi3');
|
|
|
|
|
|
|
|
console.error(
|
|
|
|
`Dockerfile.template (replaced) length=${service1Dockerfile.length}`,
|
|
|
|
);
|
|
|
|
console.error(service1Dockerfile);
|
|
|
|
|
|
|
|
const expectedFilesByService: ExpectedTarStreamFilesByService = {
|
|
|
|
service1: {
|
|
|
|
Dockerfile: {
|
|
|
|
contents: service1Dockerfile,
|
|
|
|
fileSize: service1Dockerfile.length,
|
|
|
|
type: 'file',
|
|
|
|
},
|
|
|
|
'Dockerfile.template': { fileSize: 144, type: 'file' },
|
|
|
|
'file1.sh': { fileSize: 12, type: 'file' },
|
|
|
|
'test-ignore.txt': { fileSize: 12, type: 'file' },
|
|
|
|
},
|
|
|
|
service2: {
|
|
|
|
'.dockerignore': { fileSize: 12, type: 'file' },
|
2021-07-28 13:19:57 +00:00
|
|
|
'Dockerfile-alt': { fileSize: 13, type: 'file' },
|
2020-06-24 23:01:53 +00:00
|
|
|
'file2-crlf.sh': {
|
|
|
|
fileSize: isWindows ? 12 : 14,
|
|
|
|
testStream: isWindows ? expectStreamNoCRLF : undefined,
|
|
|
|
type: 'file',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
const responseFilename = 'build-POST.json';
|
|
|
|
const responseBody = await fs.readFile(
|
|
|
|
path.join(dockerResponsePath, responseFilename),
|
|
|
|
'utf8',
|
|
|
|
);
|
|
|
|
const expectedQueryParamsByService = {
|
2020-10-19 23:00:53 +00:00
|
|
|
service1: Object.entries(
|
|
|
|
_.merge({}, commonComposeQueryParams, {
|
|
|
|
buildargs: { SERVICE1_VAR: 'This is a service specific variable' },
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
service2: Object.entries(
|
2021-07-28 13:19:57 +00:00
|
|
|
_.merge({}, commonComposeQueryParamsArmV7, {
|
2020-10-19 23:00:53 +00:00
|
|
|
buildargs: {
|
|
|
|
COMPOSE_ARG: 'an argument defined in the docker-compose.yml file',
|
|
|
|
},
|
|
|
|
dockerfile: 'Dockerfile-alt',
|
|
|
|
}),
|
|
|
|
),
|
2020-06-24 23:01:53 +00:00
|
|
|
};
|
|
|
|
const expectedResponseLines: string[] = [
|
|
|
|
...commonResponseLines[responseFilename],
|
|
|
|
...[
|
|
|
|
'[Build] service1 Step 1/4 : FROM busybox',
|
|
|
|
'[Build] service2 Step 1/4 : FROM busybox',
|
|
|
|
],
|
2021-11-22 01:14:56 +00:00
|
|
|
...getDockerignoreWarn3('deploy'),
|
2020-06-24 23:01:53 +00:00
|
|
|
];
|
|
|
|
if (isWindows) {
|
|
|
|
expectedResponseLines.push(
|
|
|
|
`[Info] Converting line endings CRLF -> LF for file: ${path.join(
|
|
|
|
projectPath,
|
|
|
|
'service2',
|
|
|
|
'file2-crlf.sh',
|
|
|
|
)}`,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-05-19 22:12:49 +00:00
|
|
|
api.expectPostRelease({});
|
2020-06-24 23:01:53 +00:00
|
|
|
api.expectPatchImage({});
|
|
|
|
api.expectPatchRelease({});
|
2021-07-28 13:19:57 +00:00
|
|
|
docker.expectGetManifestRpi3Alpine();
|
|
|
|
docker.expectGetManifestBusybox();
|
2020-06-24 23:01:53 +00:00
|
|
|
|
|
|
|
await testDockerBuildStream({
|
|
|
|
commandLine: `deploy testApp --build --source ${projectPath} --multi-dockerignore`,
|
|
|
|
dockerMock: docker,
|
|
|
|
expectedFilesByService,
|
|
|
|
expectedQueryParamsByService,
|
|
|
|
expectedResponseLines,
|
|
|
|
projectPath,
|
|
|
|
responseBody,
|
|
|
|
responseCode: 200,
|
|
|
|
services: ['service1', 'service2'],
|
|
|
|
});
|
|
|
|
});
|
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 deploy: project validation', function () {
|
2020-06-15 22:53:01 +00:00
|
|
|
let api: BalenaAPIMock;
|
2020-06-20 22:05:59 +00:00
|
|
|
|
2020-06-15 22:53:01 +00:00
|
|
|
this.beforeEach(() => {
|
|
|
|
api = new BalenaAPIMock();
|
|
|
|
api.expectGetWhoAmI({ optional: true, persist: true });
|
2020-06-15 22:53:04 +00:00
|
|
|
api.expectGetMixpanel({ optional: true });
|
2020-06-15 22:53:01 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
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 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(
|
|
|
|
`deploy 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;
|
|
|
|
});
|
|
|
|
});
|