Skip to content

Commit 95279de

Browse files
authored
Containers: improve error messages to users (#95)
- send a message if image could not be built - send a message if image have the wrong architecture
1 parent 0e27f5e commit 95279de

File tree

15 files changed

+92
-67
lines changed

15 files changed

+92
-67
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Changelog
22

3+
## 0.4.1
4+
5+
### Added
6+
7+
- clearer error messages when building a container with a different architecture than expected `amd64` [#95](https://github.com/scaleway/serverless-scaleway-functions/pull/95)
8+
9+
### Fixed
10+
11+
- fix tests [#96](https://github.com/scaleway/serverless-scaleway-functions/pull/96)
12+
313
## 0.4.0
414
### Added
515
- `serverless info` command to work with serverless compose

deploy/lib/buildAndPushContainers.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
'use strict';
2+
3+
const Docker = require('dockerode');
4+
const tar = require('tar-fs');
5+
6+
const docker = new Docker();
7+
8+
const promisifyStream = (stream, verbose) => new Promise((resolve, reject) => {
9+
stream.on('data', (data) => {
10+
if (verbose) {
11+
console.log(data.toString().replace('\n', ''));
12+
}
13+
});
14+
stream.on('end', resolve);
15+
stream.on('error', reject);
16+
});
17+
18+
module.exports = {
19+
buildAndPushContainers() {
20+
const auth = {
21+
username: 'any',
22+
password: this.provider.scwToken,
23+
};
24+
25+
const containerNames = Object.keys(this.containers);
26+
const promises = containerNames.map((containerName) => {
27+
const container = this.containers[containerName];
28+
const tarStream = tar.pack(`./${container.directory}`);
29+
const imageName = `${this.namespace.registry_endpoint}/${container.name}:latest`;
30+
31+
this.serverless.cli.log(`Building and pushing container ${container.name} to: ${imageName} ...`);
32+
33+
return new Promise(async (resolve, reject) => {
34+
const buildStream = await docker.buildImage(tarStream, { t: imageName })
35+
await promisifyStream(buildStream, this.provider.options.verbose);
36+
37+
const image = docker.getImage(imageName)
38+
39+
const inspectedImage = await image.inspect()
40+
.catch(() => reject("Error during build of the image "+imageName+": run --verbose to see the error"));
41+
42+
if (inspectedImage === undefined) {
43+
return
44+
}
45+
46+
if (inspectedImage['Architecture'] !== 'amd64') {
47+
reject("It appears that image have been built with " + inspectedImage['Architecture'] + " architecture. " +
48+
"To build a compatible image with Scaleway serverless containers, " +
49+
"the platform of the built image must be `linux/amd64`. " +
50+
"Please pull your image's base image with platform `linux/amd64`: " +
51+
"first (`docker pull --platform=linux/amd64 <your_base_image>`), " +
52+
"and just after, run `serverless deploy`. You shouldn't pull the other " +
53+
"image architecture between those two steps.")
54+
return
55+
}
56+
57+
const pushStream = await image.push(auth);
58+
await promisifyStream(pushStream, this.provider.options.verbose);
59+
60+
resolve();
61+
});
62+
});
63+
64+
return Promise.all(promises);
65+
},
66+
67+
};

deploy/lib/pushContainers.js

Lines changed: 0 additions & 52 deletions
This file was deleted.

deploy/scalewayDeploy.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const setUpDeployment = require('../shared/setUpDeployment');
44
const createNamespace = require('./lib/createNamespace');
55
const createFunctions = require('./lib/createFunctions');
66
const createContainers = require('./lib/createContainers');
7-
const pushContainers = require('./lib/pushContainers');
7+
const buildAndPushContainers = require('./lib/buildAndPushContainers');
88
const uploadCode = require('./lib/uploadCode');
99
const deployFunctions = require('./lib/deployFunctions');
1010
const deployContainers = require('./lib/deployContainers');
@@ -28,7 +28,7 @@ class ScalewayDeploy {
2828
createNamespace,
2929
createFunctions,
3030
createContainers,
31-
pushContainers,
31+
buildAndPushContainers,
3232
uploadCode,
3333
deployFunctions,
3434
deployContainers,
@@ -42,7 +42,7 @@ class ScalewayDeploy {
4242
&& this.provider.serverless.service.custom.containers
4343
&& Object.keys(this.provider.serverless.service.custom.containers).length !== 0) {
4444
return this.createContainers()
45-
.then(this.pushContainers)
45+
.then(this.buildAndPushContainers)
4646
.then(this.deployContainers);
4747
}
4848
return undefined;

examples/container-schedule/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"license": "ISC",
1111
"dependencies": {},
1212
"devDependencies": {
13-
"serverless-scaleway-functions": "^0.4.0"
13+
"serverless-scaleway-functions": "^0.4.1"
1414
},
1515
"description": ""
1616
}

examples/container/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"license": "ISC",
1111
"dependencies": {},
1212
"devDependencies": {
13-
"serverless-scaleway-functions": "^0.4.0"
13+
"serverless-scaleway-functions": "^0.4.1"
1414
},
1515
"description": ""
1616
}

examples/go/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"license": "ISC",
1010
"dependencies": {},
1111
"devDependencies": {
12-
"serverless-scaleway-functions": "^0.4.0"
12+
"serverless-scaleway-functions": "^0.4.1"
1313
},
1414
"description": ""
1515
}

examples/go113/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"license": "ISC",
1010
"dependencies": {},
1111
"devDependencies": {
12-
"serverless-scaleway-functions": "^0.4.0"
12+
"serverless-scaleway-functions": "^0.4.1"
1313
},
1414
"description": ""
1515
}

examples/multiple/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"license": "ISC",
1111
"dependencies": {},
1212
"devDependencies": {
13-
"serverless-scaleway-functions": "^0.4.0"
13+
"serverless-scaleway-functions": "^0.4.1"
1414
},
1515
"description": ""
1616
}

examples/nodejs-es-modules/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"license": "ISC",
1212
"dependencies": {},
1313
"devDependencies": {
14-
"serverless-scaleway-functions": "^0.4.0"
14+
"serverless-scaleway-functions": "^0.4.1"
1515
},
1616
"description": ""
1717
}

examples/nodejs-schedule/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"license": "ISC",
1111
"dependencies": {},
1212
"devDependencies": {
13-
"serverless-scaleway-functions": "^0.4.0"
13+
"serverless-scaleway-functions": "^0.4.1"
1414
},
1515
"description": ""
1616
}

examples/nodejs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"license": "ISC",
1111
"dependencies": {},
1212
"devDependencies": {
13-
"serverless-scaleway-functions": "^0.4.0"
13+
"serverless-scaleway-functions": "^0.4.1"
1414
},
1515
"description": ""
1616
}

examples/python3/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"license": "ISC",
1111
"dependencies": {},
1212
"devDependencies": {
13-
"serverless-scaleway-functions": "^0.4.0"
13+
"serverless-scaleway-functions": "^0.4.1"
1414
},
1515
"description": ""
1616
}

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "serverless-scaleway-functions",
3-
"version": "0.4.0",
3+
"version": "0.4.1",
44
"description": "Provider plugin for the Serverless Framework v1.x which adds support for Scaleway Functions.",
55
"main": "index.js",
66
"author": "scaleway.com",

0 commit comments

Comments
 (0)