Skip to content

Commit

Permalink
Merge pull request #166 from kbalk/common-requirements
Browse files Browse the repository at this point in the history
Consolidate common requirements to make dependabot happy
  • Loading branch information
kbalk authored Jul 23, 2021
2 parents 3ecd05d + 429a000 commit 42fc0bc
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 90 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.2.1
current_version = 0.2.2
commit = True
message = Bumps version to {new_version}
tag = False
Expand Down
5 changes: 5 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ updates:
schedule:
interval: weekly
open-pull-requests-limit: 10
- package-ecosystem: pip
directory: "/"
schedule:
interval: weekly
open-pull-requests-limit: 10
- package-ecosystem: docker
directory: "/"
schedule:
Expand Down
15 changes: 0 additions & 15 deletions .github/workflows/main.yml

This file was deleted.

43 changes: 21 additions & 22 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
dist: bionic
dist: focal

language: minimal

stages:
- lint
Expand All @@ -7,32 +9,29 @@ stages:

if: branch = master OR type = pull_request

stage: test

name: Project Tests

language: python

python:
- "3.8"
- "3.9"

install: skip

script:
- |
set -e
make docker/run target=python/test
make localstack/up
make localstack/pytest
make localstack/clean
before_install:
- tmpdaemon=$(mktemp)
- sudo jq '."registry-mirrors" += ["https://mirror.gcr.io"]' /etc/docker/daemon.json > "$tmpdaemon"
- sudo mv "$tmpdaemon" /etc/docker/daemon.json
- sudo systemctl daemon-reload
- sudo systemctl restart docker
- docker system info

jobs:
include:
- stage: lint
name: Project Syntax Verification
script:
- make docker/run target=lint
script: make docker/run target=lint
- stage: test
name: Run unit tests
script: make docker/run target=pytest/lambda/tests
- stage: test
name: Run integration tests against a mock AWS stack
install:
- make docker-compose/install
- make mockstack/up
script: make mockstack/pytest/lambda
after_script: make mockstack/clean
- stage: deploy
if: branch = master AND type = push AND repo = plus3it/terraform-aws-org-new-account-trust-policy
before_script:
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).

### 0.2.2

