Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix django template #21

Merged
merged 1 commit into from
Mar 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion kubeyard/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class InitType(metaclass=abc.ABCMeta):
context_factories.PromptedContext(
variable='PROJECT_NAME',
prompt='project name',
default=settings.DEFAULT_KUBE_SERVICE_NAME_PATTERN,
default=settings.DEFAULT_PROJECT_NAME_PATTERN,
),
context_factories.PromptedContext(
variable='KUBE_SERVICE_NAME',
Expand Down
18 changes: 13 additions & 5 deletions kubeyard/context_factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ def get(self):
})
context.update(self.project_context)
context.update(GlobalContextFactory().get())
context['UNDERSCORED_PROJECT_NAME'] = self.underscore_name(context['PROJECT_NAME'])
context['UNDERSCORED_PROJECT_NAME'] = self.normalize_name(context['PROJECT_NAME'])
context['DASHED_PROJECT_NAME'] = self.normalize_name(context['PROJECT_NAME'], '-')
return upper_keys(context)

@property
Expand All @@ -75,8 +76,8 @@ def default_project_name(self) -> str:
return pathlib.Path(self.project_dir).resolve().name

@staticmethod
def underscore_name(name: str) -> str:
return re.sub(r'[\s-]', '_', name)
def normalize_name(name: str, char='_') -> str:
return re.sub(r'[-_\s]', char, name)


def get_user_context_path():
Expand Down Expand Up @@ -111,9 +112,16 @@ def project_context(self):
context[prompt_config.variable] = io_utils.default_input(
prompt_config.prompt,
prompt_config.default.format(
self.underscore_name(context.get('PROJECT_NAME', self.default_project_name))),
project_name=context.get('PROJECT_NAME', self.default_project_name),
underscored_project_name=self.normalize_name(
context.get('PROJECT_NAME', self.default_project_name), '_',
),
dashed_project_name=self.normalize_name(
context.get('PROJECT_NAME', self.default_project_name), '-',
),
),
)
context['DOCKER_IMAGE_NAME'] = self.underscore_name(context.get('PROJECT_NAME', self.default_project_name))
context['DOCKER_IMAGE_NAME'] = self.normalize_name(context.get('PROJECT_NAME', self.default_project_name))
context['DOCKER_REGISTRY_DOMAIN'] = context['DOCKER_REGISTRY_NAME'].split('/', 1)[0]
return context

Expand Down
3 changes: 2 additions & 1 deletion kubeyard/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
'kubernetes_secrets'
)
DEFAULT_DOCKER_REGISTRY_NAME = 'registry.hub.docker.com'
DEFAULT_KUBE_SERVICE_NAME_PATTERN = '{0}'
DEFAULT_PROJECT_NAME_PATTERN = '{project_name}'
DEFAULT_KUBE_SERVICE_NAME_PATTERN = '{dashed_project_name}'
DEFAULT_KUBE_SERVICE_PORT = '80'
DEFAULT_KUBE_LIVE_RELOAD_PORT = '30555'
DEFAULT_DEV_POSTGRES_NAME = 'kubernetes-postgres'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ spec:
app: {{ KUBE_SERVICE_NAME }}
ports:
- port: {{ KUBE_SERVICE_PORT }}
nodePort: {{ KUBE_SERVICE_PORT }}
targetPort: {{ KUBE_SERVICE_PORT }}
type: NodePort
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ dev_mounted_paths:
path: /package
image-name: {{ DOCKER_IMAGE_NAME }}
dev_domains:
- {{ UNDERSCORED_PROJECT_NAME }}
- {{ DASHED_PROJECT_NAME }}