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

Feat/grafana dashboards with charm #9

Closed
wants to merge 49 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
463b985
feat(requirement): add django
Guillaumebeuzeboc Jan 11, 2024
8e280ad
feat(django): project creation
Guillaumebeuzeboc Jan 11, 2024
73336ec
feat(registration): registration app
Guillaumebeuzeboc Jan 11, 2024
c486c7b
feat(rename registration into device)
Guillaumebeuzeboc Jan 15, 2024
6b84ba1
feat(devices): devices views
Guillaumebeuzeboc Jan 15, 2024
f3b9a70
feat(API): add API
Guillaumebeuzeboc Jan 15, 2024
da559a0
fix(formating): apply black
Guillaumebeuzeboc Jan 15, 2024
a522893
fix(api formating): apply black
Guillaumebeuzeboc Jan 15, 2024
5a40d51
fix(device): apply linter
Guillaumebeuzeboc Jan 15, 2024
a62ea12
fix(API): apply linter
Guillaumebeuzeboc Jan 15, 2024
b880be5
test(devices): add model and view test
Guillaumebeuzeboc Jan 17, 2024
1912a09
test(api): add unit test for the API
Guillaumebeuzeboc Jan 17, 2024
aabe6de
fix(devices-test): use 12h as decimal number
Guillaumebeuzeboc Jan 17, 2024
6515394
test(makefile): adapt makefile test for django
Guillaumebeuzeboc Jan 17, 2024
161947f
ci(remove windows and mac)
Guillaumebeuzeboc Jan 17, 2024
fd0dcb2
feat(migration): initial
Guillaumebeuzeboc Jan 17, 2024
e53a68b
doc(readme): add project info to the readme
Guillaumebeuzeboc Jan 17, 2024
196ad06
feat(secret_key): don't use hardcoded secret key
Guillaumebeuzeboc Jan 18, 2024
1df549a
feat(allow hosts): allow extension of the list
Guillaumebeuzeboc Jan 18, 2024
0873ae4
feat(debug): set it to false
Guillaumebeuzeboc Jan 18, 2024
3896895
feat(CSRF): enable CSRF
Guillaumebeuzeboc Jan 18, 2024
241c385
feat(database): provide database location with env var
Guillaumebeuzeboc Jan 18, 2024
34b8c9c
fix(ci): use python3.10
Guillaumebeuzeboc Jan 19, 2024
78ed7b2
fix(makefile): start dev server from makefile
Guillaumebeuzeboc Jan 22, 2024
bdded17
feat(setting): define standard static_root
Guillaumebeuzeboc Jan 22, 2024
7e4504c
feat(setup): include template files
Guillaumebeuzeboc Jan 22, 2024
a4fe044
feat(snap): add snap to distribute the server
Guillaumebeuzeboc Jan 22, 2024
bd34979
feat(snap): create-super-user
Guillaumebeuzeboc Jan 22, 2024
ad22dc2
refactor(test)
Guillaumebeuzeboc Jan 24, 2024
4fe6576
feat(rock): create a rock
Guillaumebeuzeboc Jan 24, 2024
eb01c84
CI(rock)
Guillaumebeuzeboc Jan 24, 2024
6ae4dba
fix(daphne): change bind address
Guillaumebeuzeboc Jan 25, 2024
c77567e
feat(django): USE_X_FORWARDED_HOST
Guillaumebeuzeboc Jan 25, 2024
7b9a1f9
fix(gitignore): ignore generated static files
Guillaumebeuzeboc Jan 31, 2024
d700d71
fix(gunicorn): use guniron instead of daphne
Guillaumebeuzeboc Jan 31, 2024
ae527a4
fix(settings): manage static files with script_name
Guillaumebeuzeboc Jan 31, 2024
641b9e2
fix(create_super_user): accept parameters
Guillaumebeuzeboc Jan 31, 2024
380b713
fix(security): disable csrf for now
Guillaumebeuzeboc Jan 31, 2024
1036eef
feat(models): add grafana dashboard to Device model
Guillaumebeuzeboc Feb 1, 2024
edf9db9
test(device): grafana dashboards
Guillaumebeuzeboc Feb 1, 2024
e5eb868
fix(serializer): use validator for unique uid
Guillaumebeuzeboc Feb 1, 2024
fdd67ad
feat(serializer): add grafana_dashboard as well as validation
Guillaumebeuzeboc Feb 1, 2024
45166c7
feat(devices_view): don't return dashboards when we get all the devices
Guillaumebeuzeboc Feb 1, 2024
e390d49
test(API): api with grafana dashboards
Guillaumebeuzeboc Feb 1, 2024
47e51c2
CI(rock): create and publish rock when a PR is open
Guillaumebeuzeboc Feb 2, 2024
53513d0
feat(dashboard): write dashboards in a directory
Guillaumebeuzeboc Feb 2, 2024
96e2883
fix(tests): clean tests for grafana_dashboards changes
Guillaumebeuzeboc Feb 7, 2024
356e9b3
test(dashboards): dashboards files are properly created
Guillaumebeuzeboc Feb 7, 2024
89ccdd9
test(update_all_dashboard): test django command
Guillaumebeuzeboc Feb 7, 2024
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
35 changes: 35 additions & 0 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Pull Requests

