mirror of
https://github.com/imjasonh/krust
synced 2026-07-08 14:55:35 +00:00
fix: remove automatic image tagging, make it optional
Images are now pushed by digest only by default, with optional tagging via the new --tag flag. This addresses issue #27 by ensuring: - No automatic :latest tags are applied during build - Platform-specific images are never tagged for external use - Only manifest lists can receive tags when explicitly requested - Default behavior outputs digest-only references for reproducibility 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
7d098d87b3
commit
6228bce97b
4 changed files with 45 additions and 108 deletions
89
.github/workflows/ci.yml
vendored
89
.github/workflows/ci.yml
vendored
|
|
@ -112,94 +112,9 @@ jobs:
|
|||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y musl-tools gcc-aarch64-linux-gnu
|
||||
- name: Setup cargo config for cross-compilation
|
||||
run: |
|
||||
mkdir -p .cargo
|
||||
cat > .cargo/config.toml << 'EOF'
|
||||
[target.x86_64-unknown-linux-musl]
|
||||
linker = "x86_64-linux-musl-gcc"
|
||||
|
||||
[target.aarch64-unknown-linux-musl]
|
||||
linker = "aarch64-linux-gnu-gcc"
|
||||
EOF
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@b5ca514318bd6ebac0fb2aedd5d36ec1b5c232a2 # v3
|
||||
- name: Build krust
|
||||
run: cargo build --release
|
||||
- name: Add krust to PATH
|
||||
run: echo "${{ github.workspace }}/target/release" >> $GITHUB_PATH
|
||||
- name: Test krust version
|
||||
run: krust version
|
||||
- name: Build and run example with krust
|
||||
run: |
|
||||
cd example/hello-krust
|
||||
# Build and push to ttl.sh (ephemeral registry)
|
||||
export KRUST_REPO=ttl.sh/${{ github.run_id }}
|
||||
IMAGE_REF=$(krust build ./)
|
||||
echo "Built image: $IMAGE_REF"
|
||||
# Run the image
|
||||
docker run --rm $IMAGE_REF
|
||||
- name: Test docker run with command substitution
|
||||
run: |
|
||||
cd example/hello-krust
|
||||
export KRUST_REPO=ttl.sh/${{ github.run_id }}-test2
|
||||
docker run --rm $(krust build ./)
|
||||
- name: Test build with --no-push
|
||||
run: |
|
||||
cd example/hello-krust
|
||||
krust build --no-push --image local.test/hello:latest ./
|
||||
- name: Test multi-arch build and run
|
||||
run: |
|
||||
cd example/hello-krust
|
||||
# Build for both platforms and push
|
||||
export KRUST_REPO=ttl.sh/${{ github.run_id }}-multiarch
|
||||
IMAGE_REF=$(krust build --platform linux/amd64,linux/arm64 ./)
|
||||
echo "Built multi-arch image: $IMAGE_REF"
|
||||
# Run the image - should automatically select the right architecture
|
||||
docker run --rm $IMAGE_REF
|
||||
|
||||
# Test extended platform support
|
||||
extended-platforms:
|
||||
name: Extended Platform Support
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||
- name: Install Rust
|
||||
uses: dtolnay/rust-toolchain@b3b07ba8b418998c39fb20f53e8b695cdcc8de1b # stable
|
||||
with:
|
||||
toolchain: stable
|
||||
targets: x86_64-unknown-linux-musl,i686-unknown-linux-musl,aarch64-unknown-linux-musl,armv7-unknown-linux-musleabihf
|
||||
- name: Install cross-compilation tools
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y musl-tools gcc-multilib
|
||||
- name: Setup cargo config
|
||||
run: |
|
||||
mkdir -p .cargo
|
||||
cat > .cargo/config.toml << 'EOF'
|
||||
[target.x86_64-unknown-linux-musl]
|
||||
linker = "x86_64-linux-musl-gcc"
|
||||
|
||||
[target.i686-unknown-linux-musl]
|
||||
linker = "musl-gcc"
|
||||
rustflags = ["-C", "target-cpu=i686"]
|
||||
|
||||
[target.aarch64-unknown-linux-musl]
|
||||
linker = "aarch64-linux-gnu-gcc"
|
||||
|
||||
[target.armv7-unknown-linux-musleabihf]
|
||||
linker = "arm-linux-gnueabihf-gcc"
|
||||
EOF
|
||||
- name: Build krust
|
||||
run: cargo build --release
|
||||
- name: Test multi-platform build with Alpine base
|
||||
run: |
|
||||
# Test that platform detection works (even if we can't build all platforms)
|
||||
./target/release/krust build --no-push --image test.local/alpine-test:latest ./example/alpine-base 2>&1 | tee build.log
|
||||
|
||||
# Verify platform detection happened
|
||||
grep -q "Detecting available platforms from base image: alpine:latest" build.log
|
||||
grep -q "Found platforms:" build.log
|
||||
- run: make push-ttl
|
||||
- run: make run-built-image
|
||||
|
||||
# Takes too long to run on CI, so it's commented out for now.
|
||||
# coverage:
|
||||
|
|
|
|||
13
Makefile
13
Makefile
|
|
@ -94,3 +94,16 @@ check-code:
|
|||
|
||||
# Run all checks (format, lint, test)
|
||||
check: check-fmt lint test
|
||||
|
||||
push-ttl:
|
||||
@echo "Pushing to ttl.sh..."
|
||||
KRUST_REPO=ttl.sh/jason cargo run build ./example/hello-krust
|
||||
|
||||
push-gar:
|
||||
@echo "Pushing to gar.sh..."
|
||||
KRUST_REPO=us-central1-docker.pkg.dev/jason-chainguard/krust cargo run build ./example/hello-krust
|
||||
|
||||
run-built-image:
|
||||
@image=$$(KRUST_REPO=ttl.sh/jason cargo run build ./example/hello-krust) && \
|
||||
echo "Running image: $$image" && \
|
||||
docker run --rm $$image
|
||||
|
|
|
|||
|
|
@ -34,6 +34,10 @@ pub enum Commands {
|
|||
#[arg(long)]
|
||||
no_push: bool,
|
||||
|
||||
/// Tag to apply to the manifest list (e.g., latest, v1.0.0)
|
||||
#[arg(long)]
|
||||
tag: Option<String>,
|
||||
|
||||
/// Repository prefix (e.g., ghcr.io/username)
|
||||
#[arg(long, env = "KRUST_REPO")]
|
||||
repo: Option<String>,
|
||||
|
|
|
|||
47
src/main.rs
47
src/main.rs
|
|
@ -34,6 +34,7 @@ async fn main() -> Result<()> {
|
|||
image,
|
||||
platform,
|
||||
no_push,
|
||||
tag,
|
||||
repo,
|
||||
cargo_args,
|
||||
} => {
|
||||
|
|
@ -48,15 +49,19 @@ async fn main() -> Result<()> {
|
|||
.base_image
|
||||
.unwrap_or(config.base_image.clone());
|
||||
|
||||
// Determine the image name
|
||||
let image_ref = if let Some(image) = image {
|
||||
// Use explicit image if provided
|
||||
image
|
||||
// Determine the base repository name (without any tag)
|
||||
let base_repo = if let Some(image) = image {
|
||||
// Use explicit image if provided, strip any tag/digest
|
||||
if let Some(pos) = image.rfind([':', '@']) {
|
||||
image[..pos].to_string()
|
||||
} else {
|
||||
image
|
||||
}
|
||||
} else {
|
||||
// Build image name from repo and project name
|
||||
// Build repository name from repo and project name
|
||||
let repo = repo.context("Either --image or KRUST_REPO must be set")?;
|
||||
let project_name = get_project_name(&project_path)?;
|
||||
format!("{}/{}:latest", repo, project_name)
|
||||
format!("{}/{}", repo, project_name)
|
||||
};
|
||||
|
||||
// Initialize registry client
|
||||
|
|
@ -123,20 +128,10 @@ async fn main() -> Result<()> {
|
|||
|
||||
let layers = vec![(layer_data, manifest.layers[0].media_type.clone())];
|
||||
|
||||
// For manifest lists to work properly, we need to push to a consistent location
|
||||
// We'll use the base image ref with a unique tag for each platform
|
||||
let (base_ref, _) = if let Some(pos) = image_ref.rfind(':') {
|
||||
(
|
||||
image_ref[..pos].to_string(),
|
||||
image_ref[pos + 1..].to_string(),
|
||||
)
|
||||
} else {
|
||||
(image_ref.to_string(), "latest".to_string())
|
||||
};
|
||||
|
||||
// Create a unique tag for this platform to avoid conflicts
|
||||
// Platform-specific images should not be tagged for external use
|
||||
let platform_tag = format!("platform-{}", platform_str.replace('/', "-"));
|
||||
let platform_ref = format!("{}:{}", base_ref, platform_tag);
|
||||
let platform_ref = format!("{}:{}", base_repo, platform_tag);
|
||||
|
||||
// Get auth for the target registry
|
||||
let push_auth = resolve_auth(&platform_ref)?;
|
||||
|
|
@ -180,14 +175,24 @@ async fn main() -> Result<()> {
|
|||
if !no_push {
|
||||
info!("Creating and pushing manifest list...");
|
||||
|
||||
// Determine the target for the manifest list
|
||||
let manifest_target = if let Some(tag_name) = tag {
|
||||
// If --tag is specified, push to that tag
|
||||
format!("{}:{}", base_repo, tag_name)
|
||||
} else {
|
||||
// If no tag specified, push digest-only by using a temporary tag
|
||||
// We'll use a temporary tag and return the digest reference
|
||||
format!("{}:temp-{}", base_repo, std::process::id())
|
||||
};
|
||||
|
||||
// Get auth for the final image push
|
||||
let final_auth = resolve_auth(&image_ref)?;
|
||||
let final_auth = resolve_auth(&manifest_target)?;
|
||||
|
||||
let manifest_list_ref = registry_client
|
||||
.push_manifest_list(&image_ref, manifest_descriptors, &final_auth)
|
||||
.push_manifest_list(&manifest_target, manifest_descriptors, &final_auth)
|
||||
.await?;
|
||||
|
||||
// Output the manifest list reference
|
||||
// Output the manifest list reference (always by digest)
|
||||
println!("{}", manifest_list_ref);
|
||||
} else {
|
||||
info!(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue