Skip to content

Commit

Permalink
chore(controller): using django native JSONFiled
Browse files Browse the repository at this point in the history
  • Loading branch information
duanhongyi committed Aug 9, 2021
1 parent af13883 commit cf43590
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 127 deletions.
178 changes: 77 additions & 101 deletions rootfs/api/migrations/0001_initial.py

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions rootfs/api/models/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from django.conf import settings
from django.db import models
from rest_framework.exceptions import ValidationError, NotFound
from jsonfield import JSONField

from api.models import get_session
from api.models import UuidAuditedModel, AlreadyExists, DryccException, ServiceUnavailable
Expand Down Expand Up @@ -73,8 +72,10 @@ class App(UuidAuditedModel):
id = models.SlugField(max_length=63, unique=True, null=True,
validators=[validate_app_id,
validate_reserved_names])
structure = JSONField(default={}, blank=True, validators=[validate_app_structure])
procfile_structure = JSONField(default={}, blank=True, validators=[validate_app_structure])
structure = models.JSONField(
default=dict, blank=True, validators=[validate_app_structure])
procfile_structure = models.JSONField(
default=dict, blank=True, validators=[validate_app_structure])

class Meta:
verbose_name = 'Application'
Expand Down
5 changes: 2 additions & 3 deletions rootfs/api/models/appsettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from django.db import models
from django.db import transaction
from django.contrib.postgres.fields import ArrayField
from jsonfield import JSONField
from rest_framework.exceptions import NotFound

from api.utils import dict_diff
Expand All @@ -22,8 +21,8 @@ class AppSettings(UuidAuditedModel):
# the default values is None to differentiate from user sending an empty allowlist
# and user just updating other fields meaning the values needs to be copied from prev release
allowlist = ArrayField(models.CharField(max_length=50), default=None)
autoscale = JSONField(default={}, blank=True)
label = JSONField(default={}, blank=True)
autoscale = models.JSONField(default=dict, blank=True)
label = models.JSONField(default=dict, blank=True)

class Meta:
get_latest_by = 'created'
Expand Down
3 changes: 1 addition & 2 deletions rootfs/api/models/build.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from django.conf import settings
from django.db import models
from jsonfield import JSONField

from api.models import UuidAuditedModel
from api.exceptions import DryccException, Conflict
Expand All @@ -21,7 +20,7 @@ class Build(UuidAuditedModel):

# optional fields populated by builder
sha = models.CharField(max_length=40, blank=True)
procfile = JSONField(default={}, blank=True)
procfile = models.JSONField(default=dict, blank=True)
dockerfile = models.TextField(blank=True)

class Meta:
Expand Down
19 changes: 9 additions & 10 deletions rootfs/api/models/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import logging
from django.conf import settings
from django.db import models
from jsonfield import JSONField
from api.models.release import Release
from api.models import UuidAuditedModel
from api.utils import unit_to_bytes, unit_to_millicpu
Expand All @@ -20,15 +19,15 @@ class Config(UuidAuditedModel):

owner = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.PROTECT)
app = models.ForeignKey('App', on_delete=models.CASCADE)
values = JSONField(default={}, blank=True)
memory = JSONField(default={}, blank=True)
lifecycle_post_start = JSONField(default={}, blank=True)
lifecycle_pre_stop = JSONField(default={}, blank=True)
cpu = JSONField(default={}, blank=True)
tags = JSONField(default={}, blank=True)
registry = JSONField(default={}, blank=True)
healthcheck = JSONField(default={}, blank=True)
termination_grace_period = JSONField(default={}, blank=True)
values = models.JSONField(default=dict, blank=True)
memory = models.JSONField(default=dict, blank=True)
lifecycle_post_start = models.JSONField(default=dict, blank=True)
lifecycle_pre_stop = models.JSONField(default=dict, blank=True)
cpu = models.JSONField(default=dict, blank=True)
tags = models.JSONField(default=dict, blank=True)
registry = models.JSONField(default=dict, blank=True)
healthcheck = models.JSONField(default=dict, blank=True)
termination_grace_period = models.JSONField(default=dict, blank=True)

class Meta:
get_latest_by = 'created'
Expand Down
5 changes: 2 additions & 3 deletions rootfs/api/models/resource.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging
from django.conf import settings
from django.db import models, transaction
from jsonfield import JSONField
from api.exceptions import DryccException, AlreadyExists, ServiceUnavailable
from api.models import UuidAuditedModel, validate_label
from scheduler import KubeException
Expand All @@ -15,10 +14,10 @@ class Resource(UuidAuditedModel):
app = models.ForeignKey('App', on_delete=models.CASCADE)
name = models.CharField(max_length=63, validators=[validate_label])
plan = models.CharField(max_length=128)
data = JSONField(default={}, blank=True)
data = models.JSONField(default=dict, blank=True)
status = models.TextField(blank=True, null=True)
binding = models.TextField(blank=True, null=True)
options = JSONField(default={}, blank=True)
options = models.JSONField(default=dict, blank=True)

class Meta:
get_latest_by = 'created'
Expand Down
3 changes: 1 addition & 2 deletions rootfs/api/models/volume.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import logging
from django.db import models, transaction
from django.conf import settings
from jsonfield import JSONField
from api.utils import unit_to_bytes
from api.exceptions import DryccException, ServiceUnavailable, AlreadyExists
from api.models import UuidAuditedModel, validate_label
Expand All @@ -16,7 +15,7 @@ class Volume(UuidAuditedModel):
app = models.ForeignKey('App', on_delete=models.CASCADE)
name = models.CharField(max_length=63, validators=[validate_label])
size = models.CharField(max_length=128)
path = JSONField(default={}, blank=True)
path = models.JSONField(default=dict, blank=True)

class Meta:
get_latest_by = 'created'
Expand Down
3 changes: 1 addition & 2 deletions rootfs/api/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@
'corsheaders',
'guardian',
'gunicorn',
'jsonfield',
'rest_framework',
'rest_framework.authtoken',
'social_django',
Expand Down Expand Up @@ -420,7 +419,7 @@
MINIO_PORT = os.environ.get('DRYCC_MINIO_SERVICE_PORT', 80)
APP_STORAGE = os.environ.get('APP_STORAGE')

DRYCC_DATABASE_URL = os.environ.get('DRYCC_DATABASE_URL', 'postgres://:@:5432/drycc')
DRYCC_DATABASE_URL = os.environ.get('DRYCC_DATABASE_URL', 'postgres://postgres:@:5432/drycc')
DATABASES = {
'default': dj_database_url.config(default=DRYCC_DATABASE_URL, conn_max_age=600)
}
Expand Down
1 change: 0 additions & 1 deletion rootfs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ docker==5.0.0
gunicorn==20.1.0
idna==3.2
jmespath==0.10.0
jsonfield==3.1.0
jsonschema==3.2.0
morph==0.1.4
ndg-httpsclient==0.5.1
Expand Down

0 comments on commit cf43590

Please sign in to comment.