Skip to content

Commit 3ad08b1

Browse files
authored
Merge pull request #419 from snyk/chore/deploy-with-helm
chore/deploy with helm
2 parents 0c58bfc + 4934f70 commit 3ad08b1

File tree

6 files changed

+92
-33
lines changed

6 files changed

+92
-33
lines changed

.circleci/config.yml

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,10 @@ jobs:
136136
<<: *default_machine_config
137137
steps:
138138
- checkout
139+
- setup_node12
139140
- run:
140141
name: Unit tests
141142
command: |
142-
export NVM_DIR="/opt/circleci/.nvm" &&
143-
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" &&
144-
nvm install v12 &&
145-
npm install &&
146143
npm run lint &&
147144
npm run build &&
148145
npm run test:unit
@@ -160,13 +157,10 @@ jobs:
160157
<<: *default_machine_config
161158
steps:
162159
- checkout
160+
- setup_node12
163161
- run:
164162
name: System tests
165163
command: |
166-
export NVM_DIR="/opt/circleci/.nvm" &&
167-
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" &&
168-
nvm install v12 &&
169-
npm install &&
170164
npm run build &&
171165
npm run test:system
172166
- run:
@@ -183,20 +177,14 @@ jobs:
183177
<<: *default_machine_config
184178
steps:
185179
- checkout
180+
- setup_node12
186181
- run:
187182
name: create temp dir for logs
188183
command: mkdir -p /tmp/logs/test/integration/kind
189184
- run:
190185
name: Integration tests
191186
command: |
192-
export NVM_DIR="/opt/circleci/.nvm" &&
193-
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" &&
194-
nvm install v12 &&
195-
npm install &&
196-
docker login --username ${DOCKERHUB_USER} --password ${DOCKERHUB_PASSWORD} &&
197-
export IMAGE_TAG=$([[ "$CIRCLE_BRANCH" == "staging" ]] && echo "staging-candidate" || echo "discardable") &&
198-
export KUBERNETES_MONITOR_IMAGE_NAME_AND_TAG=snyk/kubernetes-monitor:${IMAGE_TAG}-${CIRCLE_SHA1} &&
199-
docker pull ${KUBERNETES_MONITOR_IMAGE_NAME_AND_TAG} &&
187+
export KUBERNETES_MONITOR_IMAGE_NAME_AND_TAG=$(./scripts/circleci-jobs/setup-integration-tests.py)
200188
npm run test:integration
201189
- run:
202190
name: Notify Slack on failure
@@ -210,24 +198,43 @@ jobs:
210198
- store_artifacts:
211199
path: /tmp/logs/test/integration/kind
212200

