-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
440e8be
commit 3d86333
Showing
15 changed files
with
517 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[report] | ||
sort = Cover | ||
[run] | ||
omit = src/slacknewsbot/venv/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[flake8] | ||
max-line-length = 88 | ||
ignore = E501,E402,E127 | ||
exclude = | ||
venv | ||
.terraform |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
name: CI | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: [3.7, 3.8] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Setup Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install flake8 pytest | ||
if [ -f src/slacknewsbot/requirements.txt ]; then pip install -r src/slacknewsbot/requirements.txt; fi | ||
- name: Lint with flake8 | ||
run: | | ||
flake8 --count --show-source --statistics | ||
- name: Test with pytest | ||
run: | | ||
PYTHONPATH=./src pytest --cov=src --cov-branch --cov-report term-missing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
builds/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.coverage.* | ||
.cachepip install -r src/slacknewsbot/requirements.txt | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# celery beat schedule file | ||
celerybeat-schedule | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
|
||
.vscode/ | ||
|
||
*.git | ||
*.tfstate | ||
*.backup | ||
*.tfplan | ||
.terraform* | ||
*.zip | ||
*output.txt | ||
secrets* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
repos: | ||
- repo: git://github.com/antonbabenko/pre-commit-terraform | ||
rev: v1.45.0 | ||
hooks: | ||
- id: terraform_fmt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
.PHONY: check test deploy deploy-with-secrets-file | ||
|
||
check: ## Run linters | ||
@echo "*** running linters ***" | ||
flake8 --count --show-source --statistics | ||
@echo "*** all linters passing ***" | ||
test: check ## Run tests | ||
@echo "*** running tests ***" | ||
PYTHONPATH=./src pytest --cov=src --cov-branch --cov-report term-missing | ||
@echo "*** all tests passing ***" | ||
deploy: test ## Deploy project when secrets are exported as env variables | ||
@echo "*** running deploy ***" | ||
terraform apply | ||
deploy-with-secrets-file: test ## Deploy project when secrets are stored in secrets.tfvars file | ||
@echo "*** running deploy ***" | ||
terraform apply -var-file=secrets.tfvars |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
|
||
## Create virtualenv | ||
``` | ||
python3 -m venv venv | ||
source venv/bin/activate | ||
pip install -r src/slacknewsbot/requirements.txt | ||
``` | ||
|
||
## Run tests | ||
``` | ||
make tests | ||
``` | ||
|
||
## Deploy function | ||
### Export secrets | ||
``` | ||
export TF_VAR_slack_bot_token=XXX | ||
export TF_VAR_ph_api_token=XXX | ||
``` | ||
### Deploy | ||
``` | ||
make deploy | ||
``` | ||
### Deploy with secrets file | ||
``` | ||
make deploy-with-secrets-file | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
provider "aws" { | ||
region = "eu-west-1" | ||
} | ||
|
||
|
||
module "lambda_function" { | ||
source = "terraform-aws-modules/lambda/aws" | ||
version = "2.2.0" | ||
|
||
function_name = var.name | ||
description = "Function to post popular articles to Slack" | ||
handler = "app.lambda_handler" | ||
runtime = "python3.8" | ||
timeout = 30 | ||
|
||
source_path = "./src/slacknewsbot" | ||
|
||
environment_variables = { | ||
SLACK_CHANNEL = var.slack_channel_name | ||
SLACK_BOT_TOKEN = var.slack_bot_token | ||
QUERY_HN = var.query_hn | ||
QUERY_PH = var.query_ph | ||
PH_API_TOKEN = var.ph_api_token | ||
STORIES_NUMBER = var.stories_number | ||
} | ||
allowed_triggers = { | ||
PostToSlack = { | ||
principal = "events.amazonaws.com" | ||
source_arn = aws_cloudwatch_event_rule.cw_cron.arn | ||
} | ||
} | ||
create_current_version_allowed_triggers = false | ||
|
||
tags = { | ||
Name = var.name | ||
} | ||
} | ||
|
||
# EVENT CONFIG | ||
resource "aws_cloudwatch_event_rule" "cw_cron" { | ||
name = "${name}-lambda-trigger" | ||
description = "Lambda trigge to post to Slack" | ||
|
||
schedule_expression = "cron(0 13 * * ? *)" | ||
} | ||
|
||
resource "aws_cloudwatch_event_target" "trigger_slack" { | ||
rule = aws_cloudwatch_event_rule.cw_cron.name | ||
arn = module.lambda_function.lambda_function_arn | ||
} |
Empty file.
Oops, something went wrong.