Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
petterhj committed Feb 8, 2024
0 parents commit 967f13e
Show file tree
Hide file tree
Showing 18 changed files with 7,019 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[bumpversion]
current_version = 0.1.0
commit = True
tag = True

[bumpversion:file:setup.py]
[bumpversion:file:serverless.yaml]
[bumpversion:file:package.json]
2 changes: 2 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dataplatform:
- '**/*'
43 changes: 43 additions & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: "CodeQL"

on:
push:
branches: [main]
paths-ignore:
- '**/*.md'
pull_request:
branches: [main]
paths-ignore:
- '**/*.md'
schedule:
- cron: "0 6 * * 1"
workflow_dispatch:

jobs:
analyze:
name: Analyze

permissions:
actions: read
contents: read
security-events: write

runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
language: ["python"]

steps:
- name: Checkout repository
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1

- name: Initialize CodeQL
uses: github/codeql-action/init@d13ca047ae14d02299ae648f2ba451622ecb7270 # v3.23.1
with:
languages: ${{ matrix.language }}
queries: +security-and-quality

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@d13ca047ae14d02299ae648f2ba451622ecb7270 # v3.23.1
33 changes: 33 additions & 0 deletions .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Deploy Dev

on:
push:
branches:
- main
paths-ignore:
- '**/*.md'
workflow_dispatch:

jobs:
deploy-dev:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Set up Python 3.11
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0
with:
python-version: '3.11'
- name: Install Python dependencies
run: pip install tox
- name: Test with tox
run: tox -e py,flake8,black
- uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1
with:
node-version: '18.x'
- name: Install NPM dependencies
run: npm install
- name: Deploy Lambda functions
run: |
AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_DEV }} \
AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY_DEV }} \
./node_modules/.bin/sls deploy -s dev
31 changes: 31 additions & 0 deletions .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Deploy Prod

on:
push:
branches:
- main
workflow_dispatch:

jobs:
deploy-prod:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Set up Python 3.11
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0
with:
python-version: '3.11'
- name: Install Python dependencies
run: pip install tox
- name: Test with tox
run: tox -e py,flake8,black
- uses: actions/setup-node@b39b52d1213e96004bfcb1c61a8a6fa8ab84f3e8 # v4.0.1
with:
node-version: '18.x'
- name: Install NPM dependencies
run: npm install
- name: Deploy Lambda functions
run: |
AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_PROD }} \
AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY_PROD }} \
./node_modules/.bin/sls deploy -s prod
19 changes: 19 additions & 0 deletions .github/workflows/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: "Pull Request Labeler"

on:
pull_request:

jobs:
triage:
runs-on: ubuntu-latest

permissions:
actions: read
contents: read
issues: write
pull-requests: write

steps:
- uses: actions/labeler@ac9175f8a1f3625fd0d4fb234536d26811351594 # v4.3.0
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
20 changes: 20 additions & 0 deletions .github/workflows/pr-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: PR Tests

on:
pull_request:
paths-ignore:
- '**/*.md'

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- name: Set up Python 3.11
uses: actions/setup-python@0a5c61591373683505ea898e09a3ea4f39ef2b9c # v5.0.0
with:
python-version: '3.11'
- name: Install dependencies
run: pip install tox
- name: Test with tox
run: tox -e py,flake8,black
32 changes: 32 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Distribution / packaging
.Python
env/
venv/
.*venv/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg
.tox/
__pycache__

# Serverless directories
.serverless
node_modules/

.gradle/
.terraform/
*~

# Jetbrains
.idea/
9 changes: 9 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The MIT License (MIT)

Copyright © 2021 Oslo kommune

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
78 changes: 78 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
.DEV_PROFILE := okdata-dev
.PROD_PROFILE := okdata-prod

GLOBAL_PY := python3
BUILD_VENV ?= .build_venv
BUILD_PY := $(BUILD_VENV)/bin/python

.PHONY: init
init: node_modules $(BUILD_VENV)

node_modules: package.json package-lock.json
npm install

$(BUILD_VENV):
$(GLOBAL_PY) -m venv $(BUILD_VENV)
$(BUILD_PY) -m pip install -U pip

.PHONY: format
format: $(BUILD_VENV)/bin/black
$(BUILD_PY) -m black .

.PHONY: test
test: $(BUILD_VENV)/bin/tox
$(BUILD_PY) -m tox -p auto -o

.PHONY: upgrade-deps
upgrade-deps: $(BUILD_VENV)/bin/pip-compile
$(BUILD_VENV)/bin/pip-compile -U

.PHONY: deploy
deploy: login-dev init format test
@echo "\nDeploying to stage: dev\n"
sls deploy --stage dev --aws-profile $(.DEV_PROFILE)

.PHONY: deploy-prod
deploy-prod: login-prod init format is-git-clean test
sls deploy --stage prod --aws-profile $(.PROD_PROFILE)

.PHONY: undeploy
undeploy: login-dev init
@echo "\nUndeploying stage: dev\n"
sls remove --stage dev --aws-profile $(.DEV_PROFILE)

.PHONY: undeploy-prod
undeploy-prod: login-prod init
@echo "\nUndeploying stage: prod\n"
sls remove --stage prod --aws-profile $(.PROD_PROFILE)

.PHONY: login-dev
login-dev: init
aws sts get-caller-identity --profile $(.DEV_PROFILE) || aws sso login --profile=$(.DEV_PROFILE)

.PHONY: login-prod
login-prod: init
aws sts get-caller-identity --profile $(.PROD_PROFILE) || aws sso login --profile=$(.PROD_PROFILE)

.PHONY: is-git-clean
is-git-clean:
@status=$$(git fetch origin && git status -s -b) ;\
if test "$${status}" != "## main...origin/main"; then \
echo; \
echo Git working directory is dirty, aborting >&2; \
false; \
fi

.PHONY: build
build: $(BUILD_VENV)/bin/wheel $(BUILD_VENV)/bin/twine
$(BUILD_PY) setup.py sdist bdist_wheel

###
# Python build dependencies
##

$(BUILD_VENV)/bin/pip-compile: $(BUILD_VENV)
$(BUILD_PY) -m pip install -U pip-tools

$(BUILD_VENV)/bin/%: $(BUILD_VENV)
$(BUILD_PY) -m pip install -U $*
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# okdata-data-collectors

Data collector jobs for the Origo dataplatform.

## Setup

```sh
make init
```

## Test

Tests are run using [tox](https://pypi.org/project/tox/):

```sh
make test
```

For tests and linting we use [pytest](https://pypi.org/project/pytest/),
[flake8](https://pypi.org/project/flake8/), and
[black](https://pypi.org/project/black/).

## Deploy

GitHub Actions deploys to dev and prod on push to `main`.

You can also deploy from a local machine to dev with:

```sh
make deploy
```

Or to prod with:

```sh
make deploy-prod
```
Loading

0 comments on commit 967f13e

Please sign in to comment.