TT#43813 build: split settings per application

Using https://django-appconf.readthedocs.io/en/latest/ helps us to
keep configs per application

Change-Id: I8b69f421bcafe5e93dd8029063496e0e32ef9595
changes/83/38583/7
Victor Seva 6 years ago
parent bb6e85c650
commit 872af3822a
No known key found for this signature in database
GPG Key ID: B1589889727198E0

@ -6,7 +6,11 @@ repos:
rev: v1.9.0 rev: v1.9.0
hooks: hooks:
- id: reorder-python-imports - id: reorder-python-imports
exclude: migrations/ exclude: >
(?x)^(
migrations/.*|
.*/conf.py
)$
args: ["--py37-plus"] args: ["--py37-plus"]
- repo: https://github.com/psf/black - repo: https://github.com/psf/black
rev: stable rev: stable

@ -0,0 +1,31 @@
# Copyright (C) 2020 The Sipwise Team - http://sipwise.com
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
from django.conf import settings # noqa
from appconf import AppConf
class BuildConf(AppConf):
KEY_AUTH = True
REPOS_SCRIPTS_CONFIG_DIR = "/usr/share/sipwise-repos-scripts/config"
POOL = 3
# sipwise-repos-scripts config files we don't want
RELEASES_SKIP = (
"internal",
"mr0.1",
)
RELEASE_JOBS = ("release-copy-debs-yml",)
class Meta:
prefix = "build"

@ -14,9 +14,9 @@
# with this program. If not, see <http://www.gnu.org/licenses/>. # with this program. If not, see <http://www.gnu.org/licenses/>.
import logging import logging
from django.conf import settings
from django.db.models import signals from django.db.models import signals
from ..conf import settings
from .br import BuildRelease from .br import BuildRelease
from build.tasks import build_release from build.tasks import build_release
from build.tasks import build_resume from build.tasks import build_resume
@ -41,7 +41,7 @@ def jbi_manage(sender, **kwargs):
if jbi.param_release_uuid is None: if jbi.param_release_uuid is None:
return return
release = jbi.param_release release = jbi.param_release
if jbi.jobname in settings.RELEASE_JOBS: if jbi.jobname in settings.BUILD_RELEASE_JOBS:
if not release.startswith("release-"): if not release.startswith("release-"):
release = "release-{}".format(jbi.param_release) release = "release-{}".format(jbi.param_release)
if jbi.param_release == "none": if jbi.param_release == "none":

@ -14,10 +14,10 @@
# with this program. If not, see <http://www.gnu.org/licenses/>. # with this program. If not, see <http://www.gnu.org/licenses/>.
import logging import logging
from django.conf import settings
from django.db import models from django.db import models
from django.forms.models import model_to_dict from django.forms.models import model_to_dict
from ..conf import settings
from build.utils import get_simple_release from build.utils import get_simple_release
from build.utils import ReleaseConfig from build.utils import ReleaseConfig
from repoapi.models import JenkinsBuildInfo from repoapi.models import JenkinsBuildInfo
@ -46,7 +46,8 @@ class BuildReleaseManager(models.Manager):
def release_jobs(self, release_uuid, flat=True): def release_jobs(self, release_uuid, flat=True):
qs = self._jbi.get_queryset() qs = self._jbi.get_queryset()
res = qs.filter( res = qs.filter(
jobname__in=settings.RELEASE_JOBS, param_release_uuid=release_uuid, jobname__in=settings.BUILD_RELEASE_JOBS,
param_release_uuid=release_uuid,
).distinct() ).distinct()
if res.exists(): if res.exists():
if flat: if flat:
@ -96,7 +97,7 @@ class BuildRelease(models.Model):
failed_projects = models.TextField(null=True, editable=False) failed_projects = models.TextField(null=True, editable=False)
pool_size = models.SmallIntegerField(default=0, editable=False) pool_size = models.SmallIntegerField(default=0, editable=False)
objects = BuildReleaseManager() objects = BuildReleaseManager()
release_jobs_len = len(",".join(settings.RELEASE_JOBS)) release_jobs_len = len(",".join(settings.BUILD_RELEASE_JOBS))
def __str__(self): def __str__(self):
return "%s[%s]" % (self.release, self.uuid) return "%s[%s]" % (self.release, self.uuid)
@ -207,7 +208,9 @@ class BuildRelease(models.Model):
if jobname.endswith("-piuparts"): if jobname.endswith("-piuparts"):
return False return False
return self._append_falied(jbi.projectname) return self._append_falied(jbi.projectname)
if jobname.endswith("-repos") or jobname in settings.RELEASE_JOBS: is_repos = jobname.endswith("-repos")
is_rj = jobname in settings.BUILD_RELEASE_JOBS
if is_repos or is_rj:
if jbi.result in ["SUCCESS", "UNSTABLE"]: if jbi.result in ["SUCCESS", "UNSTABLE"]:
return self._append_built(jbi.projectname) return self._append_built(jbi.projectname)
return False return False
@ -236,7 +239,7 @@ class BuildRelease(models.Model):
@property @property
def next(self): def next(self):
failed_projects = self.failed_projects_list failed_projects = self.failed_projects_list
if any(job in failed_projects for job in settings.RELEASE_JOBS): if any(job in failed_projects for job in settings.BUILD_RELEASE_JOBS):
logger.info("release has failed release_jobs, stop sending jobs") logger.info("release has failed release_jobs, stop sending jobs")
return return
res = self._next() res = self._next()

