mirror of
https://github.com/edera-dev/krata.git
synced 2025-08-03 05:10:55 +00:00
controller: implement enhanced image name format support
This commit is contained in:
parent
89e4f1a23d
commit
6511f2f0fa
@ -6,6 +6,9 @@ use std::ops::DerefMut;
|
|||||||
use ureq::{Agent, Request, Response};
|
use ureq::{Agent, Request, Response};
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
const MANIFEST_PICKER_PLATFORM: Os = Os::Linux;
|
||||||
|
const MANIFEST_PICKER_ARCHITECTURE: Arch = Arch::Amd64;
|
||||||
|
|
||||||
pub struct RegistryClient {
|
pub struct RegistryClient {
|
||||||
agent: Agent,
|
agent: Agent,
|
||||||
url: Url,
|
url: Url,
|
||||||
@ -86,7 +89,9 @@ impl RegistryClient {
|
|||||||
fn pick_manifest(&mut self, index: ImageIndex) -> Option<Descriptor> {
|
fn pick_manifest(&mut self, index: ImageIndex) -> Option<Descriptor> {
|
||||||
for item in index.manifests() {
|
for item in index.manifests() {
|
||||||
if let Some(platform) = item.platform() {
|
if let Some(platform) = item.platform() {
|
||||||
if *platform.os() == Os::Linux && *platform.architecture() == Arch::Amd64 {
|
if *platform.os() == MANIFEST_PICKER_PLATFORM
|
||||||
|
&& *platform.architecture() == MANIFEST_PICKER_ARCHITECTURE
|
||||||
|
{
|
||||||
return Some(item.clone());
|
return Some(item.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,9 @@ use anyhow::Result;
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
|
||||||
|
const DOCKER_HUB_MIRROR: &str = "mirror.gcr.io";
|
||||||
|
const DEFAULT_IMAGE_TAG: &str = "latest";
|
||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||||
pub struct ImageName {
|
pub struct ImageName {
|
||||||
pub hostname: String,
|
pub hostname: String,
|
||||||
@ -33,20 +36,39 @@ impl Default for ImageName {
|
|||||||
|
|
||||||
impl ImageName {
|
impl ImageName {
|
||||||
pub fn parse(name: &str) -> Result<Self> {
|
pub fn parse(name: &str) -> Result<Self> {
|
||||||
let (hostname, name) = name
|
let full_name = name.to_string();
|
||||||
|
let name = full_name.clone();
|
||||||
|
let (mut hostname, mut name) = name
|
||||||
.split_once('/')
|
.split_once('/')
|
||||||
.unwrap_or(("registry-1.docker.io", name));
|
.map(|x| (x.0.to_string(), x.1.to_string()))
|
||||||
let (hostname, port) = if let Some((hostname, port)) = hostname.split_once(':') {
|
.unwrap_or_else(|| (DOCKER_HUB_MIRROR.to_string(), format!("library/{}", name)));
|
||||||
(hostname, Some(str::parse(port)?))
|
|
||||||
|
// heuristic to find any docker hub image formats
|
||||||
|
// that may be in the hostname format. for example:
|
||||||
|
// abc/xyz:latest will trigger this if check, but abc.io/xyz:latest will not,
|
||||||
|
// and neither will abc/hello/xyz:latest
|
||||||
|
if !hostname.contains('.') && full_name.chars().filter(|x| *x == '/').count() == 1 {
|
||||||
|
name = format!("{}/{}", hostname, name);
|
||||||
|
hostname = DOCKER_HUB_MIRROR.to_string();
|
||||||
|
}
|
||||||
|
|
||||||
|
let (hostname, port) = if let Some((hostname, port)) = hostname
|
||||||
|
.split_once(':')
|
||||||
|
.map(|x| (x.0.to_string(), x.1.to_string()))
|
||||||
|
{
|
||||||
|
(hostname, Some(str::parse(&port)?))
|
||||||
} else {
|
} else {
|
||||||
(hostname, None)
|
(hostname, None)
|
||||||
};
|
};
|
||||||
let (name, reference) = name.split_once(':').unwrap_or((name, "latest"));
|
let (name, reference) = name
|
||||||
|
.split_once(':')
|
||||||
|
.map(|x| (x.0.to_string(), x.1.to_string()))
|
||||||
|
.unwrap_or((name.to_string(), DEFAULT_IMAGE_TAG.to_string()));
|
||||||
Ok(ImageName {
|
Ok(ImageName {
|
||||||
hostname: hostname.to_string(),
|
hostname,
|
||||||
port,
|
port,
|
||||||
name: name.to_string(),
|
name,
|
||||||
reference: reference.to_string(),
|
reference,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
29
scripts/krata-debug-common.sh
Normal file
29
scripts/krata-debug-common.sh
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
REAL_SCRIPT="$(realpath "${0}")"
|
||||||
|
cd "$(dirname "${REAL_SCRIPT}")/.."
|
||||||
|
|
||||||
|
if [ -z "${RUST_LOG}" ]
|
||||||
|
then
|
||||||
|
RUST_LOG="INFO"
|
||||||
|
fi
|
||||||
|
|
||||||
|
CARGO_BUILD_FLAGS=""
|
||||||
|
|
||||||
|
if [ "${KRATA_BUILD_QUIET}" = "1" ]
|
||||||
|
then
|
||||||
|
CARGO_BUILD_FLAGS="-q"
|
||||||
|
fi
|
||||||
|
|
||||||
|
build_and_run() {
|
||||||
|
EXE_TARGET="${1}"
|
||||||
|
shift
|
||||||
|
if [ "${KRATA_BUILD_INITRD}" = "1" ]
|
||||||
|
then
|
||||||
|
./initrd/build.sh -q
|
||||||
|
sudo cp "target/initrd/initrd" "/var/lib/krata/default/initrd"
|
||||||
|
fi
|
||||||
|
cargo build ${CARGO_BUILD_FLAGS} --target x86_64-unknown-linux-gnu --bin "${EXE_TARGET}"
|
||||||
|
exec sudo RUST_LOG="${RUST_LOG}" "target/x86_64-unknown-linux-gnu/debug/${EXE_TARGET}" "${@}"
|
||||||
|
}
|
@ -1,14 +1,8 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
if [ -z "${RUST_LOG}" ]
|
|
||||||
then
|
|
||||||
RUST_LOG="INFO"
|
|
||||||
fi
|
|
||||||
|
|
||||||
REAL_SCRIPT="$(realpath "${0}")"
|
REAL_SCRIPT="$(realpath "${0}")"
|
||||||
cd "$(dirname "${REAL_SCRIPT}")/.."
|
# shellcheck source-path=krata-debug-common.sh
|
||||||
./initrd/build.sh -q
|
. "$(dirname "${REAL_SCRIPT}")/krata-debug-common.sh"
|
||||||
sudo cp "target/initrd/initrd" "/var/lib/krata/default/initrd"
|
|
||||||
cargo build --target x86_64-unknown-linux-gnu --bin kratactl
|
KRATA_BUILD_INITRD=1 build_and_run kratactl "${@}"
|
||||||
exec sudo RUST_LOG="${RUST_LOG}" target/x86_64-unknown-linux-gnu/debug/kratactl "${@}"
|
|
||||||
|
@ -1,12 +1,8 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
if [ -z "${RUST_LOG}" ]
|
|
||||||
then
|
|
||||||
RUST_LOG="INFO"
|
|
||||||
fi
|
|
||||||
|
|
||||||
REAL_SCRIPT="$(realpath "${0}")"
|
REAL_SCRIPT="$(realpath "${0}")"
|
||||||
cd "$(dirname "${REAL_SCRIPT}")/.."
|
# shellcheck source-path=krata-debug-common.sh
|
||||||
cargo build --target x86_64-unknown-linux-gnu --bin kratanet
|
. "$(dirname "${REAL_SCRIPT}")/krata-debug-common.sh"
|
||||||
exec sudo RUST_LOG="${RUST_LOG}" target/x86_64-unknown-linux-gnu/debug/kratanet "${@}"
|
|
||||||
|
build_and_run kratanet "${@}"
|
||||||
|
Loading…
Reference in New Issue
Block a user