From 970657b859e1ac135606025d671cfb4fc0ccf702 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20F=2E=20D=C3=BCllmann?= Date: Fri, 10 Jul 2020 20:31:39 +0200 Subject: [PATCH] Added implementation to be able to deploy to AWS and the corresponding getting started notes. --- ctt-server/models/deployment.py | 38 ++++++++++++++++++++------------ ctt-server/util/configuration.py | 2 +- docs/getting-started.rst | 16 ++++++++++++++ 3 files changed, 41 insertions(+), 15 deletions(-) diff --git a/ctt-server/models/deployment.py b/ctt-server/models/deployment.py index d0d0373..2210f77 100644 --- a/ctt-server/models/deployment.py +++ b/ctt-server/models/deployment.py @@ -10,7 +10,7 @@ from db_orm.database import Base, db_session from models.testartifact import TestArtifact from models.abstract_model import AbstractModel -from util.configuration import BasePath, DropPolicies, DockerWorkaround +from util.configuration import BasePath, DropPolicies, FaasScenario from util.tosca_helper import Csar ip_pattern = re.compile('([1][0-9][0-9].|^[2][5][0-5].|^[2][0-4][0-9].|^[1][0-9][0-9].|^[0-9][0-9].|^[0-9].)' @@ -88,20 +88,28 @@ def deploy(self): info(f'Deploying TI {str(entry_definition)} with opera in folder {str(self.ti_storage_path)}.') subprocess.call(['opera', 'deploy', entry_definition], cwd=self.ti_storage_path) - if not DockerWorkaround: + time.sleep(30) + + envFaasScenario = os.getenv('CTT_FAAS_ENABLED') + if (envFaasScenario and envFaasScenario == "1") or FaasScenario: # FaaS scenario - pass + deployed_systems = Deployment.deployment_workaround(exclude_sut=True) + self.sut_hostname = self.__test_artifact.policy_yaml['properties']['hostname'] + self.ti_hostname = deployed_systems['ti'] else: - time.sleep(30) - deployed_systems = Deployment.deployment_workaround() + deployed_systems = Deployment.deployment_workaround(exclude_sut=False) self.sut_hostname = deployed_systems['sut'] self.ti_hostname = deployed_systems['ti'] - db_session.add(self) - db_session.commit() + + db_session.add(self) + db_session.commit() @classmethod - def deployment_workaround(cls): + def deployment_workaround(cls, exclude_sut): + result_set = {} + + # Determine Docker network that is used on the current machine docker_network = subprocess.getoutput("docker network ls | grep compose | head -n1 | awk '{print $2}'") if docker_network: current_app.logger.info(f'Automatically determined docker network {docker_network}') @@ -110,20 +118,22 @@ def deployment_workaround(cls): current_app.logger.info( f'Docker network could not be determined automatically. Falling back to {docker_network}') - sut_docker_name = 'docker-compose_edge-router_1' - if os.path.isfile('/.dockerenv'): subprocess.call(['docker', 'network', 'connect', docker_network, 'RadonCTT']) - sut_ip = Deployment.workaround_parse_ip(docker_network, sut_docker_name) + if not exclude_sut: + sut_docker_name = 'docker-compose_edge-router_1' + sut_ip = Deployment.workaround_parse_ip(docker_network, sut_docker_name) + current_app.logger.info(f'Determined SUT IP-address: {sut_ip}.') + result_set['sut'] = sut_ip ti_docker_name = 'CTTAgent' subprocess.call(['docker', 'network', 'connect', docker_network, ti_docker_name]) ti_ip = Deployment.workaround_parse_ip(docker_network, ti_docker_name) - - current_app.logger.info(f'Determined SUT IP-address: {sut_ip}.') current_app.logger.info(f'Determined TI IP-address: {ti_ip}.') - return {'sut': sut_ip, 'ti': ti_ip} + result_set['ti'] = ti_ip + + return result_set @classmethod def workaround_parse_ip(cls, docker_network, docker_name): diff --git a/ctt-server/util/configuration.py b/ctt-server/util/configuration.py index cb0f64c..08963d8 100644 --- a/ctt-server/util/configuration.py +++ b/ctt-server/util/configuration.py @@ -3,4 +3,4 @@ SUTFile = 'sut_tosca.yaml' TIFile = 'ti_tosca.yaml' DropPolicies = True -DockerWorkaround = True \ No newline at end of file +FaasScenario = True \ No newline at end of file diff --git a/docs/getting-started.rst b/docs/getting-started.rst index 17bcb50..5971b92 100644 --- a/docs/getting-started.rst +++ b/docs/getting-started.rst @@ -23,6 +23,13 @@ The easiest way to start CTT is by invoking the publicly available Docker contai docker run -t -i --name RadonCTT -p 18080:18080 -v /var/run/docker.sock:/var/run/docker.sock radonconsortium/radon-ctt:latest +In order to be able to deploy to AWS (e.g., use the ImageResize example), you need to enable this feature and pass your AWS credentials like shown below: + +:: + + docker run --rm -t -i -e CTT_FAAS_ENABLED="1" -e AWS_ACCESS_KEY_ID="" -e AWS_SECRET_ACCESS_KEY="" --name RadonCTT -p 18080:18080 -v /var/run/docker.sock:/var/run/docker.sock radonconsortium/radon-ctt:latest + + To check whether the CTT server has started properly, you should be able to access the OpenAPI-based interface via a web browser: http://localhost:18080/RadonCTT/ui/ However, for the remaining step, we will interact with the CTT server via `Curl `_. @@ -50,6 +57,15 @@ The response includes a UUID for the project that is required for the further in "uuid": "d3cb9d75-73df-422e-9575-76e7a5775f8e" } + +Similarly, you can use the ImageResize example repository which uses AWS to deploy a example FaaS application including two S3 buckets and one Lambda function: + +:: + + curl -X POST "http://localhost:18080/RadonCTT/project" -H "accept: */*" -H "Content-Type: application/json" -d "{\"name\":\"ImageResize\",\"repository_url\":\"https://github.com/radon-h2020/demo-ctt-imageresize.git\"}" + + + Generating Artifacts ~~~~~~~~~~~~~~~~~~~~