Skip to content

Commit 6cc8949

Browse files
authored
Merge pull request #1 from lambda-my-aws/release/pipeline
Repushed from latest of source ozone Automation working
2 parents 8a06c4b + ce88c37 commit 6cc8949

7 files changed

Lines changed: 363 additions & 17 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ build/*
1212
*venv*
1313
!buildspec*.yml
1414
!ozone_pipeline.yml
15+
!release/*.yml

buildspec.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ phases:
88
python: 3.7
99
commands:
1010
- pip --version && pip install pip --upgrade || curl https://bootstrap.pypa.io/get-pip.py | python
11-
- pip install troposphere
12-
- pip install awscli --upgrade
13-
- pip install boto3 --upgrade
11+
- python -m venv venv
12+
- pip install ozone --upgrade
1413
pre_build:
1514
commands:
1615
- export PY_VERSION=`python3 -c 'import sys; print("python%s.%s" % (sys.version_info[:2]))'`
@@ -21,11 +20,11 @@ phases:
2120
build:
2221
commands:
2322
- mkdir -p $PY_BUILD
24-
- cp -r $PWD/$LAYER_NAME $PY_BUILD/
23+
- pip install $LAYER_NAME -t $PY_BUILD
2524
post_build:
2625
commands:
2726
- mkdir -p $CFN_BUILD
28-
- python3 $PWD/codebuild/layer.py --path $CFN_BUILD
27+
- python3 $PWD/layer_build.py --path $CFN_BUILD
2928
artifacts:
3029
base-directory: build
3130
files:

buildspec_pypi.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
11
version: 0.2
22
env:
3-
variables:
4-
PYPI_USERNAME: 'JohnPreston'
53
parameter-store:
6-
PYPI_PASSWORD: /CodeBuild/pypipassword
4+
PYPI_USERNAME: /codebuild/pypi/username
5+
PYPI_PASSWORD: /codebuild/pypi/password
76
phases:
87
install:
98
runtime-versions:
109
python: 3.7
1110
commands:
1211
- pip --version && pip install pip --upgrade || curl https://bootstrap.pypa.io/get-pip.py | python
1312
- pip install twine
14-
- export BUILD_DIR=$PWD/builddir
1513
build:
1614
commands:
17-
- mkdir -p $BUILD_DIR
18-
- cd $BUILD_DIR
19-
- python3 setup.py sdist bdist_wheel
15+
- python3 setup.py sdist
2016
- twine upload dist/* -u $PYPI_USERNAME -p $PYPI_PASSWORD

layer_build.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env python
2+
"""
3+
Script to generate the CFN template for the library into a Lambda Layer from within the CodeBuild of the Layer Build.
4+
"""
5+
from datetime import datetime as dt
6+
from os import environ
7+
from json import dumps
8+
from argparse import ArgumentParser
9+
from ozone.templates.awslambdalayer import template
10+
import boto3
11+
12+
def get_artifact_location():
13+
"""
14+
Retrieves the Destination bucket and path of the Layer from CodeBuild within the job
15+
"""
16+
job_id = environ['CODEBUILD_BUILD_ID']
17+
client = boto3.client('codebuild')
18+
build_info = client.batch_get_builds(
19+
ids=[job_id]
20+
)['builds'][0]
21+
location = build_info['artifacts']['location'].strip('aws:arn:s3:::')
22+
bucket = location.split('/')[0]
23+
key = location.split('/', 1)[-1]
24+
return (bucket, key)
25+
26+
27+
if __name__ == '__main__':
28+
PARSER = ArgumentParser('Codebuild CFN template and params build')
29+
PARSER.add_argument(
30+
'--path', help='Path where CFN files are created', required=True
31+
)
32+
ARGS = PARSER.parse_args()
33+
BUILD_DEST = get_artifact_location()
34+
LAYER_NAME = environ['LAYER_NAME']
35+
PY_VERSION = environ['PY_VERSION']
36+
DATE = dt.utcnow().isoformat()
37+
TPL = template(make_public=True, Runtimes=[PY_VERSION], Bucket=BUILD_DEST[0], Key=BUILD_DEST[1])
38+
TPL.set_metadata({
39+
'Author': 'John Mille john@lambda-my-aws.io',
40+
'Version': DATE,
41+
'BuildBy': 'CodePipeline/CodeBuild',
42+
'LayerName': LAYER_NAME
43+
})
44+
TPL.set_description(f'Template for {LAYER_NAME} - {DATE}')
45+
with open(f'{ARGS.path}/layer_template.yml', 'w') as fd:
46+
fd.write(TPL.to_yaml())
47+
template_config = {
48+
'Parameters':
49+
{
50+
'LayerName': LAYER_NAME
51+
},
52+
'Tags': {
53+
'Name': LAYER_NAME
54+
}
55+
}
56+
with open(f'{ARGS.path}/layer_config.json', 'w') as fd:
57+
fd.write(dumps(template_config))

ozone/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
__author__ = """John Mille"""
66
__email__ = 'john@lambda-my-aws.io'
7-
__version__ = '0.0.13'
7+
__version__ = '0.0.20'

0 commit comments

Comments
 (0)