|
26 | 26 | from api.exceptions import AlreadyExists, DryccException, ServiceUnavailable |
27 | 27 | from api.utils import generate_app_name, apply_tasks, unit_to_bytes, unit_to_millicpu |
28 | 28 | from scheduler import KubeHTTPException, KubeException |
29 | | -from .gateway import Gateway, Route |
| 29 | +from scheduler.resources.pod import DEFAULT_CONTAINER_PORT |
| 30 | +from .gateway import Gateway, Route, DEFAULT_HTTP_PORT, DEFAULT_HTTPS_PORT |
30 | 31 | from .config import Config |
31 | 32 | from .service import Service |
32 | 33 | from .release import Release |
|
37 | 38 |
|
38 | 39 | User = get_user_model() |
39 | 40 | logger = logging.getLogger(__name__) |
| 41 | +DEFAULT_PROCFILE_TYPE = "web" |
40 | 42 |
|
41 | 43 |
|
42 | 44 | # http://kubernetes.io/v1.1/docs/design/identifiers.html |
@@ -297,7 +299,7 @@ def deploy(self, release, force_deploy=False, rollback_on_failure=True): # noqa |
297 | 299 | structure = self.structure.copy() |
298 | 300 | # zero out canonical pod counts |
299 | 301 | for proctype in structure.keys(): |
300 | | - if proctype == "web": |
| 302 | + if proctype == DEFAULT_PROCFILE_TYPE: |
301 | 303 | structure[proctype] = 0 |
302 | 304 | # update with the default process type. |
303 | 305 | structure.update(self._default_structure(release)) |
@@ -371,15 +373,15 @@ def deploy(self, release, force_deploy=False, rollback_on_failure=True): # noqa |
371 | 373 | self.log(err, logging.ERROR) |
372 | 374 | raise ServiceUnavailable(err) from e |
373 | 375 | for procfile_type, value in deploys.items(): |
374 | | - if procfile_type == "web": # http |
375 | | - target_port = int(value.get('envs', {}).get('PORT', 5000)) |
376 | | - self._create_default_ingress(procfile_type, target_port) |
| 376 | + if procfile_type == DEFAULT_PROCFILE_TYPE: # http |
| 377 | + target_port = int(value.get('envs', {}).get('PORT', DEFAULT_CONTAINER_PORT)) |
| 378 | + self._create_default_ingress(target_port) |
377 | 379 | service = self.service_set.filter(procfile_type=procfile_type).first() |
378 | 380 | if not service: |
379 | 381 | continue |
380 | 382 | if prev_release and prev_release.build: |
381 | 383 | continue |
382 | | - if procfile_type == "web": |
| 384 | + if procfile_type == DEFAULT_PROCFILE_TYPE: |
383 | 385 | self._verify_http_health(service, **deploys[procfile_type]) |
384 | 386 | else: |
385 | 387 | self._verify_tcp_health(service, **deploys[procfile_type]) |
@@ -816,35 +818,36 @@ def _set_default_config(self): |
816 | 818 | config.memory = new_memory |
817 | 819 | config.save() |
818 | 820 |
|
819 | | - def _create_default_ingress(self, procfile_type, target_port): |
820 | | - port = 80 |
| 821 | + def _create_default_ingress(self, target_port): |
821 | 822 | # create default service |
822 | 823 | try: |
823 | | - service = self.service_set.filter(procfile_type=procfile_type).latest() |
| 824 | + service = self.service_set.filter(procfile_type=DEFAULT_PROCFILE_TYPE).latest() |
824 | 825 | except Service.DoesNotExist: |
825 | | - service = Service(owner=self.owner, app=self, procfile_type=procfile_type) |
826 | | - service.add_port(port, "TCP", target_port) |
| 826 | + service = Service(owner=self.owner, app=self, procfile_type=DEFAULT_PROCFILE_TYPE) |
| 827 | + service.add_port(DEFAULT_HTTP_PORT, "TCP", target_port) |
827 | 828 | service.save() |
828 | 829 | else: |
829 | | - if service.update_port(port, "TCP", target_port): |
| 830 | + if service.update_port(DEFAULT_HTTP_PORT, "TCP", target_port): |
830 | 831 | service.save() |
831 | 832 | # create default gateway |
832 | 833 | try: |
833 | 834 | gateway = self.gateway_set.filter(name=self.id).latest() |
834 | 835 | except Gateway.DoesNotExist: |
835 | 836 | gateway = Gateway(app=self, owner=self.owner, name=self.id) |
836 | | - added, msg = gateway.add(port, "HTTP") |
837 | | - if not added: |
838 | | - raise DryccException(msg) |
| 837 | + modified = gateway.add(DEFAULT_HTTP_PORT, "HTTP") |
| 838 | + if self.tls_set.latest().certs_auto_enabled or self.domain_set.filter( |
| 839 | + models.Q(certificate__isnull=False)).exists(): |
| 840 | + modified = gateway.add(DEFAULT_HTTPS_PORT, "HTTPS") if not modified else True |
| 841 | + if modified: |
839 | 842 | gateway.save() |
840 | 843 | # create default route |
841 | 844 | try: |
842 | 845 | self.route_set.filter(name=self.id).latest() |
843 | 846 | except Route.DoesNotExist: |
844 | 847 | route = Route(app=self, owner=self.owner, kind="HTTPRoute", name=self.id, |
845 | | - port=port, procfile_type=service.procfile_type) |
| 848 | + port=DEFAULT_HTTP_PORT, procfile_type=service.procfile_type) |
846 | 849 | route.rules = route.default_rules |
847 | | - attached, msg = route.attach(gateway.name, port) |
| 850 | + attached, msg = route.attach(gateway.name, DEFAULT_HTTP_PORT) |
848 | 851 | if not attached: |
849 | 852 | raise DryccException(msg) |
850 | 853 | route.save() |
@@ -943,11 +946,11 @@ def _check_deployment_in_progress(self, deploys, release, force_deploy=False): |
943 | 946 | def _default_structure(release): |
944 | 947 | """Scale to default structure based on release type""" |
945 | 948 | if release.build.sha and not release.build.dockerfile and \ |
946 | | - (release.build.procfile and 'web' not in release.build.procfile): |
| 949 | + (release.build.procfile and DEFAULT_PROCFILE_TYPE not in release.build.procfile): |
947 | 950 | structure = {} |
948 | 951 | # default to heroku workflow |
949 | 952 | else: |
950 | | - structure = {'web': 1} |
| 953 | + structure = {DEFAULT_PROCFILE_TYPE: 1} |
951 | 954 | return structure |
952 | 955 |
|
953 | 956 | def _scheduler_filter(self, **kwargs): |
@@ -1119,7 +1122,8 @@ def _gather_app_settings(self, release, app_settings, process_type, replicas, vo |
1119 | 1122 |
|
1120 | 1123 | # only web is routable |
1121 | 1124 | # https://www.drycc.cc/applications/managing-app-processes/#default-process-types |
1122 | | - routable = True if process_type == 'web' and app_settings.routable else False |
| 1125 | + routable = True if ( |
| 1126 | + process_type == DEFAULT_PROCFILE_TYPE and app_settings.routable) else False |
1123 | 1127 |
|
1124 | 1128 | healthcheck = config.healthcheck.get(process_type, {}) |
1125 | 1129 | volumes, volume_mounts = self._get_volumes_and_mounts(process_type, volumes) |
|
0 commit comments