Improved parallel building

This commit is contained in:
Lorenzo Venerandi
2025-01-29 18:43:49 +01:00
parent 0490884213
commit 8246538ac5
3 changed files with 52 additions and 10 deletions

12
project/tasks/danano.go Normal file
View File

@@ -0,0 +1,12 @@
package main
import (
)
func exec_task(arg string) string{
response := "Ciao danano " + arg
return response
}

View File

@@ -1,11 +1,21 @@
project_name: Test
tasks:
- name: Data Aggregation # Displayed name
type: processor_nats # Used to select template
code: task1.go # Go code file inside tasks/ dir
target: # Where the component will be deployed
- name: Data Aggregation
type: producer_nats
code: task1.go
targets:
- edge
- cloud
source_topic: temp_sensor # Source NATS topic
dest_topic: aggregated_data # Destination NATS topic
component_name: data_aggregation # Component name displayed in the OCI artifact
source_topic: temp_sensor
dest_topic: aggregated_data
component_name: data_aggregation
version: 1.0.0
- name: Daniele pelato
type: processor_nats
code: danano.go
targets:
- edge
source_topic: temp_sensor
dest_topic: sexo
component_name: liscio
version: 1.0.0

View File

@@ -10,6 +10,8 @@ def build_project(project_dir, reg_user, reg_pass, detached):
logging.error(f"Project directory is not valid")
return
print('Building WASM components')
# Docker client
client = docker.from_env()
@@ -17,6 +19,8 @@ def build_project(project_dir, reg_user, reg_pass, detached):
try:
client.images.get("wash-build-image:latest")
except docker.errors.ImageNotFound:
print(' - Building wash-build-image from Dockerfile...')
client.images.build(
path="src/wasm_builder/docker",
dockerfile="build.Dockerfile",
@@ -24,21 +28,34 @@ def build_project(project_dir, reg_user, reg_pass, detached):
)
try:
wait_list = []
for task in os.listdir(f"{project_dir}/gen"):
__build_wasm(f"{project_dir}/gen/{task}", client, reg_user, reg_pass, detached)
__build_wasm(f"{project_dir}/gen/{task}", client, reg_user, reg_pass, detached, wait_list)
if detached == 'True':
print('Waiting for build to finish...')
for container in wait_list:
try:
client.containers.get(container).wait()
except Exception:
continue
except Exception as e:
logging.error(f"Error building project: {e}")
return
print("Project built successfully")
def __build_wasm(task_dir, client, reg_user, reg_pass, detached):
def __build_wasm(task_dir, client, reg_user, reg_pass, detached, wait_list):
wadm = __parse_yaml(f"{task_dir}/wadm.yaml")
path = os.path.abspath(task_dir)
oci_url = wadm['spec']['components'][0]['properties']['image']
name = wadm['spec']['components'][0]['name'] + '-build'
# Build the wasm module
print(f" - Building WASM module {oci_url}")
@@ -49,11 +66,14 @@ def __build_wasm(task_dir, client, reg_user, reg_pass, detached):
f'WASH_REG_PASSWORD={reg_pass}'],
volumes={path: {'bind': '/app', 'mode': 'rw'}},
remove=True,
detach=True
detach=True,
name=name
)
if detached == 'False':
container.wait()
else:
wait_list.append(name)
def __parse_yaml(yaml_file):