Skip to content

Commit

Permalink
add jinja for jenkins
Browse files Browse the repository at this point in the history
  • Loading branch information
reschandreas committed Dec 31, 2023
1 parent 66c7fcf commit 65d17f5
Show file tree
Hide file tree
Showing 7 changed files with 227 additions and 358 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/deploy-test.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
name: Deploy to Aeolus Test

on:
workflow_dispatch:
inputs:
docker-tag:
description: 'Docker tag to deploy (e.g. 1.0.0 or latest, default: nightly)'
required: true
default: 'nightly'
branch-name:
description: 'Branch name to deploy (default: develop)'
required: true
default: 'develop'
pull_request:
types: [labeled]

Expand Down
5 changes: 4 additions & 1 deletion cli/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,7 @@ trim_trailing_whitespace = false
indent_size = 2

[*.j2]
indent_size = 2
indent_size = 2

[Jenkinsfile]
indent_size = 2
14 changes: 7 additions & 7 deletions cli/generators/bamboo.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
from typing import List, Any, Optional

import requests
from docker.client import DockerClient # type: ignore
from docker.errors import DockerException # type: ignore
from docker.models.containers import Container # type: ignore
from docker.types.daemon import CancellableStream # type: ignore

import cli_utils
from classes.generated.definitions import Target
Expand All @@ -29,6 +25,10 @@
from classes.pass_metadata import PassMetadata
from cli_utils import logger, utils
from generators.base import BaseGenerator
from docker.client import DockerClient # type: ignore
from docker.errors import DockerException # type: ignore
from docker.models.containers import Container # type: ignore
from docker.types.daemon import CancellableStream # type: ignore


def docker_available() -> bool:
Expand Down Expand Up @@ -111,7 +111,7 @@ def generate_in_api(self, payload: str) -> Optional[str]:
if response.status_code == 200:
logger.info("🔨", "Bamboo YAML Spec file generated", self.output_settings.emoji)
body: dict[str, str] = response.json()
self.result.append(body["result"])
self.result = body["result"]
return body["key"]
logger.error("❌", "Bamboo YAML Spec file generation failed", self.output_settings.emoji)
raise ValueError("Bamboo YAML Spec file generation failed")
Expand Down Expand Up @@ -142,7 +142,7 @@ def generate_in_java(self, base64_str: str) -> None:
raise ValueError("Bamboo YAML Spec file generation failed")
logger.info("🔨", "Bamboo YAML Spec file generated", self.output_settings.emoji)
result_logs: str = process.stdout
self.result.append(result_logs)
self.result = result_logs

def generate_in_docker(self, base64_str: str) -> None:
"""
Expand Down Expand Up @@ -182,7 +182,7 @@ def generate_in_docker(self, base64_str: str) -> None:
logger.info("🔨", "Bamboo YAML Spec file generated", self.output_settings.emoji)
result_logs: str = container.logs(stdout=True, stderr=False).decode("utf-8")
container.remove()
self.result.append(result_logs)
self.result = result_logs

def check(self, content: str) -> bool:
raise NotImplementedError("check_syntax() not implemented")
Expand Down
15 changes: 3 additions & 12 deletions cli/generators/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class BaseGenerator:
input_settings: InputSettings
output_settings: OutputSettings
metadata: PassMetadata
result: typing.List[str]
result: str
final_result: typing.Optional[str]
environment: EnvironmentSchema
key: typing.Optional[str]
Expand All @@ -41,7 +41,7 @@ def __init__(
self.input_settings = input_settings
self.output_settings = output_settings
self.metadata = metadata
self.result = []
self.result = ""
if input_settings.target is None:
raise ValueError("No target specified")
env: typing.Optional[EnvironmentSchema] = utils.get_ci_environment(
Expand All @@ -67,14 +67,6 @@ def __init__(
self.needs_lifecycle_parameter = self.__needs_lifecycle_parameter()
self.needs_subshells = self.has_multiple_steps

def add_line(self, indentation: int, line: str) -> None:
"""
Add a line to the result.
:param indentation: indentation level
:param line: line to add
"""
self.result.append(" " * indentation + line)

def add_repository_urls_to_environment(self) -> None:
"""
Some systems don't offer a way to access repository urls in the CI file.
Expand Down Expand Up @@ -160,8 +152,7 @@ def generate(self) -> str:
"""
Generate the CI file.
"""
self.final_result = "\n".join(self.result)
return self.final_result
return self.result

def run(self, job_id: str) -> None:
"""
Expand Down
35 changes: 5 additions & 30 deletions cli/generators/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,9 @@
import re
import subprocess
import tempfile
import typing
from typing import List, Optional

from docker.client import DockerClient # type: ignore
from docker.models.containers import Container # type: ignore
from docker.types.daemon import CancellableStream # type: ignore
from jinja2 import Environment, FileSystemLoader
from jinja2 import Environment, FileSystemLoader, Template

from classes.generated.definitions import ScriptAction, Repository, Target
from classes.generated.windfile import WindFile
Expand All @@ -18,6 +14,9 @@
from classes.pass_metadata import PassMetadata
from cli_utils import logger, utils
from generators.base import BaseGenerator
from docker.client import DockerClient # type: ignore
from docker.models.containers import Container # type: ignore
from docker.types.daemon import CancellableStream # type: ignore


class CliGenerator(BaseGenerator):
Expand All @@ -29,7 +28,7 @@ class CliGenerator(BaseGenerator):

initial_directory_variable: str = "AEOLUS_INITIAL_DIRECTORY"

template: Optional[typing.Any] = None
template: Optional[Template] = None

def __init__(
self, windfile: WindFile, input_settings: InputSettings, output_settings: OutputSettings, metadata: PassMetadata
Expand Down Expand Up @@ -76,30 +75,6 @@ def handle_step(self, name: str, step: ScriptAction, call: bool) -> None:
self.after_results[step.name] = [result for result in step.results if result.before]
return None

def add_environment(self, step: ScriptAction) -> None:
"""
Add environment variables to the step.
:param step: to add environment variables to
"""
if step.environment:
for env_var in step.environment.root.root:
env_value: typing.Any = step.environment.root.root[env_var]
if isinstance(env_value, List):
env_value = " ".join(env_value)
self.result.append(f'export {env_var}="' f'{env_value}"')

def add_parameters(self, step: ScriptAction) -> None:
"""
Add parameters to the step.
:param step: to add parameters to
"""
if step.parameters is not None:
for parameter in step.parameters.root.root:
value: typing.Any = step.parameters.root.root[parameter]
if isinstance(value, List):
value = " ".join(value)
self.add_line(indentation=2, line=f'{parameter}="' f'{value}"')

def check(self, content: str) -> bool:
"""
Check the generated bash file for syntax errors.
Expand Down
Loading

0 comments on commit 65d17f5

Please sign in to comment.