Skip to content

Commit

Permalink
support registry source type
Browse files Browse the repository at this point in the history
  • Loading branch information
jelipo committed Sep 27, 2023
1 parent 8bc7580 commit 3ed95c1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
## Linux 和 MacOS

```
curl -L https://github.com/jelipo/ocipack-rs/releases/download/0.5.0/ocipack-0.5.0-amd64_$(uname).tar.gz | tar xzv
curl -L https://github.com/jelipo/ocipack-rs/releases/download/0.6.0/ocipack-0.6.0-amd64_$(uname).tar.gz | tar xzv
# 把下载解压完成的 `ocipack` 放到 `/usr/local/bin/` (可选操作)
sudo cp ocipack /usr/local/bin/ && sudo chmod +x /usr/local/bin/ocipack
Expand All @@ -37,7 +37,7 @@ sudo cp ocipack /usr/local/bin/ && sudo chmod +x /usr/local/bin/ocipack
### Windows

```
curl.exe -L https://github.com/jelipo/ocipack-rs/releases/download/0.5.0/ocipack-0.5.0-amd64_windows.zip -o ocipack.zip
curl.exe -L https://github.com/jelipo/ocipack-rs/releases/download/0.6.0/ocipack-0.6.0-amd64_windows.zip -o ocipack.zip
tar -xf ocipack.zip
```
Expand Down Expand Up @@ -118,6 +118,17 @@ my.harbor.com/jelipo/demo:v1

接下来我们执行`docker run -it --rm my.harbor.com/jelipo/demo:v1`时会输出我们的`Dockerfile`文件的内容。

### 将镜像打包成文件

如果只需要下载镜像保存到文件,可以把 `--target`参数改为 `tgz:file_path`,顺便使用socks5代理访问。

```bash
./ocipack build \
--source=registry:redis:latest \
--target=tgz:redis.tgz \
--source-proxy=socks5://127.0.0.1:1080
```

## 功能

## 构建(Build)
Expand Down Expand Up @@ -147,7 +158,7 @@ my.harbor.com/jelipo/demo:v1
Example:'socks5://127.0.0.1:1080','http://name:pass@example:8080'
# Target Image的信息
-t, --target <TARGET>
Target type. Support 'registry' Example:'registry:my.container.com/target/image:1.1'
Target type. Support registry/tar/tgz. Example:'registry:my.container.com/target/image:1.1','tgz:image.tgz'
# 当Target Image的Registry为http而非https时需要启用
--target-allow-insecure
Allow target insecure registry
Expand Down
14 changes: 9 additions & 5 deletions src/config/cmd.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use std::env;
use std::str::FromStr;

use anyhow::Result;
use anyhow::{anyhow, Error};
use anyhow::Result;
use clap::Parser;
use url::Url;

use crate::container::proxy::{ProxyAuth, ProxyInfo};
use crate::container::Platform;
use crate::container::proxy::{ProxyAuth, ProxyInfo};

#[derive(Parser)]
#[clap(about = "Fast build docker/oci image", version, author = "jelipo (github.com/jelipo)", long_about = None)]
Expand Down Expand Up @@ -76,8 +76,8 @@ pub struct BuildCmdArgs {
pub target_allow_insecure: bool,

/// Source type.
/// Support dockerfile type
/// Example:'dockerfile:/path/to/.Dockerfile'
/// Support dockerfile/registry type
/// Example:'dockerfile:/path/to/.Dockerfile','registry:redis:latest'
#[clap(long, short)]
pub source: SourceType,

Expand All @@ -90,7 +90,7 @@ pub struct BuildCmdArgs {
pub source_proxy: Option<ProxyInfo>,

/// Target type.
/// Support registry/tar/tgz'.
/// Support registry/tar/tgz.
/// Example:'registry:my.container.com/target/image:1.1','tgz:image.tgz'
#[clap(long, short)]
pub target: TargetType,
Expand Down Expand Up @@ -208,6 +208,7 @@ impl FromStr for TargetFormat {
#[derive(Clone)]
pub enum SourceType {
Dockerfile { path: String },
Registry { image: String },
Cmd { tag: String },
}

Expand All @@ -221,6 +222,9 @@ impl FromStr for SourceType {
"dockerfile" => SourceType::Dockerfile {
path: arg[potion + 1..].to_string(),
},
"registry" => SourceType::Registry {
image: arg[potion + 1..].to_string()
},
"cmd" => SourceType::Cmd {
tag: arg[potion + 1..].to_string(),
},
Expand Down
8 changes: 6 additions & 2 deletions src/subcmd/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Target image:
TargetType::Tar(tar_arg) => format!("Path: {}", tar_arg.path),
}
)
.green()
.green()
);
}

Expand All @@ -71,7 +71,7 @@ Build job failed!
"#,
err
)
.red()
.red()
);
}

Expand All @@ -81,6 +81,10 @@ fn build_source_info(build_args: &BuildCmdArgs) -> Result<(SourceInfo, BuildInfo
SourceType::Cmd { tag: _ } => {
todo!()
}
SourceType::Registry { image } => {
let fake_dockerfile_body = format!("FROM {}", image);
DockerfileAdapter::parse_from_str(&fake_dockerfile_body)?
},
};
// add library
let image_name = &image_info.image_name;
Expand Down

0 comments on commit 3ed95c1

Please sign in to comment.