diff --git a/applications/samples/Dockerfile b/applications/samples/Dockerfile index 2925caf5a..522de3c9e 100644 --- a/applications/samples/Dockerfile +++ b/applications/samples/Dockerfile @@ -3,6 +3,9 @@ ARG CLOUDHARNESS_FLASK FROM $CLOUDHARNESS_FRONTEND_BUILD as frontend +ARG TEST_ARGUMENT=default +RUN echo $TEST_ARGUMENT + ENV APP_DIR=/app WORKDIR ${APP_DIR} diff --git a/applications/samples/deploy/values-minimal.yaml b/applications/samples/deploy/values-minimal.yaml index 1312b943a..c6fb239a8 100644 --- a/applications/samples/deploy/values-minimal.yaml +++ b/applications/samples/deploy/values-minimal.yaml @@ -4,4 +4,6 @@ harness: soft: [] hard: [] use_services: [] - + dockerfile: + buildArgs: + TEST_ARGUMENT: 'minimal value' diff --git a/applications/samples/deploy/values.yaml b/applications/samples/deploy/values.yaml index 7dd5e2936..3d1717ec8 100644 --- a/applications/samples/deploy/values.yaml +++ b/applications/samples/deploy/values.yaml @@ -84,3 +84,7 @@ harness: - "--request-timeout=180000" - "--hypothesis-max-examples=2" - "--show-errors-tracebacks" + + dockerfile: + buildArgs: + TEST_ARGUMENT: example value \ No newline at end of file diff --git a/docs/applications/README.md b/docs/applications/README.md index da0c44fa1..1c4492fe8 100644 --- a/docs/applications/README.md +++ b/docs/applications/README.md @@ -117,6 +117,8 @@ The most important configuration entries are the following: - `use_services` (`{name, src, dst}[]`): create reverse proxy endpoints in the ingress for the listed applications on [subdomain].[Values.domain]/proxy/[name]. Useful to avoid CORS requests from frontend clients - `readinessProbe`: defines a a url to use as a readiness probe - `livenessProbe`: defines a a url to use as a liveness probe + - `dockerfile`: configuration for the dockerfile, currently only implemented in Skaffold + - `buildArgs`: a map of build arguments to provide to the dockerfile when building with Skaffold # Example code - [Sample application](../../applications/samples) is a sample web application providing working examples of deployment configuration, backend and frontend code. diff --git a/docs/build-deploy/ci-cd/README.md b/docs/build-deploy/ci-cd/README.md index 77b590241..3d5f2de9a 100644 --- a/docs/build-deploy/ci-cd/README.md +++ b/docs/build-deploy/ci-cd/README.md @@ -15,6 +15,10 @@ All you need to to is: - Run `skaffold build` - Run `skaffold run` +### Dockerfile configuration with Skaffold + +When defining an applications values you can provide details on dockerfile configuration such as build arguments. This feature is intended to support useful development use cases (e.g. conditionally running unit tests via build arguments) and should be used with caution as it can lead to different images in different deployment environments. + ## CI/CD with Codefresh [Codefresh](https://codefresh.io/) is a nice platform for CI/CD see details in the [dedicated document](./codefresh.md). \ No newline at end of file diff --git a/docs/model/ApplicationHarnessConfig.md b/docs/model/ApplicationHarnessConfig.md index 0d6fc57ae..ed250e7e0 100644 --- a/docs/model/ApplicationHarnessConfig.md +++ b/docs/model/ApplicationHarnessConfig.md @@ -27,6 +27,9 @@ Name | Type | Description | Notes **accounts** | [**ApplicationAccountsConfig**](ApplicationAccountsConfig.md) | | [optional] **test** | [**ApplicationTestConfig**](ApplicationTestConfig.md) | | [optional] **quotas** | **Dict[str, object]** | | [optional] +**env** | [**List[NameValue]**](NameValue.md) | Environmental variables added to all containers (deprecated, please use envmap) | [optional] +**envmap** | **Dict[str, object]** | | [optional] +**dockerfile** | [**DockerfileConfig**](DockerfileConfig.md) | | [optional] ## Example diff --git a/docs/model/DockerfileConfig.md b/docs/model/DockerfileConfig.md new file mode 100644 index 000000000..5b1925261 --- /dev/null +++ b/docs/model/DockerfileConfig.md @@ -0,0 +1,30 @@ +# DockerfileConfig + +Configuration for a dockerfile + +## Properties + +Name | Type | Description | Notes +------------ | ------------- | ------------- | ------------- +**build_args** | **Dict[str, object]** | | [optional] + +## Example + +```python +from cloudharness_model.models.dockerfile_config import DockerfileConfig + +# TODO update the JSON string below +json = "{}" +# create an instance of DockerfileConfig from a JSON string +dockerfile_config_instance = DockerfileConfig.from_json(json) +# print the JSON string representation of the object +print DockerfileConfig.to_json() + +# convert the object into a dict +dockerfile_config_dict = dockerfile_config_instance.to_dict() +# create an instance of DockerfileConfig from a dict +dockerfile_config_form_dict = dockerfile_config.from_dict(dockerfile_config_dict) +``` +[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) + + diff --git a/docs/model/HarnessMainConfig.md b/docs/model/HarnessMainConfig.md index 5cecf0529..2034bcc09 100644 --- a/docs/model/HarnessMainConfig.md +++ b/docs/model/HarnessMainConfig.md @@ -14,13 +14,12 @@ Name | Type | Description | Notes **registry** | [**RegistryConfig**](RegistryConfig.md) | | [optional] **tag** | **str** | Docker tag used to push/pull the built images. | [optional] **apps** | [**Dict[str, ApplicationConfig]**](ApplicationConfig.md) | | -**env** | [**List[NameValue]**](NameValue.md) | Environmental variables added to all pods (deprecated, please use envmap) | [optional] +**env** | [**List[NameValue]**](NameValue.md) | Environmental variables added to all pods | [optional] **privenv** | [**NameValue**](NameValue.md) | | [optional] **backup** | [**BackupConfig**](BackupConfig.md) | | [optional] **name** | **str** | Base name | [optional] **task_images** | **Dict[str, object]** | | [optional] **build_hash** | **str** | | [optional] -**envmap** | **Dict[str, object]** | | [optional] ## Example diff --git a/libraries/models/api/openapi.yaml b/libraries/models/api/openapi.yaml index 3b115091a..8dd6d7d5a 100644 --- a/libraries/models/api/openapi.yaml +++ b/libraries/models/api/openapi.yaml @@ -399,112 +399,6 @@ components: description: description: General description -- for human consumption type: string - ApplicationHarnessConfig: - description: |- - Define helm variables that allow CloudHarness to enable and configure your - application's deployment - required: [] - type: object - properties: - deployment: - $ref: '#/components/schemas/DeploymentAutoArtifactConfig' - description: Defines reference deployment parameters. Values maps to k8s spec - service: - $ref: '#/components/schemas/ServiceAutoArtifactConfig' - description: Defines automatic service parameters. - subdomain: - description: 'If specified, an ingress will be created at [subdomain].[.Values.domain]' - type: string - aliases: - description: 'If specified, an ingress will be created at [alias].[.Values.domain] for each alias' - type: array - items: - type: string - domain: - description: 'If specified, an ingress will be created at [domain]' - type: string - dependencies: - $ref: '#/components/schemas/ApplicationDependenciesConfig' - description: >- - Application dependencies are used to define what is required in the deployment when - --include (-i) is used. Specify application names in the list. - secured: - description: 'When true, the application is shielded with a getekeeper' - type: boolean - uri_role_mapping: - description: 'Map uri/roles to secure with the Gatekeeper (if `secured: true`)' - type: array - items: - $ref: '#/components/schemas/UriRoleMappingConfig' - secrets: - $ref: '#/components/schemas/SimpleMap' - description: |- - Define secrets will be mounted in the deployment - - Define as - - ```yaml - secrets: - secret_name: 'value' - - ``` - - Values if left empty are randomly generated - use_services: - description: >- - Specify which services this application uses in the frontend to create proxy - ingresses. e.g. - - ``` - - - name: samples - - ``` - type: array - items: - type: string - database: - $ref: '#/components/schemas/DatabaseDeploymentConfig' - description: '' - resources: - description: |- - Application file resources. Maps from deploy/resources folder and mounts as - configmaps - type: array - items: - $ref: '#/components/schemas/FileResourcesConfig' - readinessProbe: - $ref: '#/components/schemas/ApplicationProbe' - description: Kubernetes readiness probe configuration - startupProbe: - $ref: '#/components/schemas/ApplicationProbe' - description: '' - livenessProbe: - $ref: '#/components/schemas/ApplicationProbe' - description: Kubernetes liveness probe configuration - sourceRoot: - $ref: '#/components/schemas/Filename' - description: '' - name: - description: |- - Application's name. Do not edit, the value is automatically set from the - application directory's name - type: string - jupyterhub: - $ref: '#/components/schemas/JupyterHubConfig' - description: | - Configurations specific to jupyterhub. Edit only if your application is - configured as a jupyterhub deployment - accounts: - $ref: '#/components/schemas/ApplicationAccountsConfig' - description: Define specific test users and roles for this application - test: - $ref: '#/components/schemas/ApplicationTestConfig' - description: Enable and configure automated testing for this application. - quotas: - $ref: '#/components/schemas/Quota' - description: '' - additionalProperties: true JupyterHubConfig: description: '' type: object @@ -741,68 +635,6 @@ components: name: my-files size: 5Gi usenfs: true - HarnessMainConfig: - description: '' - required: - - local - - secured_gatekeepers - - domain - - namespace - - mainapp - - apps - type: object - properties: - local: - description: 'If set to true, local DNS mapping is added to pods.' - type: boolean - secured_gatekeepers: - description: >- - Enables/disables Gatekeepers on secured applications. Set to false for - testing/development - type: boolean - domain: - description: The root domain - type: string - example: The root domain. - namespace: - description: The K8s namespace. - type: string - mainapp: - description: Defines the app to map to the root domain - type: string - registry: - $ref: '#/components/schemas/RegistryConfig' - description: '' - tag: - description: Docker tag used to push/pull the built images. - type: string - apps: - $ref: '#/components/schemas/ApplicationsConfigsMap' - description: '' - env: - description: 'Environmental variables added to all pods (deprecated, please use envmap)' - type: array - items: - $ref: '#/components/schemas/NameValue' - privenv: - $ref: '#/components/schemas/NameValue' - description: Private environmental variables added to all pods - backup: - $ref: '#/components/schemas/BackupConfig' - description: '' - name: - description: Base name - type: string - task-images: - $ref: '#/components/schemas/SimpleMap' - description: '' - build_hash: - description: '' - type: string - envmap: - $ref: '#/components/schemas/SimpleMap' - description: Environmental variables added to all pods - additionalProperties: true SimpleMap: description: '' type: object @@ -877,3 +709,193 @@ components: - $ref: '#/components/schemas/AutoArtifactSpec' additionalAttributes: true + DockerfileConfig: + description: Configuration for a dockerfile + type: object + properties: + buildArgs: + $ref: '#/components/schemas/SimpleMap' + description: >- + Map of build arguments to provide to the dockerfile at build time. + + + The use of this feature is to aid in development (e.g. not running tests on every + local build) and not for setting environment variables in different environments; + caution should be taken when using this feature as it can lead to inconsistent + behaviour across environments. + HarnessMainConfig: + description: '' + required: + - local + - secured_gatekeepers + - domain + - namespace + - mainapp + - apps + type: object + properties: + local: + description: 'If set to true, local DNS mapping is added to pods.' + type: boolean + secured_gatekeepers: + description: >- + Enables/disables Gatekeepers on secured applications. Set to false for + testing/development + type: boolean + domain: + description: The root domain + type: string + example: The root domain. + namespace: + description: The K8s namespace. + type: string + mainapp: + description: Defines the app to map to the root domain + type: string + registry: + $ref: '#/components/schemas/RegistryConfig' + description: '' + tag: + description: Docker tag used to push/pull the built images. + type: string + apps: + $ref: '#/components/schemas/ApplicationsConfigsMap' + description: '' + env: + description: Environmental variables added to all pods + type: array + items: + $ref: '#/components/schemas/NameValue' + privenv: + $ref: '#/components/schemas/NameValue' + description: Private environmental variables added to all pods + backup: + $ref: '#/components/schemas/BackupConfig' + description: '' + name: + description: Base name + type: string + task-images: + $ref: '#/components/schemas/SimpleMap' + description: '' + build_hash: + description: '' + type: string + additionalProperties: true + ApplicationHarnessConfig: + description: |- + Define helm variables that allow CloudHarness to enable and configure your + application's deployment + required: [] + type: object + properties: + deployment: + $ref: '#/components/schemas/DeploymentAutoArtifactConfig' + description: Defines reference deployment parameters. Values maps to k8s spec + service: + $ref: '#/components/schemas/ServiceAutoArtifactConfig' + description: Defines automatic service parameters. + subdomain: + description: 'If specified, an ingress will be created at [subdomain].[.Values.domain]' + type: string + aliases: + description: 'If specified, an ingress will be created at [alias].[.Values.domain] for each alias' + type: array + items: + type: string + domain: + description: 'If specified, an ingress will be created at [domain]' + type: string + dependencies: + $ref: '#/components/schemas/ApplicationDependenciesConfig' + description: >- + Application dependencies are used to define what is required in the deployment when + --include (-i) is used. Specify application names in the list. + secured: + description: 'When true, the application is shielded with a getekeeper' + type: boolean + uri_role_mapping: + description: 'Map uri/roles to secure with the Gatekeeper (if `secured: true`)' + type: array + items: + $ref: '#/components/schemas/UriRoleMappingConfig' + secrets: + $ref: '#/components/schemas/SimpleMap' + description: |- + Define secrets will be mounted in the deployment + + Define as + + ```yaml + secrets: + secret_name: 'value' + + ``` + + Values if left empty are randomly generated + use_services: + description: >- + Specify which services this application uses in the frontend to create proxy + ingresses. e.g. + + ``` + + - name: samples + + ``` + type: array + items: + type: string + database: + $ref: '#/components/schemas/DatabaseDeploymentConfig' + description: '' + resources: + description: |- + Application file resources. Maps from deploy/resources folder and mounts as + configmaps + type: array + items: + $ref: '#/components/schemas/FileResourcesConfig' + readinessProbe: + $ref: '#/components/schemas/ApplicationProbe' + description: Kubernetes readiness probe configuration + startupProbe: + $ref: '#/components/schemas/ApplicationProbe' + description: '' + livenessProbe: + $ref: '#/components/schemas/ApplicationProbe' + description: Kubernetes liveness probe configuration + sourceRoot: + $ref: '#/components/schemas/Filename' + description: '' + name: + description: |- + Application's name. Do not edit, the value is automatically set from the + application directory's name + type: string + jupyterhub: + $ref: '#/components/schemas/JupyterHubConfig' + description: | + Configurations specific to jupyterhub. Edit only if your application is + configured as a jupyterhub deployment + accounts: + $ref: '#/components/schemas/ApplicationAccountsConfig' + description: Define specific test users and roles for this application + test: + $ref: '#/components/schemas/ApplicationTestConfig' + description: Enable and configure automated testing for this application. + quotas: + $ref: '#/components/schemas/Quota' + description: '' + env: + description: 'Environmental variables added to all containers (deprecated, please use envmap)' + type: array + items: + $ref: '#/components/schemas/NameValue' + envmap: + $ref: '#/components/schemas/SimpleMap' + description: Environmental variables added to all containers + dockerfile: + $ref: '#/components/schemas/DockerfileConfig' + description: Configuration for the dockerfile used to build the app + additionalProperties: true diff --git a/libraries/models/cloudharness_model/models/__init__.py b/libraries/models/cloudharness_model/models/__init__.py index 488c3e6f6..13238dc74 100644 --- a/libraries/models/cloudharness_model/models/__init__.py +++ b/libraries/models/cloudharness_model/models/__init__.py @@ -17,6 +17,7 @@ from cloudharness_model.models.deployment_auto_artifact_config import DeploymentAutoArtifactConfig from cloudharness_model.models.deployment_resources_conf import DeploymentResourcesConf from cloudharness_model.models.deployment_volume_spec import DeploymentVolumeSpec +from cloudharness_model.models.dockerfile_config import DockerfileConfig from cloudharness_model.models.e2_e_tests_config import E2ETestsConfig from cloudharness_model.models.file_resources_config import FileResourcesConfig from cloudharness_model.models.git_dependency_config import GitDependencyConfig diff --git a/libraries/models/cloudharness_model/models/application_harness_config.py b/libraries/models/cloudharness_model/models/application_harness_config.py index 1921de7b2..264b0ebcd 100644 --- a/libraries/models/cloudharness_model/models/application_harness_config.py +++ b/libraries/models/cloudharness_model/models/application_harness_config.py @@ -9,8 +9,10 @@ from cloudharness_model.models.application_test_config import ApplicationTestConfig from cloudharness_model.models.database_deployment_config import DatabaseDeploymentConfig from cloudharness_model.models.deployment_auto_artifact_config import DeploymentAutoArtifactConfig +from cloudharness_model.models.dockerfile_config import DockerfileConfig from cloudharness_model.models.file_resources_config import FileResourcesConfig from cloudharness_model.models.jupyter_hub_config import JupyterHubConfig +from cloudharness_model.models.name_value import NameValue from cloudharness_model.models.service_auto_artifact_config import ServiceAutoArtifactConfig from cloudharness_model.models.uri_role_mapping_config import UriRoleMappingConfig import re @@ -22,8 +24,10 @@ from cloudharness_model.models.application_test_config import ApplicationTestConfig # noqa: E501 from cloudharness_model.models.database_deployment_config import DatabaseDeploymentConfig # noqa: E501 from cloudharness_model.models.deployment_auto_artifact_config import DeploymentAutoArtifactConfig # noqa: E501 +from cloudharness_model.models.dockerfile_config import DockerfileConfig # noqa: E501 from cloudharness_model.models.file_resources_config import FileResourcesConfig # noqa: E501 from cloudharness_model.models.jupyter_hub_config import JupyterHubConfig # noqa: E501 +from cloudharness_model.models.name_value import NameValue # noqa: E501 from cloudharness_model.models.service_auto_artifact_config import ServiceAutoArtifactConfig # noqa: E501 from cloudharness_model.models.uri_role_mapping_config import UriRoleMappingConfig # noqa: E501 import re # noqa: E501 @@ -34,7 +38,7 @@ class ApplicationHarnessConfig(Model): Do not edit the class manually. """ - def __init__(self, deployment=None, service=None, subdomain=None, aliases=None, domain=None, dependencies=None, secured=None, uri_role_mapping=None, secrets=None, use_services=None, database=None, resources=None, readiness_probe=None, startup_probe=None, liveness_probe=None, source_root=None, name=None, jupyterhub=None, accounts=None, test=None, quotas=None): # noqa: E501 + def __init__(self, deployment=None, service=None, subdomain=None, aliases=None, domain=None, dependencies=None, secured=None, uri_role_mapping=None, secrets=None, use_services=None, database=None, resources=None, readiness_probe=None, startup_probe=None, liveness_probe=None, source_root=None, name=None, jupyterhub=None, accounts=None, test=None, quotas=None, env=None, envmap=None, dockerfile=None): # noqa: E501 """ApplicationHarnessConfig - a model defined in OpenAPI :param deployment: The deployment of this ApplicationHarnessConfig. # noqa: E501 @@ -79,6 +83,12 @@ def __init__(self, deployment=None, service=None, subdomain=None, aliases=None, :type test: ApplicationTestConfig :param quotas: The quotas of this ApplicationHarnessConfig. # noqa: E501 :type quotas: Dict[str, object] + :param env: The env of this ApplicationHarnessConfig. # noqa: E501 + :type env: List[NameValue] + :param envmap: The envmap of this ApplicationHarnessConfig. # noqa: E501 + :type envmap: Dict[str, object] + :param dockerfile: The dockerfile of this ApplicationHarnessConfig. # noqa: E501 + :type dockerfile: DockerfileConfig """ self.openapi_types = { 'deployment': DeploymentAutoArtifactConfig, @@ -101,7 +111,10 @@ def __init__(self, deployment=None, service=None, subdomain=None, aliases=None, 'jupyterhub': JupyterHubConfig, 'accounts': ApplicationAccountsConfig, 'test': ApplicationTestConfig, - 'quotas': Dict[str, object] + 'quotas': Dict[str, object], + 'env': List[NameValue], + 'envmap': Dict[str, object], + 'dockerfile': DockerfileConfig } self.attribute_map = { @@ -125,7 +138,10 @@ def __init__(self, deployment=None, service=None, subdomain=None, aliases=None, 'jupyterhub': 'jupyterhub', 'accounts': 'accounts', 'test': 'test', - 'quotas': 'quotas' + 'quotas': 'quotas', + 'env': 'env', + 'envmap': 'envmap', + 'dockerfile': 'dockerfile' } self._deployment = deployment @@ -149,6 +165,9 @@ def __init__(self, deployment=None, service=None, subdomain=None, aliases=None, self._accounts = accounts self._test = test self._quotas = quotas + self._env = env + self._envmap = envmap + self._dockerfile = dockerfile @classmethod def from_dict(cls, dikt) -> 'ApplicationHarnessConfig': @@ -625,3 +644,70 @@ def quotas(self, quotas: Dict[str, object]): """ self._quotas = quotas + + @property + def env(self) -> List[NameValue]: + """Gets the env of this ApplicationHarnessConfig. + + Environmental variables added to all containers (deprecated, please use envmap) # noqa: E501 + + :return: The env of this ApplicationHarnessConfig. + :rtype: List[NameValue] + """ + return self._env + + @env.setter + def env(self, env: List[NameValue]): + """Sets the env of this ApplicationHarnessConfig. + + Environmental variables added to all containers (deprecated, please use envmap) # noqa: E501 + + :param env: The env of this ApplicationHarnessConfig. + :type env: List[NameValue] + """ + + self._env = env + + @property + def envmap(self) -> Dict[str, object]: + """Gets the envmap of this ApplicationHarnessConfig. + + # noqa: E501 + + :return: The envmap of this ApplicationHarnessConfig. + :rtype: Dict[str, object] + """ + return self._envmap + + @envmap.setter + def envmap(self, envmap: Dict[str, object]): + """Sets the envmap of this ApplicationHarnessConfig. + + # noqa: E501 + + :param envmap: The envmap of this ApplicationHarnessConfig. + :type envmap: Dict[str, object] + """ + + self._envmap = envmap + + @property + def dockerfile(self) -> DockerfileConfig: + """Gets the dockerfile of this ApplicationHarnessConfig. + + + :return: The dockerfile of this ApplicationHarnessConfig. + :rtype: DockerfileConfig + """ + return self._dockerfile + + @dockerfile.setter + def dockerfile(self, dockerfile: DockerfileConfig): + """Sets the dockerfile of this ApplicationHarnessConfig. + + + :param dockerfile: The dockerfile of this ApplicationHarnessConfig. + :type dockerfile: DockerfileConfig + """ + + self._dockerfile = dockerfile diff --git a/libraries/models/cloudharness_model/models/dockerfile_config.py b/libraries/models/cloudharness_model/models/dockerfile_config.py new file mode 100644 index 000000000..4dde44cb3 --- /dev/null +++ b/libraries/models/cloudharness_model/models/dockerfile_config.py @@ -0,0 +1,63 @@ +from datetime import date, datetime # noqa: F401 + +from typing import List, Dict # noqa: F401 + +from cloudharness_model.models.base_model_ import Model +from cloudharness_model import util + + +class DockerfileConfig(Model): + """NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + + Do not edit the class manually. + """ + + def __init__(self, build_args=None): # noqa: E501 + """DockerfileConfig - a model defined in OpenAPI + + :param build_args: The build_args of this DockerfileConfig. # noqa: E501 + :type build_args: Dict[str, object] + """ + self.openapi_types = { + 'build_args': Dict[str, object] + } + + self.attribute_map = { + 'build_args': 'buildArgs' + } + + self._build_args = build_args + + @classmethod + def from_dict(cls, dikt) -> 'DockerfileConfig': + """Returns the dict as a model + + :param dikt: A dict. + :type: dict + :return: The DockerfileConfig of this DockerfileConfig. # noqa: E501 + :rtype: DockerfileConfig + """ + return util.deserialize_model(dikt, cls) + + @property + def build_args(self) -> Dict[str, object]: + """Gets the build_args of this DockerfileConfig. + + # noqa: E501 + + :return: The build_args of this DockerfileConfig. + :rtype: Dict[str, object] + """ + return self._build_args + + @build_args.setter + def build_args(self, build_args: Dict[str, object]): + """Sets the build_args of this DockerfileConfig. + + # noqa: E501 + + :param build_args: The build_args of this DockerfileConfig. + :type build_args: Dict[str, object] + """ + + self._build_args = build_args diff --git a/libraries/models/cloudharness_model/models/harness_main_config.py b/libraries/models/cloudharness_model/models/harness_main_config.py index ea8b74783..9075268b4 100644 --- a/libraries/models/cloudharness_model/models/harness_main_config.py +++ b/libraries/models/cloudharness_model/models/harness_main_config.py @@ -20,7 +20,7 @@ class HarnessMainConfig(Model): Do not edit the class manually. """ - def __init__(self, local=None, secured_gatekeepers=None, domain=None, namespace=None, mainapp=None, registry=None, tag=None, apps=None, env=None, privenv=None, backup=None, name=None, task_images=None, build_hash=None, envmap=None): # noqa: E501 + def __init__(self, local=None, secured_gatekeepers=None, domain=None, namespace=None, mainapp=None, registry=None, tag=None, apps=None, env=None, privenv=None, backup=None, name=None, task_images=None, build_hash=None): # noqa: E501 """HarnessMainConfig - a model defined in OpenAPI :param local: The local of this HarnessMainConfig. # noqa: E501 @@ -51,8 +51,6 @@ def __init__(self, local=None, secured_gatekeepers=None, domain=None, namespace= :type task_images: Dict[str, object] :param build_hash: The build_hash of this HarnessMainConfig. # noqa: E501 :type build_hash: str - :param envmap: The envmap of this HarnessMainConfig. # noqa: E501 - :type envmap: Dict[str, object] """ self.openapi_types = { 'local': bool, @@ -68,8 +66,7 @@ def __init__(self, local=None, secured_gatekeepers=None, domain=None, namespace= 'backup': BackupConfig, 'name': str, 'task_images': Dict[str, object], - 'build_hash': str, - 'envmap': Dict[str, object] + 'build_hash': str } self.attribute_map = { @@ -86,8 +83,7 @@ def __init__(self, local=None, secured_gatekeepers=None, domain=None, namespace= 'backup': 'backup', 'name': 'name', 'task_images': 'task-images', - 'build_hash': 'build_hash', - 'envmap': 'envmap' + 'build_hash': 'build_hash' } self._local = local @@ -104,7 +100,6 @@ def __init__(self, local=None, secured_gatekeepers=None, domain=None, namespace= self._name = name self._task_images = task_images self._build_hash = build_hash - self._envmap = envmap @classmethod def from_dict(cls, dikt) -> 'HarnessMainConfig': @@ -315,7 +310,7 @@ def apps(self, apps: Dict[str, ApplicationConfig]): def env(self) -> List[NameValue]: """Gets the env of this HarnessMainConfig. - Environmental variables added to all pods (deprecated, please use envmap) # noqa: E501 + Environmental variables added to all pods # noqa: E501 :return: The env of this HarnessMainConfig. :rtype: List[NameValue] @@ -326,7 +321,7 @@ def env(self) -> List[NameValue]: def env(self, env: List[NameValue]): """Sets the env of this HarnessMainConfig. - Environmental variables added to all pods (deprecated, please use envmap) # noqa: E501 + Environmental variables added to all pods # noqa: E501 :param env: The env of this HarnessMainConfig. :type env: List[NameValue] @@ -444,26 +439,3 @@ def build_hash(self, build_hash: str): """ self._build_hash = build_hash - - @property - def envmap(self) -> Dict[str, object]: - """Gets the envmap of this HarnessMainConfig. - - # noqa: E501 - - :return: The envmap of this HarnessMainConfig. - :rtype: Dict[str, object] - """ - return self._envmap - - @envmap.setter - def envmap(self, envmap: Dict[str, object]): - """Sets the envmap of this HarnessMainConfig. - - # noqa: E501 - - :param envmap: The envmap of this HarnessMainConfig. - :type envmap: Dict[str, object] - """ - - self._envmap = envmap diff --git a/tools/deployment-cli-tools/ch_cli_tools/skaffold.py b/tools/deployment-cli-tools/ch_cli_tools/skaffold.py index e96d71294..e2fbf1c9b 100644 --- a/tools/deployment-cli-tools/ch_cli_tools/skaffold.py +++ b/tools/deployment-cli-tools/ch_cli_tools/skaffold.py @@ -34,17 +34,28 @@ def get_image_tag(name): builds = {} - def build_artifact(image_name, context_path, requirements=None, dockerfile_path=''): + def build_artifact( + image_name: str, + context_path: str, + requirements: list[str] = None, + dockerfile_path: str = '', + additional_build_args: dict[str, str] = None, + ) -> dict: + build_args = { + 'REGISTRY': helm_values.registry.name, + 'TAG': helm_values.tag, + 'NOCACHE': str(time.time()), + } + + if additional_build_args: + build_args.update(additional_build_args) + artifact_spec = { 'image': image_name, 'context': context_path, 'docker': { 'dockerfile': join(dockerfile_path, 'Dockerfile'), - 'buildArgs': { - 'REGISTRY': helm_values.registry.name, - 'TAG': helm_values.tag, - 'NOCACHE': str(time.time()) - }, + 'buildArgs': build_args, 'ssh': 'default' } } @@ -56,7 +67,13 @@ def build_artifact(image_name, context_path, requirements=None, dockerfile_path= base_images = set() - def process_build_dockerfile(dockerfile_path, root_path, global_context=False, requirements=None, app_name=None): + def process_build_dockerfile( + dockerfile_path: str, + root_path: str, + global_context: bool = False, + requirements: list[str] = None, + app_name: str = None + ) -> None: if app_name is None: app_name = app_name_from_path(basename(dockerfile_path)) app_key = app_name.replace("-", "_") @@ -65,12 +82,15 @@ def process_build_dockerfile(dockerfile_path, root_path, global_context=False, r builds[app_name] = context_path base_images.add(get_image_name(app_name)) + artifacts[app_name] = build_artifact( get_image_tag(app_name), context_path, dockerfile_path=relpath(dockerfile_path, output_path), - requirements=requirements or guess_build_dependencies_from_dockerfile(dockerfile_path) + requirements=requirements or guess_build_dependencies_from_dockerfile(dockerfile_path), + additional_build_args=get_additional_build_args(helm_values, app_key), ) + if app_key in helm_values.apps and helm_values.apps[app_key].harness.dependencies and helm_values.apps[app_key].harness.dependencies.git: artifacts[app_name]['hooks'] = { 'before': [git_clone_hook(conf, context_path) for conf in helm_values.apps[app_key].harness.dependencies.git] @@ -255,4 +275,14 @@ def get_image_tag(name): if not os.path.exists(os.path.dirname(vscode_launch_path)): os.makedirs(os.path.dirname(vscode_launch_path)) with open(vscode_launch_path, 'w') as f: - json.dump(vs_conf, f, indent=2, sort_keys=True) \ No newline at end of file + json.dump(vs_conf, f, indent=2, sort_keys=True) + + +def get_additional_build_args(helm_values: HarnessMainConfig, app_key: str) -> dict[str, str]: + if app_key not in helm_values.apps: + return None + + if not (helm_values.apps[app_key].harness.dockerfile and helm_values.apps[app_key].harness.dockerfile.buildArgs): + return None + + return helm_values.apps[app_key].harness.dockerfile.buildArgs \ No newline at end of file diff --git a/tools/deployment-cli-tools/tests/test_skaffold.py b/tools/deployment-cli-tools/tests/test_skaffold.py index 981aefa58..17c0832d3 100644 --- a/tools/deployment-cli-tools/tests/test_skaffold.py +++ b/tools/deployment-cli-tools/tests/test_skaffold.py @@ -81,6 +81,8 @@ def test_create_skaffold_configuration(): a for a in sk['build']['artifacts'] if a['image'] == 'reg/cloudharness/samples' ) assert os.path.samefile(samples_artifact['context'], join(CLOUDHARNESS_ROOT, 'applications/samples')) + assert 'TEST_ARGUMENT' in samples_artifact['docker']['buildArgs'] + assert samples_artifact['docker']['buildArgs']['TEST_ARGUMENT'] == 'example value' myapp_artifact = next( a for a in sk['build']['artifacts'] if a['image'] == 'reg/cloudharness/myapp')