This commit is contained in:
Ishita Mehta 2019-12-24 16:32:40 +05:30
Родитель d73b7298c9
Коммит 3b23398ae5
4 изменённых файлов: 25 добавлений и 14 удалений

Просмотреть файл

@ -7,7 +7,8 @@ import os
from os.path import dirname, abspath
from knack.log import get_logger
from knack.util import CLIError
from azext_aks_deploy.dev.common.const import (APP_NAME_DEFAULT, APP_NAME_PLACEHOLDER,ACR_PLACEHOLDER)
from azext_aks_deploy.dev.common.const import (APP_NAME_DEFAULT, APP_NAME_PLACEHOLDER,
PORT_NUMBER_PLACEHOLDER,ACR_PLACEHOLDER)
from azext_aks_deploy.dev.common.github_api_helper import Files\
logger = get_logger(__name__)
@ -15,13 +16,14 @@ PACKS_ROOT_STRING = os.path.sep+'resources'+os.path.sep+'packs'+os.path.sep
FILE_ABSOLUTE_PATH = abspath(dirname(dirname(abspath(__file__))))
def get_docker_templates(language):
def get_docker_templates(language, port):
files = []
language_packs_path = get_supported_language_packs_path(language)
if language_packs_path:
docker_file_path = r'Dockerfile'
file_path = FILE_ABSOLUTE_PATH + language_packs_path + docker_file_path
docker_file_content = get_file_content(file_path)
file_content = get_file_content(file_path)
docker_file_content = replace_port(file_content,port)
docker_file = Files(path=docker_file_path,content=docker_file_content)
logger.debug("Checkin file path: {}".format(docker_file.path))
logger.debug("Checkin file content: {}".format(docker_file.content))
@ -37,7 +39,7 @@ def get_docker_templates(language):
return files
def get_helm_charts(language, acr_details):
def get_helm_charts(language, acr_details, port):
language_packs_path = get_supported_language_packs_path(language)
files = []
if language_packs_path:
@ -53,6 +55,7 @@ def get_helm_charts(language, acr_details):
# replace values in charts
if('values.yaml' in file_path):
file_content = replace_values(file_content, acr_details)
file_content = replace_port(file_content,port)
if file_path.startswith(abs_pack_path):
file_path=file_path[len(abs_pack_path):]
file_path = file_path.replace('\\','/')
@ -76,6 +79,10 @@ def replace_values(file_content, acr_details):
content=file_content.replace(APP_NAME_PLACEHOLDER, APP_NAME_DEFAULT).replace(ACR_PLACEHOLDER, acr_details['name'])
return content
def replace_port(file_content,port):
content=file_content.replace(PORT_NUMBER_PLACEHOLDER, port)
return content
def get_supported_language_packs_path(language):
return (PACKS_ROOT_STRING + language.lower() + os.path.sep)

Просмотреть файл

@ -13,13 +13,13 @@ from azext_aks_deploy.dev.common.github_api_helper import (Files, get_work_flow_
from azext_aks_deploy.dev.common.github_azure_secrets import get_azure_credentials
from azext_aks_deploy.dev.common.kubectl import get_deployment_IP_port
from azext_aks_deploy.dev.common.const import ( APP_NAME_DEFAULT, APP_NAME_PLACEHOLDER,
ACR_PLACEHOLDER, RG_PLACEHOLDER,
ACR_PLACEHOLDER, RG_PLACEHOLDER, PORT_NUMBER_DEFAULT,
CLUSTER_PLACEHOLDER, RELEASE_PLACEHOLDER, RELEASE_NAME)
from azext_aks_deploy.dev.aks.docker_helm_template import get_docker_templates,get_helm_charts
logger = get_logger(__name__)
def aks_deploy(aks_cluster=None, acr=None, repository=None, skip_secrets_generation=False, do_not_wait=False):
def aks_deploy(aks_cluster=None, acr=None, repository=None, port=None, skip_secrets_generation=False, do_not_wait=False):
"""Build and Deploy to AKS via GitHub actions
:param aks_cluster: Name of the cluster to select for deployment.
:type aks_cluster: str
@ -27,6 +27,8 @@ def aks_deploy(aks_cluster=None, acr=None, repository=None, skip_secrets_generat
:type acr: str
:param repository: GitHub repository URL e.g. https://github.com/azure/azure-cli.
:type repository: str
:param port: Port on which your application runs. Default is 8080
:type port:str
:param skip_secrets_generation : Flag to skip generating Azure credentials.
:type skip_secrets_generation: bool
:param do_not_wait : Do not wait for workflow completion.
@ -63,10 +65,12 @@ def aks_deploy(aks_cluster=None, acr=None, repository=None, skip_secrets_generat
logger.debug(cluster_details)
acr_details = get_acr_details(acr)
logger.debug(acr_details)
if port is None:
port = PORT_NUMBER_DEFAULT
if 'Dockerfile' not in languages.keys():
# check in docker file and docker ignore
docker_files = get_docker_templates(language)
docker_files = get_docker_templates(language, port)
if docker_files:
push_files_github(docker_files, repo_name, 'master', True,
message="Checking in docker files for K8s deployment workflow.")
@ -74,7 +78,7 @@ def aks_deploy(aks_cluster=None, acr=None, repository=None, skip_secrets_generat
logger.warning('Using the Dockerfile found in the repository {}'.format(repo_name))
# check in helm charts
helm_charts = get_helm_charts(language, acr_details)
helm_charts = get_helm_charts(language, acr_details, port)
if helm_charts:
push_files_github(helm_charts, repo_name, 'master', True,
message="Checking in helm charts for K8s deployment workflow.")

Просмотреть файл

@ -1,6 +1,6 @@
FROM node:10
ENV PORT 8080
EXPOSE 8080
ENV PORT port_number_place_holder
EXPOSE port_number_place_holder
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app

Просмотреть файл

@ -9,10 +9,10 @@ image:
nameOverride: "javascript"
fullnameOverride: "javascript"
service:
name: node
name: javascript
type: LoadBalancer
externalPort: 8080
internalPort: 8080
externalPort: port_number_place_holder
internalPort: port_number_place_holder
resources:
limits:
cpu: 100m