-
Notifications
You must be signed in to change notification settings - Fork 11
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
Added yml config for Green Metrics Tool #589
Open
mrchrisadams
wants to merge
20
commits into
master
Choose a base branch
from
sl-gmt
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
6390544
Added yml config for Green Metrics Tool and
jcamilleri-scottlogic 71f0f5e
Fix the uncommented comment
mrchrisadams f437109
Update usage scenario to get the yaml file parsing
mrchrisadams 40647df
Update use of environ for when there is no .env vars
mrchrisadams 975ee19
Fix failing test from switch to 0 as default int
mrchrisadams 5ac3b37
Remove env vars in test (we no longer need them)
mrchrisadams 863a9d0
Default to passing in mysql connection strings
mrchrisadams 682b0e4
Sanity check github actions failing test issue
mrchrisadams 98865d2
Use dedicated setup for Github CI with .env.ci
mrchrisadams 4899c94
Update dockerfile as advised by to remove use of ENV
mrchrisadams 9feac41
Fix dockerfile typos
mrchrisadams d713092
Fix typo in final Dockerfile line
mrchrisadams 4ddbc36
Update the usage_scenario to create our setup for running scenarios
mrchrisadams 9a06c88
Copy node test files from correct place, and tidy greedy mocha test
mrchrisadams 699316a
Get the first GMT scenario giving a passing result
mrchrisadams 6835239
Bring compose file to parity with usage scenario
mrchrisadams 3a6d845
Make sure request hits HTTP, not HTTPS
mrchrisadams cf3205e
Remove docker-compose-only yaml keys
mrchrisadams 452628c
Add missing command needed in first slow
mrchrisadams c7b94a8
Tidy up docs for first flow
mrchrisadams File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1,12 +1,10 @@ | ||
SECRET_KEY='some-development-secret' | ||
DATABASE_URL=mysql://root:[email protected]:3306/greencheck | ||
DATABASE_URL_READ_ONLY=mysql://root:[email protected]:3306/greencheck | ||
RABBITMQ_URL=amqp://guest:guest@localhost:5672/ | ||
MAILGUN_API_KEY="nope" | ||
DJANGO_SETTINGS_MODULE='greenweb.settings.testing' | ||
SENTRY_DSN="https://[email protected]/test" | ||
SENTRY_AUTH_TOKEN="nope" | ||
SENTRY_ORG="nope" | ||
PYTHONDONTWRITEBYTECODE=1 | ||
RABBITMQ_URL=amqp://guest:guest@localhost:5672/ | ||
|
||
MAXMIND_USER_ID = 123456 | ||
MAXMIND_LICENCE_KEY = "xxxxxxxxxxxxxxxx" |
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
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
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
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,18 @@ | ||
const request = require('supertest'); | ||
const expect = require('chai').expect; | ||
|
||
describe('Greencheck API', () => { | ||
it('Has the correct URL property', () => { | ||
// | ||
request('http://django:9000') | ||
.get('/greencheck/climateaction.tech') | ||
.expect(200) | ||
.expect('Content-Type', 'application/json') | ||
.expect(function (res) { | ||
if (!res.body.hasOwnProperty('url')) throw new Error("Expected 'url' key!"); | ||
}) | ||
.end(function (err, res) { | ||
if (err) throw err; | ||
}) | ||
}); | ||
}); |
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 @@ | ||
{ | ||
"name": "green_metric_tests", | ||
"version": "1.0.0", | ||
"description": "Integration tests for the Greencheck API, intended for use with the Green Metrics Tool from Green Code Berlin. (https://www.green-coding.io/projects/green-metrics-tool/)", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "mocha '/*.spec.js'" | ||
}, | ||
"author": "James Camilleri", | ||
"license": "SEE LICENSE IN ../LICENCE", | ||
"dependencies": { | ||
"chai": "^4.2.0", | ||
"mocha": "^10.4.0", | ||
"supertest": "^7.0.0" | ||
} | ||
} |
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 |
---|---|---|
|
@@ -10,7 +10,6 @@ | |
https://docs.djangoproject.com/en/dev/ref/settings/ | ||
""" | ||
|
||
import os | ||
import environ | ||
import pathlib | ||
from dramatiq import middleware as dramatiq_middleware | ||
|
@@ -19,27 +18,52 @@ | |
ROOT = environ.Path(__file__) - 3 | ||
env = environ.Env( | ||
DEBUG=(bool, False), | ||
SECRET_KEY=(str, os.getenv("SECRET_KEY")), | ||
DATABASE_URL=(str, os.getenv("DATABASE_URL")), | ||
DATABASE_URL_READ_ONLY=(str, os.getenv("DATABASE_URL_READ_ONLY")), | ||
DOMAIN_SNAPSHOT_BUCKET=(str, os.getenv("DOMAIN_SNAPSHOT_BUCKET")), | ||
# add for object storage | ||
OBJECT_STORAGE_ENDPOINT=(str, os.getenv("OBJECT_STORAGE_ENDPOINT")), | ||
OBJECT_STORAGE_REGION=(str, os.getenv("OBJECT_STORAGE_REGION")), | ||
OBJECT_STORAGE_ACCESS_KEY_ID=(str, os.getenv("OBJECT_STORAGE_ACCESS_KEY_ID")), | ||
SECRET_KEY=(str, "some-key"), | ||
DJANGO_LOG_LEVEL=(str, "INFO"), | ||
# databases | ||
# TODO: this is only added to debug a github action issue with failing tests | ||
DATABASE_URL=( | ||
str, | ||
"mysql://root:[email protected]:3306/greencheck", | ||
), | ||
DATABASE_URL_READ_ONLY=( | ||
str, | ||
"mysql://root:[email protected]:3306/greencheck", | ||
), | ||
EXPLORER_TOKEN=(str, "some-token"), | ||
# object storage | ||
OBJECT_STORAGE_ENDPOINT=(str, "https://s3.nl-ams.scw.cloud"), | ||
OBJECT_STORAGE_REGION=(str, "nl-ams"), | ||
OBJECT_STORAGE_ACCESS_KEY_ID=(str, "xxxxxxxxxxxxxxxxxxxx"), | ||
OBJECT_STORAGE_SECRET_ACCESS_KEY=( | ||
str, | ||
os.getenv("OBJECT_STORAGE_SECRET_ACCESS_KEY"), | ||
"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", | ||
), | ||
# add for basicauth | ||
OBJECT_STORAGE_BUCKET_NAME=(str, "tgwf-green-domains-dev"), | ||
DOMAIN_SNAPSHOT_BUCKET=(str, "tgwf-green-domains-dev"), | ||
# basicauth for staging environments | ||
BASICAUTH_DISABLE=(bool, True), | ||
BASICAUTH_USER=(str, "staging_user"), | ||
BASICAUTH_PASSWORD=(str, "strong_password"), | ||
API_URL=(str, os.getenv("API_URL")), | ||
# Swagger API docs url | ||
API_URL=(str, "https://greenweb.localhost"), | ||
TRELLO_REGISTRATION_EMAIL_TO_BOARD_ADDRESS=( | ||
str, | ||
os.getenv("TRELLO_REGISTRATION_EMAIL_TO_BOARD_ADDRESS"), | ||
"mail-to-board@localhost", | ||
), | ||
RABBITMQ_URL=(str, "amqp://USERNAME:PASSWORD@localhost:5672/"), | ||
# cloud providers updated on cronjobs | ||
# we use very high numbers to minimise chance of collision | ||
# with an actual provider id | ||
GOOGLE_PROVIDER_ID=(int, 10000001), | ||
GOOGLE_DATASET_ENDPOINT=(str, "https://www.gstatic.com/ipranges/cloud.json"), | ||
MICROSOFT_PROVIDER_ID=(int, 1000002), | ||
EQUINIX_PROVIDER_ID=(int, 1000003), | ||
EQUINIX_REMOTE_API_ENDPOINT=(str, "https://domain/link/to/file.txt"), | ||
AMAZON_PROVIDER_ID=(int, 1000004), | ||
AMAZON_REMOTE_API_ENDPOINT=(str, "https://domain/link/to/file.json"), | ||
MAXMIND_USER_ID=(str, "123456"), | ||
MAXMIND_LICENCE_KEY=(str, "xxxxxxxxxxxxxxxx"), | ||
) | ||
|
||
# in some cases we don't have a .env file to work from - the environment | ||
|
@@ -237,7 +261,7 @@ | |
DEFAULT_AUTO_FIELD = "django.db.models.AutoField" | ||
# only support API access with the sql explorer if we | ||
# explicitly set the token | ||
EXPLORER_TOKEN = os.getenv("EXPLORER_TOKEN") | ||
EXPLORER_TOKEN = env("EXPLORER_TOKEN") | ||
if EXPLORER_TOKEN: | ||
EXPLORER_TOKEN_AUTH_ENABLED = True | ||
|
||
|
@@ -246,8 +270,8 @@ | |
GEOIP_PROVIDER_DOWNLOAD_URL = ( | ||
"https://download.maxmind.com/geoip/databases/GeoLite2-City/download?suffix=tar.gz" | ||
) | ||
GEOIP_USER = env("MAXMIND_USER_ID", default=None) | ||
GEOIP_PASSWORD = env("MAXMIND_LICENCE_KEY", default=None) | ||
GEOIP_USER = env("MAXMIND_USER_ID") | ||
GEOIP_PASSWORD = env("MAXMIND_LICENCE_KEY") | ||
|
||
# Allow requests from any origin, but only make the API urls available | ||
# CORS_URLS_REGEX = r"^/api/.*$" | ||
|
@@ -319,24 +343,22 @@ | |
|
||
# Importer variables | ||
# Microsoft | ||
MICROSOFT_PROVIDER_ID = env("MICROSOFT_PROVIDER_ID", default=None) | ||
MICROSOFT_PROVIDER_ID = env("MICROSOFT_PROVIDER_ID") | ||
|
||
# Equinix | ||
EQUINIX_PROVIDER_ID = env("EQUINIX_PROVIDER_ID", default=None) | ||
EQUINIX_REMOTE_API_ENDPOINT = env("EQUINIX_REMOTE_API_ENDPOINT", default=None) | ||
EQUINIX_PROVIDER_ID = env("EQUINIX_PROVIDER_ID") | ||
EQUINIX_REMOTE_API_ENDPOINT = env("EQUINIX_REMOTE_API_ENDPOINT") | ||
|
||
# Amazon | ||
AMAZON_PROVIDER_ID = env("AMAZON_PROVIDER_ID", default=None) | ||
AMAZON_REMOTE_API_ENDPOINT = env("AMAZON_REMOTE_API_ENDPOINT", default=None) | ||
AMAZON_PROVIDER_ID = env("AMAZON_PROVIDER_ID") | ||
AMAZON_REMOTE_API_ENDPOINT = env("AMAZON_REMOTE_API_ENDPOINT") | ||
|
||
GOOGLE_PROVIDER_ID = env("GOOGLE_PROVIDER_ID", default=None) | ||
GOOGLE_DATASET_ENDPOINT = env( | ||
"GOOGLE_DATASET_ENDPOINT", default="https://www.gstatic.com/ipranges/cloud.json" | ||
) | ||
GOOGLE_PROVIDER_ID = env("GOOGLE_PROVIDER_ID") | ||
GOOGLE_DATASET_ENDPOINT = env("GOOGLE_DATASET_ENDPOINT") | ||
|
||
|
||
RABBITMQ_URL = env("RABBITMQ_URL", default=None) | ||
RABBITMQ_URL = env("RABBITMQ_URL") | ||
|
||
|
||
REST_FRAMEWORK = { | ||
|
@@ -380,7 +402,7 @@ | |
"root": {"handlers": ["console"], "level": "INFO"}, | ||
"handlers": { | ||
"console": { | ||
"level": os.getenv("DJANGO_LOG_LEVEL", "INFO"), | ||
"level": env("DJANGO_LOG_LEVEL"), | ||
"class": "logging.StreamHandler", | ||
"formatter": "simple", | ||
}, | ||
|
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
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 |
---|---|---|
|
@@ -2,6 +2,15 @@ | |
import sentry_sdk | ||
from sentry_sdk.integrations.django import DjangoIntegration | ||
|
||
import environ | ||
|
||
|
||
prod_env = environ.Env( | ||
SENTRY_DSN=(str, ""), | ||
SENTRY_ENVIRONMENT=(str, "production"), | ||
SENTRY_RELEASE=(str, "[email protected]"), | ||
SENTRY_SAMPLE_RATE=(str, 0), | ||
) | ||
|
||
ANYMAIL = { | ||
"MAILGUN_API_KEY": env("MAILGUN_API_KEY"), # noqa | ||
|
@@ -42,9 +51,9 @@ | |
AWS_S3_FILE_OVERWRITE = False | ||
|
||
# report when things asplode | ||
SENTRY_DSN = os.environ.get("SENTRY_DSN", False) # noqa | ||
SENTRY_ENVIRONMENT = os.environ.get("SENTRY_ENVIRONMENT", "production") # noqa | ||
SENTRY_RELEASE = os.environ.get("SENTRY_RELEASE", "[email protected]") # noqa | ||
SENTRY_DSN = prod_env("SENTRY_DSN") | ||
SENTRY_ENVIRONMENT = prod_env("SENTRY_ENVIRONMENT") | ||
SENTRY_RELEASE = prod_env("SENTRY_RELEASE") | ||
|
||
# Set to a value between 0 for 0% of request and | ||
# 1.0 to capture 100% of requests and annotate | ||
|
@@ -56,7 +65,7 @@ | |
# For more: | ||
# https://docs.sentry.io/platforms/python/guides/django/ | ||
# https://docs.sentry.io/platforms/python/guides/django/performance/ | ||
sentry_sample_rate = os.environ.get("SENTRY_SAMPLE_RATE", 0) # noqa | ||
sentry_sample_rate = prod_env("SENTRY_SAMPLE_RATE") | ||
|
||
if SENTRY_DSN: | ||
sentry_sdk.init( | ||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When run in root, **/*.spec.js will try to read
procfs
on the default node container, which triggers the permissions error we saw