Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Update .gitignore and Makefile #134

Merged
merged 4 commits into from
May 31, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,6 @@ htmlcov/
*.tfvars
*.tfstate.backup
*.tfstate.*.backup
.vscode
.env
reports/
ocervell marked this conversation as resolved.
Show resolved Hide resolved
85 changes: 65 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,21 @@
#
# useful targets:
# make clean -- clean distutils
# make coverage_report -- code coverage report
# make coverage -- code coverage report
# make flake8 -- flake8 checks
# make pylint -- source code checks
# make tests -- run all of the tests
# make unittest -- runs the unit tests
# make unit -- runs the unit tests
########################################################
# variable section

NAME = "slo_generator"

PIP=pip3

PYTHON=python3
TWINE=twine
COVERAGE=coverage
NOSE_OPTS = --with-coverage --cover-package=$(NAME) --cover-erase
NOSE_OPTS = --with-coverage --cover-package=$(NAME) --cover-erase --nologcapture --logging-level=ERROR
SITELIB = $(shell $(PYTHON) -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")

VERSION := $(shell grep "version = " setup.py | cut -d\ -f3)
Expand All @@ -29,18 +28,11 @@ FLAKE8_IGNORE = E302,E203,E261

########################################################

all: clean install install_test test
all: clean install test

info:
@echo "slo-generator version: ${VERSION}"

flake8:
flake8 --ignore=$(FLAKE8_IGNORE) $(NAME)/ --max-line-length=80
flake8 --ignore=$(FLAKE8_IGNORE),E402 tests/ --max-line-length=80

pylint:
find ./$(NAME) ./tests -name \*.py | xargs pylint --rcfile .pylintrc --ignore-patterns=test_.*?py

clean:
@echo "Cleaning up distutils stuff"
rm -rf build
Expand Down Expand Up @@ -69,26 +61,79 @@ develop:
$(PIP) install -e .

install: clean
$(PIP) install .

install_test:
$(PIP) install wheel flake8 mock coverage nose pylint
$(PIP) install -e ."[api, datadog, prometheus, elasticsearch, pubsub, cloud_monitoring, bigquery, dev]"

test: install_test flake8 pylint unittest
# Local tests
test: install unit integration lint

unittest: clean
unit: clean
nosetests $(NOSE_OPTS) tests/unit/* -v

coverage_report:
coverage:
$(COVERAGE) report --rcfile=".coveragerc"

lint: flake8 pylint

flake8:
flake8 --ignore=$(FLAKE8_IGNORE) $(NAME)/ --max-line-length=80
flake8 --ignore=$(FLAKE8_IGNORE),E402 tests/ --max-line-length=80

pylint:
find ./$(NAME) ./tests -name \*.py | xargs pylint --rcfile .pylintrc --ignore-patterns=test_.*?py

integration: int_cm int_csm int_custom int_dd int_dt int_es int_prom

int_cm:
slo-generator compute -f samples/cloud_monitoring -c samples/config.yaml

int_csm:
slo-generator compute -f samples/cloud_service_monitoring -c samples/config.yaml

int_custom:
slo-generator compute -f samples/custom -c samples/config.yaml

int_dd:
slo-generator compute -f samples/datadog -c samples/config.yaml

int_dt:
slo-generator compute -f samples/dynatrace -c samples/config.yaml

int_es:
slo-generator compute -f samples/elasticsearch -c samples/config.yaml

int_prom:
slo-generator compute -f samples/prometheus -c samples/config.yaml

# Docker
docker_build:
DOCKER_BUILDKIT=1
docker build -t slo-generator:latest .

docker_test: docker_build
docker run --entrypoint "make" \
-e MIN_VALID_EVENTS=10 \
-e GOOGLE_APPLICATION_CREDENTIALS=tests/unit/fixtures/fake_credentials.json \
slo-generator test

# API
run_api:
slo-generator api --target=run_compute --signature-type=cloudevent

docker_build_api:
cd slo_generator/api && \
pack build \
--builder gcr.io/buildpacks/builder:v1 \
--env GOOGLE_FUNCTION_SIGNATURE_TYPE=cloudevent \
--env GOOGLE_FUNCTION_TARGET=run_compute \
slo-generator-api

docker_push:
gcloud auth configure-docker -q
docker tag slo-generator-api gcr.io/${PROJECT_ID}/slo-generator-api:${VERSION}
docker push gcr.io/${PROJECT_ID}/slo-generator-api

cloudbuild_api:
cd slo_generator/api && \
gcloud alpha builds submit --pack image=gcr.io/${PROJECT_ID}/slo-generator-api:${VERSION},env=GOOGLE_FUNCTION_SIGNATURE_TYPE=cloudevent,env=GOOGLE_FUNCTION_TARGET=run_compute

deploy_api:
gcloud run deploy --image gcr.io/${PROJECT_ID}/slo-generator-api:${VERSION} --platform managed --set-env-vars CONFIG_URL=${CONFIG_URL} --service-account=${SERVICE_ACCOUNT}