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 all commits
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,8 @@ htmlcov/
*.tfvars
*.tfstate.backup
*.tfstate.*.backup
.vscode
.env
venv/
.venv/
reports/
94 changes: 70 additions & 24 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 flake8 -- flake8 checks
# make pylint -- source code checks
# make tests -- run all of the tests
# make unittest -- runs the unit tests
# make coverage -- code coverage report
# make test -- run lint + unit tests
# make lint -- run lint tests separately
# make unit -- runs unit tests separately
# make integration -- runs integration 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,80 @@ 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
test: install unit lint

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

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

# Docker
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

# Run API locally
run_api:
slo-generator api --target=run_compute --signature-type=http

# Local Docker build / push
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

# Cloudbuild
cloudbuild:
gcloud alpha builds submit \
--config=cloudbuild.yaml \
--project=${CLOUDBUILD_PROJECT_ID} \
--substitutions=_GCR_PROJECT_ID=${GCR_PROJECT_ID},_VERSION=${VERSION}

# Cloudrun
cloudrun:
gcloud run deploy slo-generator \
--image gcr.io/${GCR_PROJECT_ID}/slo-generator:${VERSION} \
--region=${REGION} \
--platform managed \
--set-env-vars CONFIG_PATH=${CONFIG_URL} \
--service-account=${SERVICE_ACCOUNT} \
--project=${CLOUDRUN_PROJECT_ID} \
--command="slo-generator" \
--args=api \
--args=--signature-type="${SIGNATURE_TYPE}" \
--min-instances 1 \
--allow-unauthenticated