201+
integration_tests_helm:
202+
<<: *default_machine_config
203+
steps:
204+
- checkout
205+
- setup_node12
206+
- run:
207+
name: Create temporary directory for logs
208+
command: mkdir -p /tmp/logs/test/integration/kind-helm
209+
- run:
210+
name: Integration tests with Helm deployment
211+
command: |
212+
export KUBERNETES_MONITOR_IMAGE_NAME_AND_TAG=$(./scripts/circleci-jobs/setup-integration-tests.py)
213+
npm run test:integration:kind:helm
214+
- run:
215+
name: Notify Slack on failure
216+
command: |
217+
if [[ "$CIRCLE_BRANCH" == "staging" ]]; then
218+
./scripts/slack-notify-failure.sh "staging-integration-helm-tests-${CIRCLE_SHA1}"
219+
else
220+
echo "Current branch is $CIRCLE_BRANCH so skipping notifying Slack"
221+
fi
222+
when: on_fail
223+
- store_artifacts:
224+
path: /tmp/logs/test/integration/kind-helm
225+
213226
eks_integration_tests:
214227
<<: *default_machine_config
215228
steps:
216229
- checkout
230+
- setup_node12
217231
- run:
218232
name: Create temp dir for logs
219233
command: mkdir -p /tmp/logs/test/integration/eks
220234
- run:
221235
name: Integration tests EKS
222236
command: |
223-
export NVM_DIR="/opt/circleci/.nvm" &&
224-
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" &&
225-
nvm install v12 &&
226-
npm install &&
227-
docker login --username ${DOCKERHUB_USER} --password ${DOCKERHUB_PASSWORD} &&
228-
export IMAGE_TAG=$([[ "$CIRCLE_BRANCH" == "staging" ]] && echo "staging-candidate" || echo "discardable") &&
229-
export KUBERNETES_MONITOR_IMAGE_NAME_AND_TAG=snyk/kubernetes-monitor:${IMAGE_TAG}-${CIRCLE_SHA1} &&
230-
docker pull ${KUBERNETES_MONITOR_IMAGE_NAME_AND_TAG} &&
237+
export KUBERNETES_MONITOR_IMAGE_NAME_AND_TAG=$(./scripts/circleci-jobs/setup-integration-tests.py)
231238
.circleci/do-exclusively --branch staging --job ${CIRCLE_JOB} npm run test:integration:eks
232239
- run:
233240
name: Notify Slack on failure
@@ -252,7 +259,7 @@ jobs:
252259
- run:
253260
name: Integration tests OpenShift 3
254261
command: |
255-
export KUBERNETES_MONITOR_IMAGE_NAME_AND_TAG=$(./scripts/circleci-jobs/setup-openshift3-integration-tests.py)
262+
export KUBERNETES_MONITOR_IMAGE_NAME_AND_TAG=$(./scripts/circleci-jobs/setup-integration-tests.py)
256263
npm run test:integration:openshift3
257264
- run:
258265
name: Notify Slack on failure
@@ -265,6 +272,7 @@ jobs:
265272
<<: *default_machine_config
266273
steps:
267274
- checkout
275+
- setup_node12
268276
- run:
269277
name: create temp dir for logs
270278
command: mkdir -p /tmp/logs/test/integration/openshift4
@@ -275,14 +283,7 @@ jobs:
275283
- run:
276284
name: Integration tests OpenShift 4
277285
command: |
278-
export NVM_DIR="/opt/circleci/.nvm" &&
279-
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" &&
280-
nvm install v12 &&
281-
npm install &&
282-
docker login --username ${DOCKERHUB_USER} --password ${DOCKERHUB_PASSWORD} &&
283-
export IMAGE_TAG=$([[ "$CIRCLE_BRANCH" == "staging" ]] && echo "staging-candidate" || echo "discardable") &&
284-
export KUBERNETES_MONITOR_IMAGE_NAME_AND_TAG=snyk/kubernetes-monitor:${IMAGE_TAG}-${CIRCLE_SHA1} &&
285-
docker pull ${KUBERNETES_MONITOR_IMAGE_NAME_AND_TAG} &&
286+
export KUBERNETES_MONITOR_IMAGE_NAME_AND_TAG=$(./scripts/circleci-jobs/setup-integration-tests.py)
286287
.circleci/do-exclusively --branch staging --job ${CIRCLE_JOB} npm run test:integration:openshift4
287288
- run:
288289
name: Delete Operator from Quay
@@ -434,6 +435,10 @@ workflows:
434435
requires:
435436
- build_image
436437
<<: *main_branches_filter
438+
- integration_tests_helm:
439+
requires:
440+
- build_image
441+
<<: *main_branches_filter
437442

