diff --git a/deploy/lib/createContainers.js b/deploy/lib/createContainers.js index add785d9..5f7b2110 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, 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 !"}'); });