From c9cfa54d049cc6ca59b0257747ba8d4ce828f007 Mon Sep 17 00:00:00 2001 From: thomas-tacquet Date: Fri, 23 Sep 2022 12:08:16 +0200 Subject: [PATCH 1/3] container registry image was not updated, this caused sync problems between console and serverless framework image --- deploy/lib/createContainers.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/deploy/lib/createContainers.js b/deploy/lib/createContainers.js index add785d9..5e21218e 100644 --- a/deploy/lib/createContainers.js +++ b/deploy/lib/createContainers.js @@ -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, @@ -126,6 +127,6 @@ module.exports = { this.applyDomainsContainer(foundContainer.id, container.custom_domains); return this.updateContainer(foundContainer.id, params) - .then(response => Object.assign(response, { directory: container.directory })); + .then((response) => Object.assign(response, { directory: container.directory })); }, }; From b32e2a1aaba5e96aa789e5eef49617e01d505ef9 Mon Sep 17 00:00:00 2001 From: thomas-tacquet Date: Mon, 26 Sep 2022 14:29:54 +0200 Subject: [PATCH 2/3] review --- deploy/lib/createContainers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deploy/lib/createContainers.js b/deploy/lib/createContainers.js index 5e21218e..5f7b2110 100644 --- a/deploy/lib/createContainers.js +++ b/deploy/lib/createContainers.js @@ -127,6 +127,6 @@ module.exports = { this.applyDomainsContainer(foundContainer.id, container.custom_domains); return this.updateContainer(foundContainer.id, params) - .then((response) => Object.assign(response, { directory: container.directory })); + .then(response => Object.assign(response, { directory: container.directory })); }, }; From 78dd0f70478a0ad1458c5828cf8e22f6fc95ad06 Mon Sep 17 00:00:00 2001 From: thomas-tacquet Date: Mon, 26 Sep 2022 16:04:15 +0200 Subject: [PATCH 3/3] =?UTF-8?q?tests=20for=20registry=20image=20fix=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/containers/containers.test.js | 59 +++++++++++++++++++ .../containers_private_registry.test.js | 2 +- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/tests/containers/containers.test.js b/tests/containers/containers.test.js index 76eb5ef2..f603dd32 100644 --- a/tests/containers/containers.test.js +++ b/tests/containers/containers.test.js @@ -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'); @@ -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); diff --git a/tests/containers/containers_private_registry.test.js b/tests/containers/containers_private_registry.test.js index ea176bc3..6b268b98 100644 --- a/tests/containers/containers_private_registry.test.js +++ b/tests/containers/containers_private_registry.test.js @@ -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 !"}'); });