Skip to content

Commit

Permalink
feat: initialize dfinit crate (#330)
Browse files Browse the repository at this point in the history
Signed-off-by: Gaius <[email protected]>
  • Loading branch information
gaius-qi authored Mar 18, 2024
1 parent 19614cb commit aa9f8f7
Show file tree
Hide file tree
Showing 12 changed files with 172 additions and 14 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 14 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 9 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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"] }
Expand Down Expand Up @@ -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
1 change: 1 addition & 0 deletions dragonfly-client-config/src/dfdaemon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
31 changes: 31 additions & 0 deletions dragonfly-client-config/src/dfinit.rs
Original file line number Diff line number Diff line change
@@ -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)
}
1 change: 1 addition & 0 deletions dragonfly-client-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 19 additions & 0 deletions dragonfly-client-init/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions dragonfly-client-init/Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
46 changes: 46 additions & 0 deletions dragonfly-client-init/src/bin/main.rs
Original file line number Diff line number Diff line change
@@ -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);
}
2 changes: 1 addition & 1 deletion dragonfly-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
File renamed without changes.

0 comments on commit aa9f8f7

Please sign in to comment.