-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathECR.test.js
More file actions
118 lines (101 loc) · 3.18 KB
/
ECR.test.js
File metadata and controls
118 lines (101 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
const Test = require('thunk-test')
const assert = require('assert')
const ECR = require('./ECR')
const AwsCredentials = require('./AwsCredentials')
const Docker = require('./Docker')
const test = new Test('ECR', async function integration() {
const awsCreds = await AwsCredentials('presidium')
awsCreds.region = 'us-east-1'
const awsAccountId = '141814482060'
const ecr = new ECR({ ...awsCreds })
await ecr.deleteRepository('test-repo/p1', { force: true }).catch(() => {})
{
const response = await ecr.createRepository('test-repo/p1', {
tags: [{ Key: 'a', Value: '1' }],
imageTagMutability: 'IMMUTABLE',
imageScanningConfiguration: {
scanOnPush: true
},
encryptionConfiguration: {
encryptionType: 'AES256',
}
})
assert.equal(response.repository.repositoryName, 'test-repo/p1')
assert.equal(response.repository.imageTagMutability, 'IMMUTABLE')
assert.equal(response.repository.imageScanningConfiguration.scanOnPush, true)
assert.equal(response.repository.encryptionConfiguration.encryptionType, 'AES256')
}
const authorizationToken = await ecr.getAuthorizationToken()
assert.equal(typeof authorizationToken, 'string')
const docker = new Docker({ apiVersion: '1.44' })
{ // pull node-15:alpine
const dataStream = await docker.pullImage('node:15-alpine')
dataStream.pipe(process.stdout)
await new Promise(resolve => dataStream.on('end', resolve))
}
{
const dataStream = await docker.buildImage(__dirname, {
image: 'test-repo/p1:test',
archive: {
Dockerfile: `
FROM node:15-alpine
WORKDIR /opt
COPY . .
EXPOSE 8888`,
},
})
dataStream.pipe(process.stdout)
await new Promise(resolve => {
dataStream.on('end', resolve)
})
dataStream.on('data', chunk => {
const line = chunk.toString('utf8')
if (line.startsWith('{"error')) {
throw new Error(line)
}
})
}
{
const data = await docker.tagImage(
'test-repo/p1:test',
`${awsAccountId}.dkr.ecr.${awsCreds.region}.amazonaws.com/test-repo/p1:test`,
)
assert.equal(Object.keys(data).length, 0)
}
{
const dataStream = await docker.pushImage({
image: 'test-repo/p1:test',
registry: `${awsAccountId}.dkr.ecr.${awsCreds.region}.amazonaws.com`,
authToken: authorizationToken,
})
dataStream.pipe(process.stdout)
await new Promise(resolve => {
dataStream.on('end', resolve)
})
dataStream.on('data', chunk => {
const line = chunk.toString('utf8')
if (line.startsWith('{"error')) {
throw new Error(line)
}
})
}
{
await assert.rejects(
ecr.deleteRepository('test-repo/p1'),
error => {
assert.equal(error.name, 'RepositoryNotEmptyException')
assert(error.message.includes('cannot be deleted because it still contains images'))
return true
}
)
}
{
const response = await ecr.deleteRepository('test-repo/p1', { force: true })
assert.equal(response.repository.repositoryName, 'test-repo/p1')
assert.equal(response.repository.imageTagMutability, 'IMMUTABLE')
}
}).case()
if (process.argv[1] == __filename) {
test()
}
module.exports = test