on:
workflow_dispatch: {}
pull_request:
branches:
- main

jobs:
main:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Determine any rockcraft.yaml changed in the PR
id: changed-files
uses: tj-actions/changed-files@v35
with:
files: "./rockcraft.yaml"

- name: Setup LXD
if: steps.changed-files.outputs.any_changed
uses: canonical/[email protected]
with:
channel: latest/stable

- name: Install dependencies
if: steps.changed-files.outputs.any_changed
run: |
sudo snap install --classic rockcraft
- name: Build ROCK
if: steps.changed-files.outputs.any_changed
run: |
rockcraft pack --verbose
58 changes: 58 additions & 0 deletions .github/workflows/rock-release-dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# The workflow canonical/observability/.github/workflows/rock-release-dev.yaml@main
# https://github.com/canonical/observability/blob/34b7edb56094e8e3f01200ce49e01bf9dd6688ac/.github/workflows/rock-release-dev.yaml
# does not allow setting a GHCR repo where to publish at the moment.
# We thus copy it below and adapt it.

name: Build ROCK and release dev tag to GHCR

on:
workflow_dispatch:
push:
branches:
- main

jobs:
main:
runs-on: ubuntu-latest
steps:

- name: Checkout repository
uses: actions/checkout@v3

- name: Find the *latest* rockcraft.yaml
id: find-latest
run: |
latest_rockcraft_file=$(find $GITHUB_WORKSPACE -name "rockcraft.yaml" | sort -V | tail -n1)
rockcraft_dir=$(dirname ${latest_rockcraft_file#\./})
echo "latest-dir=$rockcraft_dir" >> $GITHUB_OUTPUT
- name: Build ROCK
uses: canonical/craft-actions/rockcraft-pack@main
with:
path: "${{ steps.find-latest.outputs.latest-dir }}"
verbosity: verbose
id: rockcraft

- name: Upload locally built ROCK artifact
uses: actions/upload-artifact@v3
with:
name: cos-registration-agent-rock
path: ${{ steps.rockcraft.outputs.rock }}

- name: Upload ROCK to ghcr.io
run: |
sudo skopeo --insecure-policy copy oci-archive:$(realpath ${{ steps.rockcraft.outputs.rock }}) docker://ghcr.io/ubuntu-robotics/cos-registration-server:dev --dest-creds "${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}"
- name: Generate digest
run: |
digest=$(skopeo inspect oci-archive:$(realpath ${{ steps.rockcraft.outputs.rock }}) --format '{{.Digest}}')
echo "digest=${digest#*:}" >> "$GITHUB_OUTPUT"
- name: Install Syft
run: |
curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin
- name: Create SBOM
run: syft $(realpath ${{ steps.rockcraft.outputs.rock }}) -o spdx-json=cos-registration-server.sbom.json

- name: Upload SBOM
uses: actions/upload-artifact@v3
with:
name: cos-registration-server-sbom
path: "cos-registration-server.sbom.json"
58 changes: 58 additions & 0 deletions .github/workflows/rock-release-pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# The workflow canonical/observability/.github/workflows/rock-release-dev.yaml@main
# https://github.com/canonical/observability/blob/34b7edb56094e8e3f01200ce49e01bf9dd6688ac/.github/workflows/rock-release-dev.yaml
# does not allow setting a GHCR repo where to publish at the moment.
# We thus copy it below and adapt it.

name: Build ROCK and release pr tag to GHCR

on:
workflow_dispatch:
pull_request:
branches:
- main

jobs:
main:
runs-on: ubuntu-latest
steps:

- name: Checkout repository
uses: actions/checkout@v3

- name: Find the *latest* rockcraft.yaml
id: find-latest
run: |
latest_rockcraft_file=$(find $GITHUB_WORKSPACE -name "rockcraft.yaml" | sort -V | tail -n1)
rockcraft_dir=$(dirname ${latest_rockcraft_file#\./})
echo "latest-dir=$rockcraft_dir" >> $GITHUB_OUTPUT
- name: Build ROCK
uses: canonical/craft-actions/rockcraft-pack@main
with:
path: "${{ steps.find-latest.outputs.latest-dir }}"
verbosity: verbose
id: rockcraft

- name: Upload locally built ROCK artifact
uses: actions/upload-artifact@v3
with:
name: cos-registration-agent-rock
path: ${{ steps.rockcraft.outputs.rock }}

- name: Upload ROCK to ghcr.io
run: |
sudo skopeo --insecure-policy copy oci-archive:$(realpath ${{ steps.rockcraft.outputs.rock }}) docker://ghcr.io/ubuntu-robotics/cos-registration-server:pr --dest-creds "${{ github.actor }}:${{ secrets.GITHUB_TOKEN }}"
- name: Generate digest
run: |
digest=$(skopeo inspect oci-archive:$(realpath ${{ steps.rockcraft.outputs.rock }}) --format '{{.Digest}}')
echo "digest=${digest#*:}" >> "$GITHUB_OUTPUT"
- name: Install Syft
run: |
curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin
- name: Create SBOM
run: syft $(realpath ${{ steps.rockcraft.outputs.rock }}) -o spdx-json=cos-registration-server.sbom.json

- name: Upload SBOM
uses: actions/upload-artifact@v3
with:
name: cos-registration-server-sbom
path: "cos-registration-server.sbom.json"
48 changes: 5 additions & 43 deletions .github/workflows/main.yml → .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This is a basic workflow to help you get started with Actions

name: CI
name: tests

# Controls when the workflow will run
on:
Expand All @@ -18,7 +18,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.9]
python-version: ["3.10"]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -28,6 +28,8 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Install project
run: make install
- name: Generate django secret key
run: export SECRET_KEY_DJANGO=$(make secretkey)
- name: Run linter
run: make lint

Expand All @@ -36,7 +38,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.9]
python-version: ["3.10"]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -50,43 +52,3 @@ jobs:
run: make test
- name: "Upload coverage to Codecov"
uses: codecov/codecov-action@v3
# with:
# fail_ci_if_error: true

tests_mac:
needs: linter
strategy:
fail-fast: false
matrix:
python-version: [3.9]
os: [macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install project
run: make install
- name: Run tests
run: make test

tests_win:
needs: linter
strategy:
fail-fast: false
matrix:
python-version: [3.9]
os: [windows-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
- name: Install Pip
run: pip install --user --upgrade pip
- name: Install project
run: pip install -e .[test]
- name: run tests
run: pytest -s -vvvv -l --tb=long tests
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,10 @@ dmypy.json

# templates
.github/templates/*

# snap
*.snap
# rock
*.rock
# static files
cos_registration_server/static/
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ then activate it with `source .venv/bin/activate`.

Run `make install` to install the project in develop mode.

## Start the developer server

Run `make runserver` to start the django developer server.

## Run the tests to ensure everything is working

Run `make test` to run the tests.
Expand Down
3 changes: 1 addition & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
include LICENSE
include HISTORY.md
include Containerfile
graft tests
graft cos_registration_server
recursive-include cos_registration_server/devices/templates *
21 changes: 12 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,32 @@ install: ## Install the project in dev mode.
@echo "Don't forget to run 'make virtualenv' if you got errors."
$(ENV_PREFIX)pip install -e .[test]

.PHONY: runserver
runserver: ## Django run server.
$(ENV_PREFIX)python3 cos_registration_server/manage.py runserver

.PHONY: secretkey
secretkey: ## Generate the django secret key.
$(ENV_PREFIX)python3 -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())'


.PHONY: fmt
fmt: ## Format code using black & isort.
$(ENV_PREFIX)isort cos_registration_server/
$(ENV_PREFIX)black -l 79 cos_registration_server/
$(ENV_PREFIX)black -l 79 tests/

.PHONY: lint
lint: ## Run pep8, black, mypy linters.
$(ENV_PREFIX)flake8 cos_registration_server/
$(ENV_PREFIX)black -l 79 --check cos_registration_server/
$(ENV_PREFIX)black -l 79 --check tests/
$(ENV_PREFIX)mypy --ignore-missing-imports cos_registration_server/

.PHONY: test
test: lint ## Run tests and generate coverage report.
$(ENV_PREFIX)pytest -v --cov-config .coveragerc --cov=cos_registration_server -l --tb=short --maxfail=1 tests/
$(ENV_PREFIX)coverage run --source='.' cos_registration_server/manage.py test api devices
$(ENV_PREFIX)coverage xml
$(ENV_PREFIX)coverage html

.PHONY: watch
watch: ## Run tests on every change.
ls **/**.py | entr $(ENV_PREFIX)pytest -s -vvv -l --tb=long --maxfail=1 tests/

.PHONY: clean
clean: ## Clean unused files.
@find ./ -name '*.pyc' -exec rm -f {} \;
Expand Down Expand Up @@ -77,9 +80,9 @@ virtualenv: ## Create a virtual environment.
release: ## Create a new tag for release.
@echo "WARNING: This operation will create s version tag and push to github"
@read -p "Version? (provide the next x.y.z semver) : " TAG
@echo "$${TAG}" > cos_registration_server/VERSION
@echo "$${TAG}" > cos_registration_server/cos_registration_server/VERSION
@$(ENV_PREFIX)gitchangelog > HISTORY.md
@git add cos_registration_server/VERSION HISTORY.md
@git add cos_registration_server/cos_registration_server/VERSION HISTORY.md
@git commit -m "release: version $${TAG} 🚀"
@echo "creating git tag : $${TAG}"
@git tag $${TAG}
Expand Down
Loading
Loading