@ -15,8 +15,8 @@
import logging import logging
from celery import shared_task from celery import shared_task
from django.conf import settings
from .conf import settings
from build.models.br import BuildRelease from build.models.br import BuildRelease
from build.utils import trigger_build from build.utils import trigger_build
from build.utils import trigger_copy_deps from build.utils import trigger_copy_deps

@ -0,0 +1,27 @@
# Copyright (C) 2015 The Sipwise Team - http://sipwise.com
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
from django.test import TestCase
class TestBuildConf(TestCase):
def test_django_settings(self):
from django.conf import settings
self.assertEqual(settings.BUILD_KEY_AUTH, True)
def test_build_settings(self):
from build.conf import settings
self.assertEqual(settings.BUILD_KEY_AUTH, True)

@ -75,7 +75,7 @@ class ReleaseConfigTestCase(SimpleTestCase):
"check-tools", "check-tools",
] ]
@override_settings(RELEASES_SKIP=["mr0.1"]) @override_settings(BUILD_RELEASES_SKIP=["mr0.1"])
def test_supported_releases(self): def test_supported_releases(self):
supported = [ supported = [
"trunk", "trunk",

@ -19,11 +19,11 @@ import urllib
from pathlib import Path from pathlib import Path
from uuid import uuid4 from uuid import uuid4
from django.conf import settings
from yaml import load from yaml import load
from yaml import Loader from yaml import Loader
from . import exceptions as err from . import exceptions as err
from .conf import settings
from repoapi.utils import openurl from repoapi.utils import openurl
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -157,9 +157,11 @@ class ReleaseConfig(object):
@classmethod @classmethod
def supported_releases(cls): def supported_releases(cls):
skip_files = ["{}.yml".format(x) for x in settings.RELEASES_SKIP] skip_files = ["{}.yml".format(x) for x in settings.BUILD_RELEASES_SKIP]
res = [] res = []
for root, dirs, files in os.walk(settings.REPOS_SCRIPTS_CONFIG_DIR): for root, dirs, files in os.walk(
settings.BUILD_REPOS_SCRIPTS_CONFIG_DIR
):
for name in files: for name in files:
path_name = Path(name) path_name = Path(name)
if path_name.suffix != ".yml": if path_name.suffix != ".yml":
@ -183,7 +185,7 @@ class ReleaseConfig(object):
filename = name filename = name
self.config_file = "{}.yml".format(filename) self.config_file = "{}.yml".format(filename)
self.config_path = os.path.join( self.config_path = os.path.join(
settings.REPOS_SCRIPTS_CONFIG_DIR, self.config_file settings.BUILD_REPOS_SCRIPTS_CONFIG_DIR, self.config_file
) )
try: try:
with open(self.config_path) as f: with open(self.config_path) as f:

@ -37,7 +37,7 @@ def release_uuid(request, _uuid):
"stats_queued": True, "stats_queued": True,
"build_release": br, "build_release": br,
"projects": projects, "projects": projects,
"release_jobs_size": len(settings.RELEASE_JOBS), "release_jobs_size": len(settings.BUILD_RELEASE_JOBS),
"release_jobs": release_jobs, "release_jobs": release_jobs,
"total": len(br.projects_list), "total": len(br.projects_list),
"queued_projects": queued_projects, "queued_projects": queued_projects,

@ -57,7 +57,9 @@ class JenkinsBuildInfoManager(models.Manager):
return res return res
def releases(self, flat=True): def releases(self, flat=True):
qs = self.get_queryset().exclude(jobname__in=settings.RELEASE_JOBS) qs = self.get_queryset().exclude(
jobname__in=settings.BUILD_RELEASE_JOBS
)
res = qs.filter(tag__isnull=False).values("param_release").distinct() res = qs.filter(tag__isnull=False).values("param_release").distinct()
if res.exists(): if res.exists():
if flat: if flat:

@ -145,14 +145,6 @@ DEBIAN_RELEASES = (
"wheezy", "wheezy",
"squeeze", "squeeze",
) )
# sipwise-repos-scripts config files we don't want
RELEASES_SKIP = [
"internal",
"mr0.1",
]
RELEASE_JOBS = [
"release-copy-debs-yml",
]
RELEASE_DASHBOARD_SETTINGS = { RELEASE_DASHBOARD_SETTINGS = {
"debian_supported": DEBIAN_RELEASES, "debian_supported": DEBIAN_RELEASES,
"build_deps": ( "build_deps": (

@ -90,7 +90,7 @@ WORKFRONT_NOTE = True
# build app # build app
BUILD_KEY_AUTH = True BUILD_KEY_AUTH = True
REPOS_SCRIPTS_CONFIG_DIR = "/usr/share/sipwise-repos-scripts/config" BUILD_REPOS_SCRIPTS_CONFIG_DIR = "/usr/share/sipwise-repos-scripts/config"
# celery # celery
CELERY_BROKER_URL = server_config.get("server", "BROKER_URL") CELERY_BROKER_URL = server_config.get("server", "BROKER_URL")

@ -93,7 +93,7 @@ DOCKER_IMAGES = {
# build app # build app
BUILD_KEY_AUTH = True BUILD_KEY_AUTH = True
REPOS_SCRIPTS_CONFIG_DIR = join(BASE_DIR, "build", "fixtures", "config") BUILD_REPOS_SCRIPTS_CONFIG_DIR = join(BASE_DIR, "build", "fixtures", "config")
# celery # celery
CELERY_BROKER_URL = "memory://localhost/" CELERY_BROKER_URL = "memory://localhost/"

@ -1,5 +1,6 @@
celery celery
Django==1.11.28 Django==1.11.28
django-appconf
django-assets django-assets
django-celery-beat<2.0 django-celery-beat<2.0
django-celery-results django-celery-results

@ -5,7 +5,7 @@ FROM docker.mgm.sipwise.com/sipwise-buster:latest
# is updated with the current date. It will force refresh of all # is updated with the current date. It will force refresh of all
# of the base images and things like `apt-get update` won't be using # of the base images and things like `apt-get update` won't be using
# old cached versions when the Dockerfile is built. # old cached versions when the Dockerfile is built.
ENV REFRESHED_AT 2020-03-20 ENV REFRESHED_AT 2020-03-21
# test execution; we need the backport of python3-junitxml from our own # test execution; we need the backport of python3-junitxml from our own
# repository since it's not part of Debian/buster # repository since it's not part of Debian/buster

Loading…
Cancel
Save