Skip to content
This repository was archived by the owner on Jun 30, 2021. It is now read-only.

Commit 3cbfeb9

Browse files
authored
Implement app logic and unit tests (#6)
* Implement app logic and unit tests * Address comments * Update CodeBuild image to 3.7.1 to match Lambda python version * Move s3/codepipeline helper functions into separate files * Add flake8 settings * Add a codepipeline test event template for re-using between test files * Minor fix * Change default input artifact name to BuildArtifact
1 parent ceeeb59 commit 3cbfeb9

23 files changed

+899
-251
lines changed

.flake8

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[flake8]
2+
max-line-length = 120
3+
ignore = E126

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ wheels/
2525
*.egg
2626
MANIFEST
2727
.idea*
28+
.vscode/
2829

2930
# PyInstaller
3031
# Usually these files are written by a python script from a template
@@ -102,4 +103,4 @@ venv.bak/
102103
/site
103104

104105
# mypy
105-
.mypy_cache/
106+
.mypy_cache/

Makefile

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
11
SHELL := /bin/sh
2-
PY_VERSION := 3.6
2+
PY_VERSION := 3.7
33

44
export PYTHONUNBUFFERED := 1
55

6-
BUILD_DIR := dist
6+
SRC_DIR := src
7+
TEST_DIR := test
8+
SAM_DIR := .aws-sam
79
TEMPLATE_DIR := sam
810

911
# Required environment variables (user must override)
1012

1113
# S3 bucket used for packaging SAM templates
12-
PACKAGE_BUCKET ?= <bucket>
14+
PACKAGE_BUCKET ?= aws-sar-publishing
1315

1416
# user can optionally override the following by setting environment variables with the same names before running make
1517

18+
# Path to system pip
19+
PIP ?= pip
20+
# Default AWS CLI region
21+
AWS_DEFAULT_REGION ?= us-east-1
22+
1623
# Stack name used when deploying the app for manual testing
1724
APP_STACK_NAME ?= aws-serverless-codepipeline-serverlessrepo-publish
1825
# GitHub owner.
@@ -28,32 +35,36 @@ PYTHON := $(shell /usr/bin/which python$(PY_VERSION))
2835
.DEFAULT_GOAL := build
2936

3037
clean:
31-
rm -rf $(BUILD_DIR)
38+
rm -f $(SRC_DIR)/requirements.txt
39+
rm -rf $(SAM_DIR)
3240

41+
# used by CI build to install dependencies
3342
init:
3443
$(PYTHON) -m pip install pipenv --user
3544
pipenv sync --dev
3645

3746
init-cicd:
3847
pipenv run sam deploy --template-file $(TEMPLATE_DIR)/cicd.yml --stack-name $(CICD_STACK_NAME) --parameter-overrides GitHubOwner="$(GITHUB_OWNER)" GitHubRepo="$(GITHUB_REPO)" --capabilities CAPABILITY_IAM
3948

40-
compile-app:
41-
mkdir -p $(BUILD_DIR)
42-
pipenv run flake8 app
43-
pipenv run pydocstyle app
49+
compile:
50+
pipenv run flake8 $(SRC_DIR) $(TEST_DIR)
51+
pipenv run pydocstyle $(SRC_DIR)
52+
pipenv run cfn-lint $(TEMPLATE_DIR)/app.yml
53+
pipenv run py.test --cov=$(SRC_DIR) --cov-fail-under=85 -vv test/unit
54+
pipenv lock --requirements > $(SRC_DIR)/requirements.txt
55+
pipenv run sam build -t $(TEMPLATE_DIR)/app.yml -m $(SRC_DIR)/requirements.txt --debug
4456

45-
test: compile-app
46-
pipenv run py.test --cov=app -vv test/unit
57+
integ-test:
58+
pipenv run py.test --cov=$(SRC_DIR) --cov-fail-under=85 -vv test/integration
4759

48-
build: package test
60+
build: compile
4961

50-
package: compile-app
51-
cp -r $(TEMPLATE_DIR)/app.yml app $(BUILD_DIR)
62+
package: compile
63+
pipenv run sam package --template-file $(SAM_DIR)/build/template.yaml --s3-bucket $(PACKAGE_BUCKET) --output-template-file $(SAM_DIR)/packaged-app.yml
5264

53-
# package dependencies in lib dir
54-
pipenv lock --requirements > $(BUILD_DIR)/requirements.txt
55-
pipenv run pip install -t $(BUILD_DIR)/app/lib -r $(BUILD_DIR)/requirements.txt
65+
publish: package
66+
pipenv run sam publish --template $(SAM_DIR)/packaged-app.yml
5667

5768
deploy: package
58-
pipenv run sam package --template-file $(BUILD_DIR)/app.yml --s3-bucket $(PACKAGE_BUCKET) --output-template-file $(BUILD_DIR)/packaged-app.yml
59-
pipenv run sam deploy --template-file $(BUILD_DIR)/packaged-app.yml --stack-name $(APP_STACK_NAME) --capabilities CAPABILITY_IAM
69+
pipenv run sam package --template-file $(SAM_DIR)/app.yml --s3-bucket $(PACKAGE_BUCKET) --output-template-file $(SAM_DIR)/packaged-app.yml
70+
pipenv run sam deploy --template-file $(SAM_DIR)/packaged-app.yml --stack-name $(APP_STACK_NAME) --capabilities CAPABILITY_IAM

Pipfile

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,21 @@ verify_ssl = true
44
name = "pypi"
55

66
[packages]
7-
"boto3" = "*"
7+
boto3 = "*"
8+
aws-xray-sdk = "*"
9+
serverlessrepo = "*"
810

911
[dev-packages]
10-
pytest = "*"
11-
"flake8" = "*"
12+
flake8 = "*"
13+
autopep8 = "*"
1214
pydocstyle = "*"
13-
pytest-cov = "*"
15+
cfn-lint = "*"
1416
aws-sam-cli = "*"
17+
awscli = "*"
18+
pytest = "*"
19+
pytest-mock = "*"
20+
pytest-cov = "*"
21+
mock = "*"
1522

1623
[requires]
17-
python_version = "3.6"
24+
python_version = "3.7"

0 commit comments

Comments
 (0)