Skip to content

Commit 439726e

Browse files
Merge pull request #834 from snyk/test/fix-integration-tests
test: replace AWS CLI installation with CircleCI orb
2 parents d11ba62 + fd7f3a2 commit 439726e

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

.circleci/config.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,15 @@ jobs:
3838
image: ubuntu-2004:202010-01
3939
steps:
4040
- checkout
41+
- setup_node16
4142
- install_python_requests
4243
- azure-cli/install
4344
- run:
4445
command: mkdir -p /tmp/logs/test/integration/aks
4546
name: Create temp dir for logs
4647
- run:
4748
command: |
49+
npm install &&
4850
export KUBERNETES_MONITOR_IMAGE_NAME_AND_TAG=$(./scripts/circleci-jobs/setup-integration-tests.py)
4951
.circleci/do-exclusively --branch staging --job ${CIRCLE_JOB} npm run test:integration:aks:yaml
5052
name: Integration tests AKS
@@ -193,11 +195,14 @@ jobs:
193195
- checkout
194196
- install_python_requests
195197
- setup_node16
198+
- aws-cli/install:
199+
override-installed: true
196200
- run:
197201
command: mkdir -p /tmp/logs/test/integration/eks
198202
name: Create temp dir for logs
199203
- run:
200204
command: |
205+
npm install &&
201206
export KUBERNETES_MONITOR_IMAGE_NAME_AND_TAG=$(./scripts/circleci-jobs/setup-integration-tests.py)
202207
.circleci/do-exclusively --branch staging --job ${CIRCLE_JOB} npm run test:integration:eks:yaml
203208
name: Integration tests EKS
@@ -890,6 +895,7 @@ master_branch_only_filter:
890895
only:
891896
- master
892897
orbs:
898+
aws-cli: circleci/[email protected]
893899
azure-cli: circleci/[email protected]
894900
redhat-openshift: circleci/[email protected]
895901
staging_branch_only_filter:

.circleci/config/jobs/@jobs.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,15 @@ eks_integration_tests:
235235
- checkout
236236
- install_python_requests
237237
- setup_node16
238+
- aws-cli/install:
239+
override-installed: true
238240
- run:
239241
name: Create temp dir for logs
240242
command: mkdir -p /tmp/logs/test/integration/eks
241243
- run:
242244
name: Integration tests EKS
243245
command: |
246+
npm install &&
244247
export KUBERNETES_MONITOR_IMAGE_NAME_AND_TAG=$(./scripts/circleci-jobs/setup-integration-tests.py)
245248
.circleci/do-exclusively --branch staging --job ${CIRCLE_JOB} npm run test:integration:eks:yaml
246249
- run:
@@ -267,6 +270,7 @@ aks_integration_tests:
267270
- run:
268271
name: Integration tests AKS
269272
command: |
273+
npm install &&
270274
export KUBERNETES_MONITOR_IMAGE_NAME_AND_TAG=$(./scripts/circleci-jobs/setup-integration-tests.py)
271275
.circleci/do-exclusively --branch staging --job ${CIRCLE_JOB} npm run test:integration:aks:yaml
272276
- run:

.circleci/config/orbs/@aws-cli.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
aws-cli: circleci/[email protected]

test/setup/platforms/eks.ts

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { throwIfEnvironmentVariableUnset } from './helpers';
21
import * as kubectl from '../../helpers/kubectl';
32
import { execWrapper as exec } from '../../helpers/exec';
3+
import { throwIfEnvironmentVariableUnset } from './helpers';
44

55
export async function validateRequiredEnvironment(): Promise<void> {
66
console.log(
@@ -14,9 +14,6 @@ export async function validateRequiredEnvironment(): Promise<void> {
1414
}
1515

1616
export async function setupTester(): Promise<void> {
17-
// update the `aws` CLI, the one in CircleCI's default image is outdated and doens't support eks
18-
await exec('pip install awscli --ignore-installed six');
19-
2017
// TODO: assert all the vars are present before starting the setup?
2118
// TODO: wipe out the data during teardown?
2219
await exec(
@@ -48,24 +45,24 @@ export async function loadImageInCluster(
4845
): Promise<string> {
4946
console.log(`Loading image ${imageNameAndTag} in ECR...`);
5047

51-
const ecrLogin = await exec(
52-
'aws ecr get-login --region us-east-2 --no-include-email',
48+
const accountIdResult = await exec(
49+
'aws sts get-caller-identity --query Account --output text',
5350
);
51+
const accountId = accountIdResult.stdout.trim();
52+
const ecrURL = `${accountId}.dkr.ecr.${process.env.AWS_REGION}.amazonaws.com`;
5453

55-
// aws ecr get-login returns something that looks like:
56-
// docker login -U AWS -p <secret> https://the-address-of-ecr-we-should-use.com
57-
// `docker tag` wants just the last part without https://
58-
// `docker login` wants everything
54+
const ecrLogin = await exec(
55+
`aws ecr get-login-password | docker login --username AWS --password-stdin "${ecrURL}"`,
56+
);
5957

6058
// validate output so we don't execute malicious stuff
61-
if (ecrLogin.stdout.indexOf('docker login -u AWS -p') !== 0) {
62-
throw new Error('aws ecr get-login returned an unexpected output');
59+
if (!ecrLogin.stdout.includes('Login Succeeded')) {
60+
throw new Error('aws ecr get-login-password returned an unexpected output');
6361
}
6462

65-
const targetImage = targetImageFromLoginDetails(ecrLogin.stdout);
63+
const targetImage = `${ecrURL}/snyk/kubernetes-monitor:local`;
6664

6765
await exec(`docker tag ${imageNameAndTag} ${targetImage}`);
68-
await exec(ecrLogin.stdout);
6966
await exec(`docker push ${targetImage}`);
7067

7168
console.log(`Loaded image ${targetImage} in ECR`);
@@ -78,11 +75,3 @@ export async function clean(): Promise<void> {
7875
kubectl.deleteNamespace('snyk-monitor'),
7976
]);
8077
}
81-
82-
function targetImageFromLoginDetails(ecrLoginOutput: string): string {
83-
const split = ecrLoginOutput.split(' ');
84-
const targetImagePrefix = split[split.length - 1]
85-
.replace('https://', '')
86-
.trim();
87-
return `${targetImagePrefix}/snyk/kubernetes-monitor:local`;
88-
}

0 commit comments

Comments
 (0)