forked from aws-samples/sagemaker-ssh-helper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
76 lines (74 loc) · 2.96 KB
/
.gitlab-ci.yml
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
image: public.ecr.aws/docker/library/python:3.8
stages:
- test
run_tests:
stage: test
resource_group: ssh-helper-tests
script:
# Install the package
- pip freeze --all | tee pip_freeze_before.txt
- pip install '.'
- pip check
- pip freeze --all | tee pip_freeze_after.txt
- pip install '.[cdk,test]'
- pip check
- pip freeze --all | tee pip_freeze_after_test.txt
- '( diff pip_freeze_before.txt pip_freeze_after.txt || : ) | tee pip_freeze_diff.txt'
- '( diff pip_freeze_after.txt pip_freeze_after_test.txt || : ) | tee pip_freeze_diff_test.txt'
# Scanning sources
- bandit -r ./sagemaker_ssh_helper/ ./tests/ *.py --skip B603,B404,B101 2>&1 | tee bandit.txt
- flake8 --extend-ignore E501,F401,F541,E402 ./sagemaker_ssh_helper/ ./tests/ *.py | tee flake8.txt
# Update IAM/SSM policies
- curl -fsSL https://deb.nodesource.com/setup_lts.x | bash -
- apt-get install -y nodejs
- npm install -g aws-cdk
- cdk --version
- cd cdk
- USER_ROLE=$GITLAB_ROLE_ARN
- cdk deploy SSH-IAM-SSM-Stack-Tests --require-approval never -c sagemaker_role=$SAGEMAKER_ROLE -c user_role=$USER_ROLE
- cdk deploy SSH-IAM-SSM-Stack --require-approval never -c sagemaker_role=$SAGEMAKER_ROLE -c user_role=$USER_ROLE
- cdk deploy SSM-Advanced-Tier-Stack --require-approval never -c sagemaker_role=$SAGEMAKER_ROLE -c user_role=$USER_ROLE
- AWS_REGION=eu-west-2 cdk deploy SSM-Advanced-Tier-Stack --require-approval never -c sagemaker_role=$SAGEMAKER_ROLE -c user_role=$USER_ROLE
- cd -
# Configure local env
- sm-local-configure
# Assume CI/CD role
- sts=( $(
aws sts assume-role
--role-arn "$GITLAB_ROLE_ARN"
--role-session-name "gitlab-ci"
--duration-seconds 18000
--query 'Credentials.[AccessKeyId,SecretAccessKey,SessionToken]'
--output text
) )
- export AWS_ACCESS_KEY_ID=${sts[0]}
- export AWS_SECRET_ACCESS_KEY=${sts[1]}
- export AWS_SESSION_TOKEN=${sts[2]}
# Build BYOC docker image for tests
- sm-docker build . --file tests/byoc/Dockerfile --repo byoc-ssh:latest
# Run tests
- echo "Extra args for pytest - $PYTEST_EXTRA_ARGS"
- cd tests
- coverage run -m pytest --html=pytest_report.html --self-contained-html --junitxml=pytest_report.xml -m 'not manual' -o sagemaker_role=$SAGEMAKER_ROLE -o kernel_gateway_name=$KERNEL_GATEWAY_NAME $PYTEST_EXTRA_ARGS
- coverage report
- coverage xml
- cd -
coverage: '/(?i)total.*? (100(?:\.0+)?\%|[1-9]?\d(?:\.\d+)?\%)$/'
artifacts:
when: always
reports:
junit: tests/pytest_report.xml
coverage_report:
coverage_format: cobertura
path: tests/coverage.xml
paths:
- pip_freeze_before.txt
- pip_freeze_after.txt
- pip_freeze_diff.txt
- pip_freeze_after_test.txt
- pip_freeze_diff_test.txt
- tests/pytest_report.xml
- tests/pytest_report.html
- tests/coverage.xml
- bandit.txt
- flake8.txt