Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions deploy/lib/createContainers.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ module.exports = {
memory_limit: container.memoryLimit,
min_scale: container.minScale,
max_scale: container.maxScale,
registry_image: `${this.namespace.registry_endpoint}/${container.name}:latest`,
max_concurrency: container.maxConcurrency,
timeout: container.timeout,
privacy: container.privacy,
Expand Down
59 changes: 59 additions & 0 deletions tests/containers/containers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
const path = require('path');
const fs = require('fs');
const { expect } = require('chai');
const Docker = require('dockerode');
const tar = require('tar-fs');

const { getTmpDirPath, replaceTextInFile } = require('../utils/fs');
const { getServiceName, sleep, serverlessDeploy, serverlessRemove} = require('../utils/misc');
Expand Down Expand Up @@ -56,6 +58,63 @@ describe('Service Lifecyle Integration Test', () => {
containerName = namespace.containers[0].name;
});

it('should replace container image with test image', async () => {
// This tests will push a dummy image to the same namespace of the deployed
// container. And then it will modify the image through the API.
// After that we run a serverless deploy to ensure the container image
// is NOT the dummy image.

// build a new image with same path but different name for testing.
const regImg = namespace.containers[0].registry_image;
const contName = namespace.containers[0].name;
const imageName = regImg.replace(contName, 'test-container');

const docker = new Docker();

// used for pushing
const auth = {
username: 'any',
password: scwToken,
};

const regEndpoint = `rg.${scwRegion}.scw.cloud`;
const registryAuth = {};
registryAuth[regEndpoint] = {
username: 'any',
password: scwToken,
};

await docker.checkAuth(registryAuth);

const tarStream = tar.pack(path.join(tmpDir, 'my-container'));

await docker.buildImage(tarStream, { t: imageName, registryconfig: registryAuth });

const image = docker.getImage(imageName);

await image.push(auth);

const params = {
redeploy: false,
registry_image: imageName,
};

// registry lag
await sleep(30000);

await api.updateContainer(namespace.containers[0].id, params);

const nsContainers = await api.listContainers(namespace.id);

expect(nsContainers[0].registry_image).to.be.equal(imageName);

serverlessDeploy();

const nsContainersAfterSlsDeploy = await api.listContainers(namespace.id);

expect(nsContainersAfterSlsDeploy[0].registry_image).to.not.contains('test-container');
});

it('should invoke container from scaleway', async () => {
// TODO query function status instead of having an arbitrary sleep
await sleep(30000);
Expand Down
2 changes: 1 addition & 1 deletion tests/containers/containers_private_registry.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe('Build and deploy on container with a base image private', () => {
// TODO query function status instead of having an arbitrary sleep
await sleep(30000);

let output = execCaptureOutput(serverlessExec, ['invoke', '--function', containerName]);
const output = execCaptureOutput(serverlessExec, ['invoke', '--function', containerName]);
expect(output).to.be.equal('{"message":"Hello, World from Scaleway Container !"}');
});

Expand Down