Switch pipeline to new review app system (#601)

* update readme, app.json, reviewapp admin script and settings

* Update README.md

Co-Authored-By: Christopher DeCairos <christopherd@mozillafoundation.org>

* Update README.md

Co-Authored-By: Christopher DeCairos <christopherd@mozillafoundation.org>

* Update README.md

Co-Authored-By: Christopher DeCairos <christopherd@mozillafoundation.org>

Co-authored-by: Christopher DeCairos <christopherd@mozillafoundation.org>
This commit is contained in:
Lucie 2020-01-21 14:00:22 +01:00 коммит произвёл GitHub
Родитель 857d78ea8c
Коммит c3a0a17506
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 73 добавлений и 60 удалений

Просмотреть файл

@ -936,9 +936,29 @@ While for local development we provide a `sample.env` that you can use as defaul
### Review App
Opening a PR will automatically create a Review App in the `network-pulse-api` pipeline. Since it's not possible to use OAuth, you will need to log using Django admin. A slack bot posts credentials and links to Review Apps in to the `mofo-ra-pulse-api` channel.
#### Review App for PRs
This only work for Mo-Fo staff: you will need to manually open a Review App on Heroku for PRs opened by external contributors.
Opening a PR will automatically create a Review App in the `network-pulse-api` pipeline. A slack bot posts credentials and links to Review Apps in to the `mofo-ra-pulse-api` Slack channel.
*Note:* This only work for Mo-Fo staff: you will need to manually open a Review App on Heroku for PRs opened by external contributors.
#### Review App for branches
You can manually create a review app for any branch pushed to this repo. It's useful if you want to test your code on Heroku without opening a PR yet.
To create one:
- log into Heroku.
- Go to the `network-pulse-api` pipeline.
- Click on `+ New app` and select the branch you want to use.
The review app slack bot will post a message in the `mofo-ra-pulse-api` channel with links and credentials as soon as the review app is ready.
#### Environment variables:
- `GITHUB_TOKEN`: GITHUB API authentication,
- `SLACK_WEBHOOK_RA`: Webhook to `mofo-ra-pulse-api`
Non-secret envs can be added to the `app.json` file. Secrets must be set on Heroku in the `Review Apps` (pipelines' `settings` tab).
## Debugging all the things

Просмотреть файл

@ -1,42 +1,9 @@
{
"name": "network-pulse-api",
"env": {
"HEROKU_APP_NAME": {
"required": true
},
"SECRET_KEY": {
"generator": "secret"
},
"AWS_ACCESS_KEY_ID": {
"required": true
},
"AWS_S3_CUSTOM_DOMAIN": {
"required": true
},
"AWS_SECRET_ACCESS_KEY": {
"required": true
},
"AWS_STORAGE_BUCKET_NAME": {
"required": true
},
"AWS_STORAGE_ROOT": {
"required": true
},
"CORS_ORIGIN_REGEX_WHITELIST": {
"required": true
},
"CORS_ORIGIN_WHITELIST": {
"required": true
},
"CSRF_TRUSTED_ORIGINS": {
"required": true
},
"GITHUB_TOKEN": {
"required": true
},
"SLACK_WEBHOOK_RA": {
"required": true
},
"USE_S3": "True",
"SSL_PROTECTION": "False",
"DEBUG": "True"
@ -44,6 +11,11 @@
"addons": [
"heroku-postgresql:hobby-dev"
],
"formation": {
"web": {
"quantity": 1
}
},
"buildpacks": [
{
"url": "heroku/python"

Просмотреть файл

@ -34,6 +34,8 @@ env = environ.Env(
DEBUG=(bool, False),
DJANGO_LOG_LEVEL=(str, 'INFO'),
HEROKU_APP_NAME=(str, ''),
HEROKU_PR_NUMBER=(str, ''),
HEROKU_BRANCH=(str, ''),
PULSE_FRONTEND_HOSTNAME=(str, ''),
SECRET_KEY=(str, ''),
SSL_PROTECTION=(bool, False),
@ -60,6 +62,8 @@ ALLOWED_HOSTS = os.getenv(
).split(',')
HEROKU_APP_NAME = env('HEROKU_APP_NAME')
HEROKU_PR_NUMBER = env('HEROKU_PR_NUMBER')
HEROKU_BRANCH = env('HEROKU_BRANCH')
# Create a simple function to show Django Debug Toolbar on Review App

Просмотреть файл

@ -2,8 +2,6 @@
Management command called during Heroku Review App post-deployment phase: create an admin user and
post the credentials on a private channel on Slack.
"""
import re
import requests
from django.conf import settings
from django.core.exceptions import ObjectDoesNotExist
@ -32,9 +30,13 @@ class Command(BaseCommand):
EmailUser.objects.create_superuser('admin', 'admin@mozillafoundation.org', password)
reviewapp_name = settings.HEROKU_APP_NAME
m = re.search(r'\d+', reviewapp_name)
pr_number = m.group()
pr_number = settings.HEROKU_PR_NUMBER
branch_name = settings.HEROKU_BRANCH
# As of 01/2020 we can only get the PR number if the review app was automatically created
# (https://devcenter.heroku.com/articles/github-integration-review-apps#injected-environment-variables).
# For review app manually created, we have to use the branch name instead.
if pr_number:
# Get PR's title from Github
token = settings.GITHUB_TOKEN
org = 'mozilla'
@ -51,17 +53,32 @@ class Command(BaseCommand):
break
else:
color = '#7CD197'
fallback_text = f'''New review app deployed: It will be ready in a minute!\n
PR {pr_number}{pr_title}\n
Login: admin\n
Password: {password}\n
URL: https://{reviewapp_name}.herokuapp.com'''
message_title = f'PR {pr_number}{pr_title}\n'
github_url = f'https://github.com/mozilla/network-pulse-api/pull/{pr_number}'
github_button_text = 'View PR on Github'
else:
color = '#7CD197'
fallback_text = f'''New review app deployed: It will be ready in a minute!\n
Branch: {branch_name}\n
Login: admin\n
Password: {password}\n
URL: https://{reviewapp_name}.herokuapp.com'''
message_title = f'Branch: {branch_name}\n'
github_url = f'https://github.com/mozilla/network-pulse-api/tree/{branch_name}'
github_button_text = 'View branch on Github'
slack_payload = {
'attachments': [
{
'fallback': 'New review app deployed: It will be ready in a minute!\n'
f'PR {pr_number}{pr_title}\n'
f'Login: admin@mozillafoundation.org\n'
f'Password: {password}\n'
f'URL: https://{reviewapp_name}.herokuapp.com',
'fallback': f'{fallback_text}',
'pretext': 'New review app deployed. It will be ready in a minute!',
'title': f'PR {pr_number}{pr_title}\n',
'title': f'{message_title}',
'text': 'Login: admin@mozillafoundation.org\n'
f'Password: {password}\n',
'color': f'{color}',
@ -73,8 +90,8 @@ class Command(BaseCommand):
},
{
'type': 'button',
'text': 'View PR on Github',
'url': f'https://github.com/mozilla/network-pulse-api/pull/{pr_number}'
'text': f'{github_button_text}',
'url': f'{github_url}'
}
]
}