-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DSO-2697 - Update runtime and dependencies (#37)
* update * test * fix test * prettier * add parser option * Update deploy.sh * Update handler.js * update * Update serverless.yml * Update serverless.yml * update serverless * Update serverless.yml * Update serverless.yml * Update serverless.yml * Delete .env * Update serverless.yml * Update serverless.yml * update region * revert * cleanup * delete unneeded files
- Loading branch information
Showing
9 changed files
with
6,883 additions
and
4,365 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,5 +3,8 @@ | |
"node": true, | ||
"es6": true, | ||
"mocha": true | ||
}, | ||
"parserOptions": { | ||
"ecmaVersion": 2020 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ on: | |
- push | ||
|
||
env: | ||
NODE_VERSION: 10.x | ||
NODE_VERSION: 18.x | ||
|
||
jobs: | ||
build_and_test: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,116 +1,109 @@ | ||
const assert = require("assert"); | ||
const { | ||
BatchDeleteImageCommand, | ||
DescribeImagesCommand, | ||
ECRClient, | ||
} = require("@aws-sdk/client-ecr"); | ||
const moment = require("moment"); | ||
const proxyquire = require("proxyquire"); | ||
const sinon = require("sinon"); | ||
const { mockClient } = require("aws-sdk-client-mock"); | ||
const { cleanupImages } = require("./handler"); | ||
const { expect } = require("expect"); | ||
globalThis.expect = expect; | ||
require("aws-sdk-client-mock-jest"); | ||
|
||
const deletePromise = { | ||
promise: () => | ||
Promise.resolve({ | ||
imageIds: [ | ||
{ | ||
imageDigest: "3797470f-bb69-11e6-90e4-19b39eb619f7", | ||
imageTag: "some-tag", | ||
}, | ||
], | ||
failures: [], | ||
}), | ||
imageIds: [ | ||
{ | ||
imageDigest: "3797470f-bb69-11e6-90e4-19b39eb619f7", | ||
imageTag: "some-tag", | ||
}, | ||
], | ||
failures: [], | ||
}; | ||
|
||
const desribeImagesPromise = { | ||
promise: () => | ||
Promise.resolve({ | ||
nextToken: null, | ||
imageDetails: [ | ||
{ | ||
registryId: "384553929753", | ||
repositoryName: "test-repo", | ||
imageDigest: "1", | ||
imageTags: ["1.0.0-master", "ignore-this"], | ||
imageSizeInBytes: "1024", | ||
imagePushedAt: moment(), | ||
}, | ||
{ | ||
registryId: "384553929753", | ||
repositoryName: "test-repo", | ||
imageDigest: "2", | ||
imageTags: ["1.0.0-master", "ignore-this"], | ||
imageSizeInBytes: "1024", | ||
imagePushedAt: moment().add(-31, "days"), | ||
}, | ||
{ | ||
registryId: "384553929753", | ||
repositoryName: "test-repo", | ||
imageDigest: "3", | ||
imageTags: ["1.0.0-other", "ignore-this"], | ||
imageSizeInBytes: "1024", | ||
imagePushedAt: moment(), | ||
}, | ||
{ | ||
registryId: "384553929753", | ||
repositoryName: "test-repo", | ||
imageDigest: "4", | ||
imageTags: ["1.0.0-other", "dont-ignore-this"], | ||
imageSizeInBytes: "1024", | ||
imagePushedAt: moment().add(-31, "days"), | ||
}, | ||
{ | ||
registryId: "384553929753", | ||
repositoryName: "test-repo", | ||
imageDigest: "5", | ||
imageTags: ["1.0.0-main", "ignore-this"], | ||
imageSizeInBytes: "1024", | ||
imagePushedAt: moment().add(-31, "days"), | ||
}, | ||
], | ||
}), | ||
}; | ||
|
||
const sandbox = sinon.sandbox.create(); | ||
const deleteStub = sandbox.stub(); | ||
const describeImagesStub = sandbox.stub().returns(desribeImagesPromise); | ||
const mocks = { | ||
"aws-sdk": { | ||
ECR: function () { | ||
// eslint-disable-line | ||
this.batchDeleteImage = deleteStub; | ||
this.describeImages = describeImagesStub; | ||
nextToken: null, | ||
imageDetails: [ | ||
{ | ||
registryId: "384553929753", | ||
repositoryName: "test-repo", | ||
imageDigest: "1", | ||
imageTags: ["1.0.0-master", "ignore-this"], | ||
imageSizeInBytes: "1024", | ||
imagePushedAt: moment(), | ||
}, | ||
{ | ||
registryId: "384553929753", | ||
repositoryName: "test-repo", | ||
imageDigest: "2", | ||
imageTags: ["1.0.0-master", "ignore-this"], | ||
imageSizeInBytes: "1024", | ||
imagePushedAt: moment().add(-31, "days"), | ||
}, | ||
{ | ||
registryId: "384553929753", | ||
repositoryName: "test-repo", | ||
imageDigest: "3", | ||
imageTags: ["1.0.0-other", "ignore-this"], | ||
imageSizeInBytes: "1024", | ||
imagePushedAt: moment(), | ||
}, | ||
{ | ||
registryId: "384553929753", | ||
repositoryName: "test-repo", | ||
imageDigest: "4", | ||
imageTags: ["1.0.0-other", "dont-ignore-this"], | ||
imageSizeInBytes: "1024", | ||
imagePushedAt: moment().add(-31, "days"), | ||
}, | ||
{ | ||
registryId: "384553929753", | ||
repositoryName: "test-repo", | ||
imageDigest: "5", | ||
imageTags: ["1.0.0-main", "ignore-this"], | ||
imageSizeInBytes: "1024", | ||
imagePushedAt: moment().add(-31, "days"), | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
describe("cleanupImages", () => { | ||
const cleanup = proxyquire("./handler.js", mocks); | ||
const ecrMock = mockClient(ECRClient); | ||
|
||
function callback() {} | ||
|
||
describe("cleanupImages", () => { | ||
beforeEach(() => { | ||
ecrMock.reset(); | ||
process.env.DRY_RUN = "true"; | ||
process.env.REPO_NAMES = "test-repo"; | ||
process.env.AWS_ACCOUNT_ID = "1234567890"; | ||
|
||
sandbox.reset(); | ||
ecrMock | ||
.on(DescribeImagesCommand) | ||
.resolves(desribeImagesPromise) | ||
.on(BatchDeleteImageCommand) | ||
.resolves(deletePromise); | ||
}); | ||
|
||
it.only("Should not remove master images", (done) => { | ||
it("Should not remove master images", async () => { | ||
process.env.DRY_RUN = "false"; | ||
deleteStub.returns(deletePromise); | ||
cleanup.cleanupImages(null, null, () => { | ||
assert(describeImagesStub.called); | ||
assert( | ||
deleteStub.calledWith({ | ||
registryId: "1234567890", | ||
repositoryName: "test-repo", | ||
imageIds: [{ imageDigest: "4" }], | ||
}) | ||
); | ||
done(); | ||
|
||
await cleanupImages(null, null, callback); | ||
|
||
expect(ecrMock).toHaveReceivedCommand(DescribeImagesCommand); | ||
expect(ecrMock).toHaveReceivedCommandWith(BatchDeleteImageCommand, { | ||
registryId: "1234567890", | ||
repositoryName: "test-repo", | ||
imageIds: [{ imageDigest: "4" }], | ||
}); | ||
}); | ||
|
||
it("Should not call delete if dry run", (done) => { | ||
deleteStub.returns(deletePromise); | ||
cleanup.cleanupImages(null, null, () => { | ||
assert(describeImagesStub.called); | ||
assert(deleteStub.notCalled); | ||
done(); | ||
it("Should not call delete if dry run", async () => { | ||
await cleanupImages(null, null, callback); | ||
|
||
expect(ecrMock).toHaveReceivedCommandWith(DescribeImagesCommand, { | ||
maxResults: 100, | ||
registryId: "1234567890", | ||
repositoryName: "test-repo", | ||
}); | ||
expect(ecrMock).toHaveReceivedCommandTimes(BatchDeleteImageCommand, 0); | ||
}); | ||
}); |
Oops, something went wrong.