Add deployer config
This commit is contained in:
parent
0f93d30d54
commit
7110021b54
@ -13,8 +13,9 @@
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http:#www.gnu.org/licenses/>.
|
||||
|
||||
from pathlib import Path
|
||||
from python_on_whales import DockerClient, DockerException
|
||||
from app.deploy.deployer import Deployer, DeployerException
|
||||
from app.deploy.deployer import Deployer, DeployerException, DeployerConfigGenerator
|
||||
|
||||
|
||||
class DockerDeployer(Deployer):
|
||||
@ -65,3 +66,14 @@ class DockerDeployer(Deployer):
|
||||
return self.docker.run(image=image, command=command, user=user, volumes=volumes, entrypoint=entrypoint)
|
||||
except DockerException as e:
|
||||
raise DeployerException(e)
|
||||
|
||||
|
||||
class DockerDeployerConfigGenerator(DeployerConfigGenerator):
|
||||
config_file_name: str = "kind-config.yml"
|
||||
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
# Nothing needed at present for the docker deployer
|
||||
def generate(self, deployment_dir: Path):
|
||||
pass
|
||||
|
@ -14,6 +14,7 @@
|
||||
# along with this program. If not, see <http:#www.gnu.org/licenses/>.
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
class Deployer(ABC):
|
||||
@ -50,3 +51,10 @@ class Deployer(ABC):
|
||||
class DeployerException(Exception):
|
||||
def __init__(self, *args: object) -> None:
|
||||
super().__init__(*args)
|
||||
|
||||
|
||||
class DeployerConfigGenerator(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def generate(self, deployment_dir: Path):
|
||||
pass
|
||||
|
@ -13,11 +13,20 @@
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http:#www.gnu.org/licenses/>.
|
||||
|
||||
from app.deploy.k8s.deploy_k8s import K8sDeployer
|
||||
from app.deploy.compose.deploy_docker import DockerDeployer
|
||||
from app.deploy.k8s.deploy_k8s import K8sDeployer, K8sDeployerConfigGenerator
|
||||
from app.deploy.compose.deploy_docker import DockerDeployer, DockerDeployerConfigGenerator
|
||||
|
||||
|
||||
def getDeployer(type, compose_files, compose_project_name, compose_env_file):
|
||||
def getDeployerConfigGenerator(type: str):
|
||||
if type == "compose" or type is None:
|
||||
return DockerDeployerConfigGenerator()
|
||||
elif type == "k8s":
|
||||
return K8sDeployerConfigGenerator()
|
||||
else:
|
||||
print(f"ERROR: deploy-to {type} is not valid")
|
||||
|
||||
|
||||
def getDeployer(type: str, compose_files, compose_project_name, compose_env_file):
|
||||
if type == "compose" or type is None:
|
||||
return DockerDeployer(compose_files, compose_project_name, compose_env_file)
|
||||
elif type == "k8s":
|
||||
|
@ -24,6 +24,7 @@ import sys
|
||||
from app.util import (get_stack_file_path, get_parsed_deployment_spec, get_parsed_stack_config, global_options, get_yaml,
|
||||
get_pod_list, get_pod_file_path, pod_has_scripts, get_pod_script_paths, get_plugin_code_paths)
|
||||
from app.deploy.deploy_types import DeploymentContext, DeployCommandContext, LaconicStackSetupCommand
|
||||
from app.deploy.deployer_factory import getDeployerConfigGenerator
|
||||
|
||||
|
||||
def _make_default_deployment_dir():
|
||||
@ -366,6 +367,9 @@ def create(ctx, spec_file, deployment_dir, network_dir, initial_peers):
|
||||
deployment_command_context = ctx.obj
|
||||
deployment_command_context.stack = stack_name
|
||||
deployment_context = DeploymentContext(Path(deployment_dir), deployment_command_context)
|
||||
# Call the deployer to generate any deployer-specific files (e.g. for kind)
|
||||
deployer_config_generator = getDeployerConfigGenerator(parsed_spec["deploy-to"])
|
||||
deployer_config_generator.generate(deployment_dir)
|
||||
call_stack_deploy_create(deployment_context, [network_dir, initial_peers])
|
||||
|
||||
|
||||
|
@ -13,11 +13,12 @@
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http:#www.gnu.org/licenses/>.
|
||||
|
||||
from pathlib import Path
|
||||
from kubernetes import client, config
|
||||
|
||||
from app.deploy.deployer import Deployer
|
||||
from app.deploy.deployer import Deployer, DeployerConfigGenerator
|
||||
from app.deploy.k8s.helpers import create_cluster, destroy_cluster, load_images_into_kind
|
||||
from app.deploy.k8s.helpers import pods_in_deployment, log_stream_from_string
|
||||
from app.deploy.k8s.helpers import pods_in_deployment, log_stream_from_string, generate_kind_config
|
||||
from app.deploy.k8s.cluster_info import ClusterInfo
|
||||
from app.opts import opts
|
||||
|
||||
@ -108,3 +109,18 @@ class K8sDeployer(Deployer):
|
||||
def run(self, image, command, user, volumes, entrypoint=None):
|
||||
# We need to figure out how to do this -- check why we're being called first
|
||||
pass
|
||||
|
||||
|
||||
class K8sDeployerConfigGenerator(DeployerConfigGenerator):
|
||||
config_file_name: str = "kind-config.yml"
|
||||
|
||||
def __init__(self) -> None:
|
||||
super().__init__()
|
||||
|
||||
def generate(self, deployment_dir: Path):
|
||||
# Check the file isn't already there
|
||||
# Get the config file contents
|
||||
content = generate_kind_config()
|
||||
# Write the file
|
||||
with open(deployment_dir, "w") as output_file:
|
||||
output_file.write(content)
|
||||
|
@ -102,3 +102,13 @@ def volumes_for_pod_files(parsed_pod_files):
|
||||
volume = client.V1Volume(name=volume_name, persistent_volume_claim=claim)
|
||||
result.append(volume)
|
||||
return result
|
||||
|
||||
|
||||
def generate_kind_config():
|
||||
return (
|
||||
'''kind: Cluster
|
||||
apiVersion: kind.x-k8s.io/v1alpha4
|
||||
nodes:
|
||||
- role: control-plane
|
||||
'''
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user