feat: add docker config for dfinit (#358)
Signed-off-by: Gaius <gaius.qi@gmail.com>
This commit is contained in:
parent
4f69f3999c
commit
0cd452f33b
|
|
@ -43,6 +43,12 @@ fn default_container_runtime_containerd_config_path() -> PathBuf {
|
|||
PathBuf::from("/etc/containerd/config.toml")
|
||||
}
|
||||
|
||||
// default_container_runtime_docker_config_path is the default docker configuration path.
|
||||
#[inline]
|
||||
fn default_container_runtime_docker_config_path() -> PathBuf {
|
||||
PathBuf::from("/etc/docker/daemon.json")
|
||||
}
|
||||
|
||||
// default_proxy_addr is the default proxy address of dfdaemon.
|
||||
#[inline]
|
||||
fn default_proxy_addr() -> String {
|
||||
|
|
@ -95,12 +101,27 @@ pub struct Containerd {
|
|||
pub registries: Vec<Registry>,
|
||||
}
|
||||
|
||||
// Docker is the docker configuration for dfinit.
|
||||
#[derive(Debug, Clone, Default, Validate, Deserialize)]
|
||||
#[serde(default, rename_all = "camelCase")]
|
||||
pub struct Docker {
|
||||
// enable is a flag to enable docker feature.
|
||||
pub enable: bool,
|
||||
|
||||
// config_path is the path of docker configuration file.
|
||||
#[serde(default = "default_container_runtime_docker_config_path")]
|
||||
pub config_path: PathBuf,
|
||||
}
|
||||
|
||||
// ContainerRuntime is the container runtime configuration for dfinit.
|
||||
#[derive(Debug, Clone, Default, Validate, Deserialize)]
|
||||
#[serde(default, rename_all = "camelCase")]
|
||||
pub struct ContainerRuntime {
|
||||
// containerd is the containerd configuration.
|
||||
pub containerd: Containerd,
|
||||
|
||||
// docker is the docker configuration.
|
||||
pub docker: Docker,
|
||||
}
|
||||
|
||||
// Proxy is the proxy server configuration for dfdaemon.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,57 @@
|
|||
/*
|
||||
* Copyright 2024 The Dragonfly Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
use dragonfly_client_config::dfinit;
|
||||
use dragonfly_client_core::{Error, Result};
|
||||
use tracing::info;
|
||||
|
||||
// Docker represents the docker runtime manager.
|
||||
pub struct Docker {
|
||||
// config is the configuration for initializing
|
||||
// runtime environment for the dfdaemon.
|
||||
config: dfinit::Docker,
|
||||
|
||||
// proxy_config is the configuration for the dfdaemon's proxy server.
|
||||
proxy_config: dfinit::Proxy,
|
||||
}
|
||||
|
||||
// Docker implements the docker runtime manager.
|
||||
impl Docker {
|
||||
// new creates a new docker runtime manager.
|
||||
pub fn new(config: dfinit::Docker, proxy_config: dfinit::Proxy) -> Self {
|
||||
Self {
|
||||
config,
|
||||
proxy_config,
|
||||
}
|
||||
}
|
||||
|
||||
// TODO Implement the run method for Docker.
|
||||
//
|
||||
// run runs the docker runtime to initialize
|
||||
// runtime environment for the dfdaemon.
|
||||
pub async fn run(&self) -> Result<()> {
|
||||
info!(
|
||||
"docker feature is enabled, proxy_addr: {}",
|
||||
self.proxy_config.addr
|
||||
);
|
||||
Err(Error::Unimplemented())
|
||||
}
|
||||
|
||||
// is_enabled returns true if docker feature is enabled.
|
||||
pub fn is_enabled(&self) -> bool {
|
||||
self.config.enable
|
||||
}
|
||||
}
|
||||
|
|
@ -20,11 +20,15 @@ use std::sync::Arc;
|
|||
use tracing::info;
|
||||
|
||||
pub mod containerd;
|
||||
pub mod docker;
|
||||
|
||||
// ContainerRuntime represents the container runtime manager.
|
||||
pub struct ContainerRuntime {
|
||||
// containerd is the containerd runtime manager.
|
||||
containerd: containerd::Containerd,
|
||||
|
||||
// docker is the docker runtime manager.
|
||||
docker: docker::Docker,
|
||||
}
|
||||
|
||||
// ContainerRuntime implements the container runtime manager.
|
||||
|
|
@ -36,18 +40,28 @@ impl ContainerRuntime {
|
|||
config.container_runtime.containerd.clone(),
|
||||
config.proxy.clone(),
|
||||
),
|
||||
docker: docker::Docker::new(
|
||||
config.container_runtime.docker.clone(),
|
||||
config.proxy.clone(),
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
// run runs the container runtime to initialize runtime environment for the dfdaemon.
|
||||
pub async fn run(&self) -> Result<()> {
|
||||
// If containerd is enabled, override the default containerd
|
||||
// configuration and restart containerd.
|
||||
// configuration.
|
||||
if self.containerd.is_enabled() {
|
||||
info!("containerd feature is enabled");
|
||||
self.containerd.run().await?;
|
||||
}
|
||||
|
||||
// If docker is enabled, override the default docker configuration.
|
||||
if self.docker.is_enabled() {
|
||||
info!("docker feature is enabled");
|
||||
self.docker.run().await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue