feat: initialize dfinit crate (#330)

Signed-off-by: Gaius <gaius.qi@gmail.com>
This commit is contained in:
Gaius 2024-03-18 17:17:38 +08:00 committed by GitHub
parent 19614cb861
commit aa9f8f7306
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 172 additions and 14 deletions

View File

@ -69,6 +69,7 @@ jobs:
uses: docker/build-push-action@v5 uses: docker/build-push-action@v5
with: with:
context: . context: .
file: dragonfly-client/Dockerfile
platforms: linux/amd64,linux/arm64 platforms: linux/amd64,linux/arm64
labels: |- labels: |-
org.opencontainers.image.source=https://github.com/${{ github.repository }} org.opencontainers.image.source=https://github.com/${{ github.repository }}
@ -83,6 +84,25 @@ jobs:
cache-from: type=local,src=/tmp/.buildx-cache cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new cache-to: type=local,dest=/tmp/.buildx-cache-new
- name: Push Dfinit to Registry
uses: docker/build-push-action@v5
with:
context: .
file: dragonfly-client-init/Dockerfile
platforms: linux/amd64,linux/arm64
labels: |-
org.opencontainers.image.source=https://github.com/${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }}
build-args: |
GITVERSION=git-${{ steps.vars.outputs.git_revision }}
VERSION=${{ steps.get_version.outputs.VERSION }}
tags: |
dragonflyoss/dfinit:${{ steps.get_version.outputs.VERSION }}
ghcr.io/${{ env.IMAGE_REPOSITORY }}/dfinit:${{ steps.get_version.outputs.VERSION }}
push: true
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
- name: Move cache - name: Move cache
run: | run: |
rm -rf /tmp/.buildx-cache rm -rf /tmp/.buildx-cache

View File

@ -87,6 +87,15 @@ jobs:
tar -czf "$dirname.tar.gz" "$dirname" tar -czf "$dirname.tar.gz" "$dirname"
echo "DFSTORE_ASSET=$dirname.tar.gz" >> $GITHUB_ENV echo "DFSTORE_ASSET=$dirname.tar.gz" >> $GITHUB_ENV
- name: Build archive dfinit
shell: bash
run: |
binary_name="dfinit"
dirname="$binary_name-${{ env.VERSION }}-${{ matrix.target }}"
mv "target/${{ matrix.target }}/release/$binary_name" "$dirname"
tar -czf "$dirname.tar.gz" "$dirname"
echo "DFSTORE_ASSET=$dirname.tar.gz" >> $GITHUB_ENV
- name: Release - name: Release
uses: softprops/action-gh-release@v2 uses: softprops/action-gh-release@v2
with: with:

20
Cargo.lock generated
View File

@ -601,7 +601,7 @@ dependencies = [
[[package]] [[package]]
name = "dragonfly-client" name = "dragonfly-client"
version = "0.1.22" version = "0.1.23"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bytes", "bytes",
@ -660,7 +660,7 @@ dependencies = [
[[package]] [[package]]
name = "dragonfly-client-backend" name = "dragonfly-client-backend"
version = "0.1.22" version = "0.1.23"
dependencies = [ dependencies = [
"dragonfly-client-core", "dragonfly-client-core",
"futures", "futures",
@ -673,7 +673,7 @@ dependencies = [
[[package]] [[package]]
name = "dragonfly-client-config" name = "dragonfly-client-config"
version = "0.1.22" version = "0.1.23"
dependencies = [ dependencies = [
"dragonfly-client-core", "dragonfly-client-core",
"home", "home",
@ -691,7 +691,7 @@ dependencies = [
[[package]] [[package]]
name = "dragonfly-client-core" name = "dragonfly-client-core"
version = "0.1.22" version = "0.1.23"
dependencies = [ dependencies = [
"headers 0.4.0", "headers 0.4.0",
"http 1.1.0", "http 1.1.0",
@ -713,9 +713,17 @@ dependencies = [
"warp", "warp",
] ]
[[package]]
name = "dragonfly-client-init"
version = "0.1.23"
dependencies = [
"clap",
"dragonfly-client-config",
]
[[package]] [[package]]
name = "dragonfly-client-storage" name = "dragonfly-client-storage"
version = "0.1.22" version = "0.1.23"
dependencies = [ dependencies = [
"base16ct", "base16ct",
"chrono", "chrono",
@ -737,7 +745,7 @@ dependencies = [
[[package]] [[package]]
name = "dragonfly-client-util" name = "dragonfly-client-util"
version = "0.1.22" version = "0.1.23"
dependencies = [ dependencies = [
"dragonfly-api", "dragonfly-api",
"dragonfly-client-core", "dragonfly-client-core",

View File

@ -1,9 +1,9 @@
[workspace] [workspace]
resolver = "2" resolver = "2"
members = ["dragonfly-client", "dragonfly-client-backend","dragonfly-client-config","dragonfly-client-core", "dragonfly-client-storage", "dragonfly-client-util"] members = ["dragonfly-client", "dragonfly-client-backend","dragonfly-client-config","dragonfly-client-core", "dragonfly-client-init", "dragonfly-client-storage", "dragonfly-client-util"]
[workspace.package] [workspace.package]
version = "0.1.22" version = "0.1.23"
authors = ["The Dragonfly Developers"] authors = ["The Dragonfly Developers"]
homepage = "https://d7y.io/" homepage = "https://d7y.io/"
repository = "https://github.com/dragonflyoss/client.git" repository = "https://github.com/dragonflyoss/client.git"
@ -13,11 +13,12 @@ readme = "README.md"
edition = "2021" edition = "2021"
[workspace.dependencies] [workspace.dependencies]
dragonfly-client-core = { path = "dragonfly-client-core", version = "0.1.22" } dragonfly-client-core = { path = "dragonfly-client-core", version = "0.1.23" }
dragonfly-client-config = { path = "dragonfly-client-config", version = "0.1.22" } dragonfly-client-config = { path = "dragonfly-client-config", version = "0.1.23" }
dragonfly-client-storage = { path = "dragonfly-client-storage", version = "0.1.22" } dragonfly-client-storage = { path = "dragonfly-client-storage", version = "0.1.23" }
dragonfly-client-backend = { path = "dragonfly-client-backend", version = "0.1.22" } dragonfly-client-backend = { path = "dragonfly-client-backend", version = "0.1.23" }
dragonfly-client-util = { path = "dragonfly-client-util", version = "0.1.21" } dragonfly-client-util = { path = "dragonfly-client-util", version = "0.1.23" }
dragonfly-client-init = { path = "dragonfly-client-init", version = "0.1.23" }
thiserror = "1.0" thiserror = "1.0"
dragonfly-api = "2.0.106" dragonfly-api = "2.0.106"
reqwest = { version = "0.11.25", features = ["stream", "native-tls", "rustls-tls"] } reqwest = { version = "0.11.25", features = ["stream", "native-tls", "rustls-tls"] }
@ -51,6 +52,7 @@ humantime = "2.1.0"
prost-wkt-types = "0.4" prost-wkt-types = "0.4"
chrono = { version = "0.4.34", features = ["serde"] } chrono = { version = "0.4.34", features = ["serde"] }
openssl = { version = "0.10", features = ["vendored"] } openssl = { version = "0.10", features = ["vendored"] }
clap = { version = "4.5.1", features = [ "derive" ] }
[profile.bench] [profile.bench]
debug = true debug = true

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
use dragonfly_client_core::Result; use dragonfly_client_core::Result;
use local_ip_address::{local_ip, local_ipv6}; use local_ip_address::{local_ip, local_ipv6};
use regex::Regex; use regex::Regex;

View File

@ -0,0 +1,31 @@
/*
* 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 std::path::PathBuf;
// NAME is the name of dfinit.
pub const NAME: &str = "dfinit";
// default_dfinit_config_path is the default config path for dfinit.
#[inline]
pub fn default_dfinit_config_path() -> PathBuf {
super::default_config_dir().join("dfinit.yaml")
}
// default_dfinit_log_dir is the default log directory for dfinit.
pub fn default_dfinit_log_dir() -> PathBuf {
super::default_log_dir().join(NAME)
}

View File

@ -18,6 +18,7 @@ use std::path::PathBuf;
pub mod dfdaemon; pub mod dfdaemon;
pub mod dfget; pub mod dfget;
pub mod dfinit;
pub mod dfstore; pub mod dfstore;
// SERVICE_NAME is the name of the service. // SERVICE_NAME is the name of the service.

View File

@ -0,0 +1,19 @@
[package]
name = "dragonfly-client-init"
description = "Initialize runtime environment of the dfdaemon"
version.workspace = true
authors.workspace = true
homepage.workspace = true
repository.workspace = true
keywords.workspace = true
license.workspace = true
readme.workspace = true
edition.workspace = true
[[bin]]
name = "dfinit"
path = "src/bin/main.rs"
[dependencies]
dragonfly-client-config.workspace = true
clap.workspace = true

View File

@ -0,0 +1,21 @@
FROM rust:1.75.0 as builder
RUN apt-get update && apt-get install -y openssl libclang-dev pkg-config protobuf-compiler
WORKDIR /app/client
COPY Cargo.toml ./
COPY Cargo.lock ./
COPY dragonfly-client-init/Cargo.toml ./dragonfly-client-init/Cargo.toml
COPY dragonfly-client-init/src ./dragonfly-client-init/src
RUN cargo build --release --verbose
FROM debian:bookworm-slim
RUN apt-get update && apt-get install -y --no-install-recommends wget \
&& rm -rf /var/lib/apt/lists/*
COPY --from=builder /app/client/target/release/dfinit /usr/local/bin/dfinit
ENTRYPOINT ["/usr/local/bin/dfinit"]

View File

@ -0,0 +1,46 @@
/*
* 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 clap::Parser;
use dragonfly_client_config::dfinit;
use std::path::PathBuf;
#[derive(Debug, Parser)]
#[command(
name = dfinit::NAME,
author,
version,
about = "dfinit is a command line for initializing runtime environment of the dfdaemon",
long_about = "A command line for initializing runtime environment of the dfdaemon, \
For example, if the container's runtime is containerd, then dfinit will modify the mirror configuration of containerd and restart the containerd service. \
It also supports to change configuration of the other container's runtime, such as cri-o, docker, etc."
)]
struct Args {
#[arg(
short = 'c',
long = "config",
default_value_os_t = dfinit::default_dfinit_config_path(),
help = "Specify config file to use")
]
config: PathBuf,
}
fn main() {
// Parse command line arguments.
let args = Args::parse();
println!("{:?}", args);
}

View File

@ -51,7 +51,7 @@ reqwest.workspace = true
url.workspace = true url.workspace = true
http.workspace = true http.workspace = true
openssl.workspace = true openssl.workspace = true
clap = { version = "4.5.1", features = [ "derive" ] } clap.workspace = true
tracing-log = "0.1" tracing-log = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] } tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tracing-appender = "0.2.3" tracing-appender = "0.2.3"