Skip to content

Commit 0961f92

Browse files
Tarun-Aroracanihavesomecoffeethealphadollar
authored
[IMPROVEMENT] Deprecate mod_deploy module and update Deployment pipeline workflow (#842)
* Update build commit and runCI script files Signed-off-by: Tarun Arora <[email protected]> * Remove mod_deploy module, update CD Github workflow Signed-off-by: Tarun Arora <[email protected]> * Add build_commit in flask globals Signed-off-by: Tarun Arora <[email protected]> * Add unittests to check when github response is invalid Signed-off-by: Tarun Arora <[email protected]> * Add unittests for request_from_github Signed-off-by: Tarun Arora <[email protected]> * Apply suggestions from code review Co-authored-by: Shivam Kumar Jha <[email protected]> --------- Signed-off-by: Tarun Arora <[email protected]> Co-authored-by: Willem <[email protected]> Co-authored-by: Shivam Kumar Jha <[email protected]>
1 parent 8e3848f commit 0961f92

14 files changed

+169
-429
lines changed

.github/workflows/sp-deployment-pipeline.yml

+10-1
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,12 @@ jobs:
2929
script_stop: true
3030
command_timeout: 10m
3131
script: |
32+
echo "defining directories"
33+
INSTALL_FOLDER="/var/www/sample-platform"
34+
SAMPLE_REPOSITORY="/repository"
35+
3236
echo "jump to app folder"
33-
cd /var/www/sample-platform
37+
cd $INSTALL_FOLDER
3438
3539
echo "checkout branch"
3640
sudo git restore .
@@ -50,5 +54,10 @@ jobs:
5054
echo "run migrations"
5155
sudo FLASK_APP=./run.py flask db upgrade
5256
57+
echo "update runCI script files"
58+
sudo cp "install/ci-vm/ci-linux/ci/bootstrap" "${SAMPLE_REPOSITORY}/TestData/ci-linux/bootstrap"
59+
sudo cp "install/ci-vm/ci-linux/ci/runCI" "${SAMPLE_REPOSITORY}/TestData/ci-linux/runCI"
60+
sudo cp "install/ci-vm/ci-windows/ci/runCI.bat" "${SAMPLE_REPOSITORY}/TestData/ci-windows/runCI.bat"
61+
5362
echo "reload server"
5463
sudo systemctl reload platform

.pycodestylerc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[pycodestyle]
22
count = True
33
max-line-length = 120
4-
exclude=test_diff.py,migrations,venv*,parse.py
4+
exclude=test_diff.py,migrations,venv*,parse.py,config.py
55
ignore = E701

config_sample.py

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
EMAIL_DOMAIN = ''
1414
EMAIL_API_KEY = ''
1515
HMAC_KEY = ''
16-
GITHUB_DEPLOY_KEY = ''
1716
GITHUB_CI_KEY = ''
1817
GITHUB_CLIENT_ID = ''
1918
GITHUB_CLIENT_KEY = ''

decorators.py

+2-5
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from functools import wraps
55
from typing import Any, Callable, Dict, List, Optional, Union
66

7+
import git
78
from flask import g, render_template, request
89

910
from database import EnumSymbol
@@ -93,11 +94,7 @@ def decorated_function(*args, **kwargs):
9394
ctx['applicationName'] = 'CCExtractor CI platform'
9495
ctx['applicationVersion'] = getattr(g, 'version', 'Unknown')
9596
ctx['currentYear'] = date.today().strftime('%Y')
96-
try:
97-
from build_commit import build_commit
98-
except ImportError:
99-
build_commit = 'Unknown'
100-
ctx['build_commit'] = build_commit
97+
ctx['build_commit'] = getattr(g, 'build_commit', "Unknown")
10198
user = getattr(g, 'user', None)
10299
ctx['user'] = user
103100
# Create menu entries

install/install.sh

-3
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,6 @@ userInput email_domain "Email Domain:" $config_server_name "" 1
137137
echo "You can generate your own Email API key here, https://www.mailgun.com/)"
138138
userInput email_api_key "Email API key:" "" "Authentication, Email notification related functions" 0
139139
hmac_key=$(head -80 /dev/urandom | LC_ALL=c tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
140-
echo "You can get details about creating deployment secrets here, https://developer.github.com/webhooks/"
141-
userInput github_deploy_key "GitHub Automated Deploy Webhook Secret:" "" "Automated deployment, mod_deploy module functions" 0
142140
echo "You can get details about creating WEBHOOK_SECRET here, https://developer.github.com/webhooks/"
143141
userInput github_ci_key "GitHub CI Webhook Secret:" "" "CI related functions (mod_ci module)" 0
144142
echo "Get the GitHub client ID and client secret for the platform, by registering the platform here, https://github.com/settings/applications/new"
@@ -236,7 +234,6 @@ SERVER_NAME = '${server_name}'
236234
EMAIL_DOMAIN = '${email_domain}'
237235
EMAIL_API_KEY = '${email_api_key}'
238236
HMAC_KEY = '${hmac_key}'
239-
GITHUB_DEPLOY_KEY = '${github_deploy_key}'
240237
GITHUB_CI_KEY = '${github_ci_key}'
241238
GITHUB_CLIENT_ID = '${github_client_id}'
242239
GITHUB_CLIENT_KEY = '${github_client_secret_key}'

mod_ci/controllers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
from mod_ci.models import (BlockedUsers, GcpInstance, MaintenanceMode,
3636
PrCommentInfo)
3737
from mod_customized.models import CustomizedTest
38-
from mod_deploy.controllers import is_valid_signature, request_from_github
3938
from mod_home.models import CCExtractorVersion, GeneralData
4039
from mod_regression.models import (Category, RegressionTest,
4140
RegressionTestOutput,
@@ -44,6 +43,7 @@
4443
from mod_sample.models import Issue
4544
from mod_test.models import (Fork, Test, TestPlatform, TestProgress,
4645
TestResult, TestResultFile, TestStatus, TestType)
46+
from utility import is_valid_signature, request_from_github
4747

4848
mod_ci = Blueprint('ci', __name__)
4949

mod_deploy/__init__.py

-1
This file was deleted.

mod_deploy/controllers.py

-196
This file was deleted.

run.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from datetime import datetime
88
from typing import Any, Dict, List, Optional
99

10+
import git
1011
from flask import Flask, g
1112
from flask_migrate import Migrate
1213
from google.cloud.storage import Client
@@ -26,7 +27,6 @@
2627
from mod_auth.controllers import mod_auth
2728
from mod_ci.controllers import mod_ci
2829
from mod_customized.controllers import mod_customized
29-
from mod_deploy.controllers import mod_deploy
3030
from mod_home.controllers import mod_home
3131
from mod_regression.controllers import mod_regression
3232
from mod_sample.controllers import mod_sample
@@ -43,10 +43,7 @@
4343
raise MissingConfigError()
4444

4545
app.config.from_mapping(config)
46-
try:
47-
app.config['DEBUG'] = os.environ['DEBUG']
48-
except KeyError:
49-
app.config['DEBUG'] = False
46+
app.config['DEBUG'] = os.environ.get('DEBUG', False)
5047

5148
# embed flask-migrate in the app itself
5249
try:
@@ -67,6 +64,10 @@
6764
storage_client = Client.from_service_account_json(sa_file)
6865
storage_client_bucket = storage_client.bucket(app.config.get('GCS_BUCKET_NAME', ''))
6966

67+
# Save build commit
68+
repo = git.Repo(search_parent_directories=True)
69+
app.config['BUILD_COMMIT'] = repo.head.object.hexsha
70+
7071

7172
def load_secret_keys(application: Flask, secret_session: str = 'secret_key',
7273
secret_csrf: str = 'secret_csrf') -> None:
@@ -233,6 +234,7 @@ def before_request() -> None:
233234
g.version = "0.1"
234235
g.log = log
235236
g.github = get_github_config(app.config)
237+
g.build_commit = app.config['BUILD_COMMIT']
236238

237239

238240
def get_github_config(config: Dict[str, str]) -> Dict[str, str]:
@@ -245,7 +247,6 @@ def get_github_config(config: Dict[str, str]) -> Dict[str, str]:
245247
:rtype: dict
246248
"""
247249
return {
248-
'deploy_key': config.get('GITHUB_DEPLOY_KEY', ''),
249250
'ci_key': config.get('GITHUB_CI_KEY', ''),
250251
'bot_token': config.get('GITHUB_TOKEN', ''),
251252
'bot_name': config.get('GITHUB_BOT', ''),
@@ -268,7 +269,6 @@ def teardown(exception: Optional[Exception]):
268269
app.register_blueprint(mod_regression, url_prefix='/regression')
269270
app.register_blueprint(mod_sample, url_prefix='/sample')
270271
app.register_blueprint(mod_home)
271-
app.register_blueprint(mod_deploy)
272272
app.register_blueprint(mod_test, url_prefix="/test")
273273
app.register_blueprint(mod_ci)
274274
app.register_blueprint(mod_customized, url_prefix='/custom')

tests/base.py

-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ def load_config(file):
104104
'DATABASE_URI': 'sqlite:///:memory:',
105105
'WTF_CSRF_ENABLED': False,
106106
'SQLALCHEMY_POOL_SIZE': 1,
107-
'GITHUB_DEPLOY_KEY': "test_deploy",
108107
'GITHUB_CI_KEY': "test_ci",
109108
'GITHUB_TOKEN': "",
110109
'GITHUB_BOT': "",

tests/test_deploy/__init__.py

-1
This file was deleted.

0 commit comments

Comments
 (0)