438443
MERGE_TO_STAGING:
439444
jobs:
@@ -453,6 +458,10 @@ workflows:
453458
requires:
454459
- build_image
455460
<<: *staging_branch_only_filter
461+
- integration_tests_helm:
462+
requires:
463+
- build_image
464+
<<: *staging_branch_only_filter
456465
- eks_integration_tests:
457466
requires:
458467
- build_image
@@ -474,6 +483,7 @@ workflows:
474483
- unit_tests
475484
- system_tests
476485
- integration_tests
486+
- integration_tests_helm
477487
<<: *staging_branch_only_filter
478488
- deploy_dev:
479489
requires:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ config.local.json
4848
kind
4949
kubectl
5050
oc
51+
helm
5152
kubeconfig-integration-test-kind
5253
snyk-monitor-test-deployment.yaml
5354
snyk-operator/helm-charts

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"test:system": "tap test/system --timeout=600",
1010
"test:integration": "DEPLOYMENT_TYPE=YAML TEST_PLATFORM=kind CREATE_CLUSTER=true tap test/integration/kubernetes.test.ts --timeout=900",
1111
"test:integration:kind": "DEPLOYMENT_TYPE=YAML TEST_PLATFORM=kind CREATE_CLUSTER=true tap test/integration/kubernetes.test.ts --timeout=900",
12+
"test:integration:kind:helm": "DEPLOYMENT_TYPE=Helm TEST_PLATFORM=kind CREATE_CLUSTER=true tap test/integration/kubernetes.test.ts --timeout=900",
1213
"test:integration:eks": "DEPLOYMENT_TYPE=YAML TEST_PLATFORM=eks CREATE_CLUSTER=false tap test/integration/kubernetes.test.ts --timeout=900",
1314
"test:integration:openshift3": "DEPLOYMENT_TYPE=YAML TEST_PLATFORM=openshift3 CREATE_CLUSTER=true tap test/integration/kubernetes.test.ts --timeout=900",
1415
"test:integration:openshift4": "DEPLOYMENT_TYPE=Operator TEST_PLATFORM=openshift4 CREATE_CLUSTER=false tap test/integration/kubernetes.test.ts --timeout=900",

test/setup/deployers/helm.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { exec } from 'child-process-promise';
2+
import { platform } from 'os';
3+
4+
import { IDeployer, IImageOptions } from './types';
5+
import { existsSync, chmodSync } from 'fs';
6+
7+
const helmVersion = '3.0.0';
8+
const helmPath = './helm';
9+
const helmChartPath = './snyk-monitor';
10+
11+
export const helmDeployer: IDeployer = {
12+
deploy: deployKubernetesMonitor,
13+
};
14+
15+
async function deployKubernetesMonitor(
16+
imageOptions: IImageOptions,
17+
): Promise<void> {
18+
if (!existsSync(helmPath)) {
19+
await downloadHelm();
20+
}
21+
22+
const imageNameAndTag = imageOptions.nameAndTag.split(':');
23+
const imageName = imageNameAndTag[0];
24+
const imageTag = imageNameAndTag[1];
25+
const imagePullPolicy = imageOptions.pullPolicy;
26+
27+
await exec(
28+
`${helmPath} upgrade --install snyk-monitor ${helmChartPath} --namespace snyk-monitor ` +
29+
`--set image.repository=${imageName} ` +
30+
`--set image.tag=${imageTag} ` +
31+
`--set image.pullPolicy=${imagePullPolicy} ` +
32+
'--set integrationApi=https://kubernetes-upstream.dev.snyk.io',
33+
);
34+
console.log(`Deployed ${imageOptions.nameAndTag} with pull policy ${imageOptions.pullPolicy}`);
35+
}
36+
37+
async function downloadHelm(): Promise<void> {
38+
console.log(`Downloading Helm ${helmVersion}...`);
39+
const os = platform();
40+
await exec(
41+
`curl https://get.helm.sh/helm-v${helmVersion}-${os}-amd64.tar.gz | tar xfzO - ${os}-amd64/helm > ${helmPath}`,
42+
);
43+
chmodSync(helmPath, 0o755); // rwxr-xr-x
44+
console.log('Downloaded Helm');
45+
}

test/setup/deployers/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { yamlDeployer } from './yaml';
22
import { operatorDeployer } from './operator';
3+
import { helmDeployer } from './helm';
34

45
export default {
56
YAML: yamlDeployer,
67
Operator: operatorDeployer,
8+
Helm: helmDeployer,
79
};

0 commit comments

Comments
 (0)