diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 24f297a0..a80f88ef 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -69,6 +69,7 @@ jobs: uses: docker/build-push-action@v5 with: context: . + file: dragonfly-client/Dockerfile platforms: linux/amd64,linux/arm64 labels: |- org.opencontainers.image.source=https://github.com/${{ github.repository }} @@ -83,6 +84,25 @@ jobs: cache-from: type=local,src=/tmp/.buildx-cache 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 run: | rm -rf /tmp/.buildx-cache diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f3b01f4f..3b296b2d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -87,6 +87,15 @@ jobs: tar -czf "$dirname.tar.gz" "$dirname" 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 uses: softprops/action-gh-release@v2 with: diff --git a/Cargo.lock b/Cargo.lock index 97ed8cdd..e29ac7af 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -601,7 +601,7 @@ dependencies = [ [[package]] name = "dragonfly-client" -version = "0.1.22" +version = "0.1.23" dependencies = [ "anyhow", "bytes", @@ -660,7 +660,7 @@ dependencies = [ [[package]] name = "dragonfly-client-backend" -version = "0.1.22" +version = "0.1.23" dependencies = [ "dragonfly-client-core", "futures", @@ -673,7 +673,7 @@ dependencies = [ [[package]] name = "dragonfly-client-config" -version = "0.1.22" +version = "0.1.23" dependencies = [ "dragonfly-client-core", "home", @@ -691,7 +691,7 @@ dependencies = [ [[package]] name = "dragonfly-client-core" -version = "0.1.22" +version = "0.1.23" dependencies = [ "headers 0.4.0", "http 1.1.0", @@ -713,9 +713,17 @@ dependencies = [ "warp", ] +[[package]] +name = "dragonfly-client-init" +version = "0.1.23" +dependencies = [ + "clap", + "dragonfly-client-config", +] + [[package]] name = "dragonfly-client-storage" -version = "0.1.22" +version = "0.1.23" dependencies = [ "base16ct", "chrono", @@ -737,7 +745,7 @@ dependencies = [ [[package]] name = "dragonfly-client-util" -version = "0.1.22" +version = "0.1.23" dependencies = [ "dragonfly-api", "dragonfly-client-core", diff --git a/Cargo.toml b/Cargo.toml index 08d71ef7..9bbdb16b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,9 +1,9 @@ [workspace] 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] -version = "0.1.22" +version = "0.1.23" authors = ["The Dragonfly Developers"] homepage = "https://d7y.io/" repository = "https://github.com/dragonflyoss/client.git" @@ -13,11 +13,12 @@ readme = "README.md" edition = "2021" [workspace.dependencies] -dragonfly-client-core = { path = "dragonfly-client-core", version = "0.1.22" } -dragonfly-client-config = { path = "dragonfly-client-config", version = "0.1.22" } -dragonfly-client-storage = { path = "dragonfly-client-storage", version = "0.1.22" } -dragonfly-client-backend = { path = "dragonfly-client-backend", version = "0.1.22" } -dragonfly-client-util = { path = "dragonfly-client-util", version = "0.1.21" } +dragonfly-client-core = { path = "dragonfly-client-core", version = "0.1.23" } +dragonfly-client-config = { path = "dragonfly-client-config", version = "0.1.23" } +dragonfly-client-storage = { path = "dragonfly-client-storage", version = "0.1.23" } +dragonfly-client-backend = { path = "dragonfly-client-backend", version = "0.1.23" } +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" dragonfly-api = "2.0.106" reqwest = { version = "0.11.25", features = ["stream", "native-tls", "rustls-tls"] } @@ -51,6 +52,7 @@ humantime = "2.1.0" prost-wkt-types = "0.4" chrono = { version = "0.4.34", features = ["serde"] } openssl = { version = "0.10", features = ["vendored"] } +clap = { version = "4.5.1", features = [ "derive" ] } [profile.bench] debug = true diff --git a/dragonfly-client-config/src/dfdaemon.rs b/dragonfly-client-config/src/dfdaemon.rs index c4e4ac82..f7f4011a 100644 --- a/dragonfly-client-config/src/dfdaemon.rs +++ b/dragonfly-client-config/src/dfdaemon.rs @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + use dragonfly_client_core::Result; use local_ip_address::{local_ip, local_ipv6}; use regex::Regex; diff --git a/dragonfly-client-config/src/dfinit.rs b/dragonfly-client-config/src/dfinit.rs new file mode 100644 index 00000000..90957179 --- /dev/null +++ b/dragonfly-client-config/src/dfinit.rs @@ -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) +} diff --git a/dragonfly-client-config/src/lib.rs b/dragonfly-client-config/src/lib.rs index 139397bd..5c976885 100644 --- a/dragonfly-client-config/src/lib.rs +++ b/dragonfly-client-config/src/lib.rs @@ -18,6 +18,7 @@ use std::path::PathBuf; pub mod dfdaemon; pub mod dfget; +pub mod dfinit; pub mod dfstore; // SERVICE_NAME is the name of the service. diff --git a/dragonfly-client-init/Cargo.toml b/dragonfly-client-init/Cargo.toml new file mode 100644 index 00000000..a4b6c73e --- /dev/null +++ b/dragonfly-client-init/Cargo.toml @@ -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 diff --git a/dragonfly-client-init/Dockerfile b/dragonfly-client-init/Dockerfile new file mode 100644 index 00000000..64bf035b --- /dev/null +++ b/dragonfly-client-init/Dockerfile @@ -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"] diff --git a/dragonfly-client-init/src/bin/main.rs b/dragonfly-client-init/src/bin/main.rs new file mode 100644 index 00000000..acf972e1 --- /dev/null +++ b/dragonfly-client-init/src/bin/main.rs @@ -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); +} diff --git a/dragonfly-client/Cargo.toml b/dragonfly-client/Cargo.toml index 872e91a4..d1782493 100644 --- a/dragonfly-client/Cargo.toml +++ b/dragonfly-client/Cargo.toml @@ -51,7 +51,7 @@ reqwest.workspace = true url.workspace = true http.workspace = true openssl.workspace = true -clap = { version = "4.5.1", features = [ "derive" ] } +clap.workspace = true tracing-log = "0.1" tracing-subscriber = { version = "0.3", features = ["env-filter"] } tracing-appender = "0.2.3" diff --git a/Dockerfile b/dragonfly-client/Dockerfile similarity index 100% rename from Dockerfile rename to dragonfly-client/Dockerfile