**Commit Delta**: [Change from 0.2.1 release](https://github.com/plus3it/terraform-aws-org-new-account-trust-policy/compare/0.2.1...0.2.2)

**Released**: 2021.07.22

**Summary**:

* Moved common requirements to `requirements_common.txt`. Dependabot
does not want to see duplicate requirements.

* Updated the `Makefile` to take advantage of new targets in tardigrade-ci.

* Updated the Travis workflow to reflect changes in tardigrade-ci

### 0.2.1

**Commit Delta**: [Change from 0.2.0 release](https://github.com/plus3it/terraform-aws-org-new-account-trust-policy/compare/0.2.0...0.2.1)
Expand Down
11 changes: 6 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
FROM plus3it/tardigrade-ci:0.14.1
FROM plus3it/tardigrade-ci:0.16.1

COPY ./lambda/src/requirements.txt /src/requirements.txt
COPY ./lambda/tests/requirements_dev.txt /tests/requirements_dev.txt
COPY ./lambda/src/requirements.txt /lambda/src/requirements.txt
COPY ./lambda/tests/requirements_dev.txt /lambda/tests/requirements_dev.txt
COPY ./tests/requirements_test.txt /tests/requirements_test.txt
COPY ./requirements_common.txt /requirements_common.txt

RUN python -m pip install --no-cache-dir \
-r /src/requirements.txt \
-r /tests/requirements_dev.txt \
-r /lambda/src/requirements.txt \
-r /lambda/tests/requirements_dev.txt \
-r /tests/requirements_test.txt
3 changes: 2 additions & 1 deletion Dockerfile_test
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
FROM plus3it/tardigrade-ci:0.14.1
FROM plus3it/tardigrade-ci:0.16.1

COPY ./tests/requirements_test.txt /tests/requirements_test.txt
COPY ./requirements_common.txt /requirements_common.txt

RUN python -m pip install --no-cache-dir -r /tests/requirements_test.txt
43 changes: 7 additions & 36 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,55 +1,26 @@
SHELL := /bin/bash
export PYTHONPATH := $(PYTHONPATH):./lambda/src
export TERRAFORM_PYTEST_DIR := tests

include $(shell test -f .tardigrade-ci || curl -sSL -o .tardigrade-ci "https://raw.githubusercontent.com/plus3it/tardigrade-ci/master/bootstrap/Makefile.bootstrap"; echo .tardigrade-ci)

pytest/install:
@ $(MAKE) install/pip/$(@D) PYPI_PKG_NAME=$(@D)
.PHONY: pytest/deps
pytest/deps:
@ echo "[@] Installing dependencies used for unit and integration tests"
@ python -m pip install \
-r lambda/tests/requirements_dev.txt \
-r tests/requirements_test.txt

.PHONY: python/deps
python/deps:
@ echo "[$@] Installing package dependencies"
@ echo "[$@] Installing lambda dependencies"
@ python -m pip install -r lambda/src/requirements.txt

.PHONY: python/test
python/test: | guard/program/pytest
python/test:
@ echo "[$@] Starting Python tests"
pytest lambda/tests
@ echo "[$@]: Tests executed!"

.PHONY: terraform/pytest
terraform/pytest: | guard/program/terraform guard/program/pytest
@ echo "[$@] Starting test of Terraform lambda installation"
@ echo "[$@] LocalStack must be running; 'make localstack/up' can "
@ echo "[$@] be used to start LocalStack"
@ echo "[$@] Terraform 'apply' command is slow ... be patient !!!"
pytest tests
@ echo "[$@]: Completed successfully!"

.PHONY: localstack/pytest localstack/up localstack/down localstack/clean
localstack/pytest: | guard/program/terraform guard/program/pytest
.PHONY: mockstack/pytest/lambda
mockstack/pytest/lambda: | guard/program/terraform guard/program/pytest
@ echo "[$@] Running Terraform tests against LocalStack"
DOCKER_RUN_FLAGS="--network tests_default --rm -e LOCALSTACK_HOST=localstack" \
TARDIGRADE_CI_DOCKERFILE=Dockerfile_test \
IMAGE_NAME=new-account-trust-policy-integration-test:latest \
$(MAKE) docker/run target=terraform/pytest
@ echo "[$@]: Completed successfully!"

localstack/up: | guard/program/terraform guard/program/pytest
@ echo "[$@] Starting LocalStack container"
docker-compose -f tests/docker-compose-localstack.yml up --detach

localstack/down: | guard/program/terraform guard/program/pytest
@ echo "[$@] Stopping LocalStack container"
docker-compose -f tests/docker-compose-localstack.yml down

localstack/clean: | localstack/down
@ echo "[$@] Stopping and removing LocalStack container and images"
set +o pipefail; docker images | grep lambci | \
awk '{print $$1 ":" $$2}' | xargs -r docker rmi
set +o pipefail; docker images | grep new-account-trust-policy | \
awk '{print $$1 ":" $$2}' | xargs -r docker rmi
19 changes: 13 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,24 @@ aws cloudformation deploy --profile mock-dev --template package.yaml --capabilit

## Testing

To set up and run tests against the Terraform configuration:
To set up and run tests:

```
# Start up LocalStack, a mock AWS stack:
make localstack/up
# Ensure the dependencies are installed on your system.
make python/deps
make pytest/deps
# Start up a mock AWS stack:
make mockstack/up
# Run unit tests:
make docker/run target=pytest/lambda/tests
# Run the tests:
make terraform/pytest
make mockstack/pytest/lambda
# Shut down LocalStack and clean up docker images:
make localstack/clean
# Shut down the mock AWS stack and clean up docker images:
make mockstack/clean
```

<!-- BEGIN TFDOCS -->
Expand Down
2 changes: 1 addition & 1 deletion lambda/src/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
aws-lambda-powertools==1.17.1
boto3==1.17.109
boto3==1.18.2
aws-assume-role-lib==1.7.0
4 changes: 2 additions & 2 deletions lambda/tests/requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
moto==2.0.11
pytest==6.2.3
moto==2.1.0
-r ../../requirements_common.txt
1 change: 1 addition & 0 deletions requirements_common.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pytest==6.2.4
2 changes: 1 addition & 1 deletion tests/requirements_test.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
tftest==1.6.0
pytest==6.2.3
localstack-client==1.21
-r ../requirements_common.txt

0 comments on commit 42fc0bc

Please sign in to comment.