Skip to content

Commit

Permalink
Add multiarch support
Browse files Browse the repository at this point in the history
Bump version of balena-multibuild to the one that supports multiarch
Remove previous hack to avoid sending platform information to multibuild

Change-type: minor
Signed-off-by: Paul Jonathan <[email protected]>
See: #1508
  • Loading branch information
toochevere authored and pdcastro committed Sep 17, 2021
1 parent 88fc3f7 commit 9eeef83
Show file tree
Hide file tree
Showing 13 changed files with 212 additions and 32 deletions.
3 changes: 0 additions & 3 deletions lib/utils/compose_ts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1051,9 +1051,6 @@ export async function makeBuildTasks(
infoStr = `build [${task.context}]`;
}
logger.logDebug(` ${task.serviceName}: ${infoStr}`);
// Workaround for Docker v20.10 + single-arch base images. See:
// https://www.flowdock.com/app/rulemotion/i-cli/threads/RuSu1KiWOn62xaGy7O2sn8m8BUc
task.dockerPlatform = 'none';
});

logger.logDebug(
Expand Down
35 changes: 26 additions & 9 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"test:standalone": "npm run build:standalone && npm run test:standalone:fast",
"test:standalone:fast": "cross-env BALENA_CLI_TEST_TYPE=standalone mocha --config .mocharc-standalone.js",
"test:fast": "npm run build:fast && npm run test:source",
"test:debug": "cross-env BALENA_CLI_TEST_TYPE=source mocha --inspect-brk=0.0.0.0",
"test:only": "npm run build:fast && cross-env BALENA_CLI_TEST_TYPE=source mocha \"tests/**/${npm_config_test}.spec.ts\"",
"catch-uncommitted": "ts-node --transpile-only automation/run.ts catch-uncommitted",
"ci": "npm run test && npm run catch-uncommitted",
Expand Down Expand Up @@ -267,7 +268,7 @@
"resin-cli-visuals": "^1.8.0",
"resin-compose-parse": "^2.1.3",
"resin-doodles": "^0.1.1",
"resin-multibuild": "^4.11.0",
"resin-multibuild": "^4.12.1",
"resin-stream-logger": "^0.1.2",
"rimraf": "^3.0.2",
"semver": "^7.3.2",
Expand Down
54 changes: 43 additions & 11 deletions tests/commands/build.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ const commonQueryParams = {
labels: '',
};

const commonQueryParamsIntel = {
...commonQueryParams,
platform: 'linux/amd64',
};

const commonQueryParamsArmV6 = {
...commonQueryParams,
platform: 'linux/arm/v6',
};

const commonComposeQueryParams = {
t: '${tag}',
buildargs: {
Expand All @@ -62,6 +72,11 @@ const commonComposeQueryParams = {
labels: '',
};

const commonComposeQueryParamsIntel = {
...commonComposeQueryParams,
platform: 'linux/amd64',
};

// "itSS" means "it() Skip Standalone"
const itSS = process.env.BALENA_CLI_TEST_TYPE === 'standalone' ? it.skip : it;

Expand All @@ -76,7 +91,7 @@ describe('balena build', function () {
api.expectGetWhoAmI({ optional: true, persist: true });
api.expectGetMixpanel({ optional: true });
docker.expectGetPing();
docker.expectGetVersion();
docker.expectGetVersion({ persist: true });
});

this.afterEach(() => {
Expand Down Expand Up @@ -123,13 +138,16 @@ describe('balena build', function () {
}
}
docker.expectGetInfo({});
docker.expectGetManifestBusybox();
await testDockerBuildStream({
commandLine: `build ${projectPath} --deviceType nuc --arch amd64 ${
isV13() ? '' : '-g'
}`,
dockerMock: docker,
expectedFilesByService: { main: expectedFiles },
expectedQueryParamsByService: { main: Object.entries(commonQueryParams) },
expectedQueryParamsByService: {
main: Object.entries(commonQueryParamsIntel),
},
expectedResponseLines,
projectPath,
responseBody,
Expand All @@ -152,7 +170,7 @@ describe('balena build', function () {
'Dockerfile-alt': { fileSize: 30, type: 'file' },
};
const expectedQueryParams = {
...commonQueryParams,
...commonQueryParamsIntel,
buildargs: '{"BARG1":"b1","barg2":"B2"}',
cachefrom: '["my/img1","my/img2"]',
};
Expand Down Expand Up @@ -181,6 +199,7 @@ describe('balena build', function () {
}
}
docker.expectGetInfo({});
docker.expectGetManifestBusybox();
await testDockerBuildStream({
commandLine: `build ${projectPath} --deviceType nuc --arch amd64 -B BARG1=b1 -B barg2=B2 --cache-from my/img1,my/img2`,
dockerMock: docker,
Expand Down Expand Up @@ -271,14 +290,15 @@ describe('balena build', function () {
});
mock.reRequire('../../build/utils/qemu');
docker.expectGetInfo({ OperatingSystem: 'balenaOS 2.44.0+rev1' });
docker.expectGetManifestBusybox();
await testDockerBuildStream({
commandLine: `build ${projectPath} --emulated --deviceType ${deviceType} --arch ${arch} ${
isV13() ? '' : '--nogitignore'
}`,
dockerMock: docker,
expectedFilesByService: { main: expectedFiles },
expectedQueryParamsByService: {
main: Object.entries(commonQueryParams),
main: Object.entries(commonQueryParamsArmV6),
},
expectedResponseLines,
projectPath,
Expand Down Expand Up @@ -327,11 +347,15 @@ describe('balena build', function () {
);
}
docker.expectGetInfo({});
docker.expectGetManifestBusybox();

await testDockerBuildStream({
commandLine: `build ${projectPath} --deviceType nuc --arch amd64 --noconvert-eol -m`,
dockerMock: docker,
expectedFilesByService: { main: expectedFiles },
expectedQueryParamsByService: { main: Object.entries(commonQueryParams) },
expectedQueryParamsByService: {
main: Object.entries(commonQueryParamsIntel),
},
expectedResponseLines,
projectPath,
responseBody,
Expand Down Expand Up @@ -360,7 +384,7 @@ describe('balena build', function () {
},
service2: {
'.dockerignore': { fileSize: 12, type: 'file' },
'Dockerfile-alt': { fileSize: 40, type: 'file' },
'Dockerfile-alt': { fileSize: 13, type: 'file' },
'file2-crlf.sh': {
fileSize: isWindows ? 12 : 14,
testStream: isWindows ? expectStreamNoCRLF : undefined,
Expand All @@ -386,7 +410,7 @@ describe('balena build', function () {
}),
),
service2: Object.entries(
_.merge({}, commonComposeQueryParams, {
_.merge({}, commonComposeQueryParamsIntel, {
buildargs: {
COMPOSE_ARG: 'A',
barg: 'b',
Expand Down Expand Up @@ -417,6 +441,8 @@ describe('balena build', function () {
);
}
docker.expectGetInfo({});
docker.expectGetManifestNucAlpine();
docker.expectGetManifestBusybox();
await testDockerBuildStream({
commandLine: `build ${projectPath} --deviceType nuc --arch amd64 --convert-eol ${
isV13() ? '' : '-G'
Expand Down Expand Up @@ -453,7 +479,7 @@ describe('balena build', function () {
},
service2: {
'.dockerignore': { fileSize: 12, type: 'file' },
'Dockerfile-alt': { fileSize: 40, type: 'file' },
'Dockerfile-alt': { fileSize: 13, type: 'file' },
'file2-crlf.sh': {
fileSize: isWindows ? 12 : 14,
testStream: isWindows ? expectStreamNoCRLF : undefined,
Expand All @@ -473,7 +499,7 @@ describe('balena build', function () {
}),
),
service2: Object.entries(
_.merge({}, commonComposeQueryParams, {
_.merge({}, commonComposeQueryParamsIntel, {
buildargs: {
COMPOSE_ARG: 'an argument defined in the docker-compose.yml file',
},
Expand Down Expand Up @@ -505,6 +531,9 @@ describe('balena build', function () {
);
}
docker.expectGetInfo({});
docker.expectGetManifestBusybox();
docker.expectGetManifestNucAlpine();

await testDockerBuildStream({
commandLine: `build ${projectPath} --deviceType nuc --arch amd64 --convert-eol -m`,
dockerMock: docker,
Expand Down Expand Up @@ -539,7 +568,7 @@ describe('balena build', function () {
},
service2: {
'.dockerignore': { fileSize: 12, type: 'file' },
'Dockerfile-alt': { fileSize: 40, type: 'file' },
'Dockerfile-alt': { fileSize: 13, type: 'file' },
'file2-crlf.sh': {
fileSize: isWindows ? 12 : 14,
testStream: isWindows ? expectStreamNoCRLF : undefined,
Expand All @@ -559,7 +588,7 @@ describe('balena build', function () {
}),
),
service2: Object.entries(
_.merge({}, commonComposeQueryParams, {
_.merge({}, commonComposeQueryParamsIntel, {
buildargs: {
COMPOSE_ARG: 'an argument defined in the docker-compose.yml file',
},
Expand Down Expand Up @@ -593,6 +622,9 @@ describe('balena build', function () {
const projectName = 'spectest';
const tag = 'myTag';
docker.expectGetInfo({});
docker.expectGetManifestBusybox();
docker.expectGetManifestNucAlpine();

await testDockerBuildStream({
commandLine: `build ${projectPath} --deviceType nuc --arch amd64 --convert-eol -m --tag ${tag} --projectName ${projectName}`,
dockerMock: docker,
Expand Down
16 changes: 14 additions & 2 deletions tests/commands/deploy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const commonResponseLines = {
};

const commonQueryParams = [
['platform', 'linux/arm/v7'],
['t', '${tag}'],
['buildargs', '{}'],
['labels', ''],
Expand All @@ -67,6 +68,11 @@ const commonComposeQueryParams = {
labels: '',
};

const commonComposeQueryParamsArmV7 = {
...commonComposeQueryParams,
platform: 'linux/arm/v7',
};

describe('balena deploy', function () {
let api: BalenaAPIMock;
let docker: DockerMock;
Expand Down Expand Up @@ -139,6 +145,7 @@ describe('balena deploy', function () {
api.expectPatchImage({});
api.expectPatchRelease({});
api.expectPostImageLabel();
docker.expectGetManifestBusybox();

await testDockerBuildStream({
commandLine: `deploy testApp --build --source ${projectPath} ${
Expand Down Expand Up @@ -189,6 +196,7 @@ describe('balena deploy', function () {
api.expectPatchImage({});
api.expectPatchRelease({});
api.expectPostImageLabel();
docker.expectGetManifestBusybox();

await testDockerBuildStream({
commandLine: `deploy testApp --build --source ${projectPath}`,
Expand Down Expand Up @@ -238,6 +246,7 @@ describe('balena deploy', function () {
api.expectPatchImage({});
api.expectPatchRelease({});
api.expectPostImageLabel();
docker.expectGetManifestBusybox();

await testDockerBuildStream({
commandLine: `deploy testApp --build --draft --source ${projectPath}`,
Expand Down Expand Up @@ -275,6 +284,7 @@ describe('balena deploy', function () {
const expectedExitCode = 1;

api.expectPostRelease({});
docker.expectGetManifestBusybox();

// Mock this patch HTTP request to return status code 500, in which case
// the release status should be saved as "failed" rather than "success"
Expand Down Expand Up @@ -352,7 +362,7 @@ describe('balena deploy', function () {
},
service2: {
'.dockerignore': { fileSize: 12, type: 'file' },
'Dockerfile-alt': { fileSize: 40, type: 'file' },
'Dockerfile-alt': { fileSize: 13, type: 'file' },
'file2-crlf.sh': {
fileSize: isWindows ? 12 : 14,
testStream: isWindows ? expectStreamNoCRLF : undefined,
Expand All @@ -372,7 +382,7 @@ describe('balena deploy', function () {
}),
),
service2: Object.entries(
_.merge({}, commonComposeQueryParams, {
_.merge({}, commonComposeQueryParamsArmV7, {
buildargs: {
COMPOSE_ARG: 'an argument defined in the docker-compose.yml file',
},
Expand Down Expand Up @@ -407,6 +417,8 @@ describe('balena deploy', function () {
api.expectPostRelease({});
api.expectPatchImage({});
api.expectPatchRelease({});
docker.expectGetManifestRpi3Alpine();
docker.expectGetManifestBusybox();

await testDockerBuildStream({
commandLine: `deploy testApp --build --source ${projectPath} --multi-dockerignore`,
Expand Down
4 changes: 2 additions & 2 deletions tests/commands/push.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ describe('balena push', function () {
'docker-compose.yml': { fileSize: 332, type: 'file' },
'service1/Dockerfile.template': { fileSize: 144, type: 'file' },
'service1/file1.sh': { fileSize: 12, type: 'file' },
'service2/Dockerfile-alt': { fileSize: 40, type: 'file' },
'service2/Dockerfile-alt': { fileSize: 13, type: 'file' },
'service2/.dockerignore': { fileSize: 12, type: 'file' },
'service2/file2-crlf.sh': {
fileSize: isWindows ? 12 : 14,
Expand Down Expand Up @@ -508,7 +508,7 @@ describe('balena push', function () {
'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/Dockerfile-alt': { fileSize: 13, type: 'file' },
'service2/.dockerignore': { fileSize: 12, type: 'file' },
'service2/file2-crlf.sh': {
fileSize: isWindows ? 12 : 14,
Expand Down
2 changes: 1 addition & 1 deletion tests/docker-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export async function testDockerBuildStream(o: {
tag,
});
if (o.commandLine.startsWith('build')) {
o.dockerMock.expectGetImages();
o.dockerMock.expectGetImages({ optional: true });
}
}

Expand Down
Loading

0 comments on commit 9eeef83

Please sign in to comment.