From 0e408971d1015be4ee79987111f6ea19db3f34ff Mon Sep 17 00:00:00 2001 From: Marat Radchenko Date: Mon, 10 Jan 2022 14:36:04 +0300 Subject: [PATCH] see #8 preparations for Linux containers --- .github/workflows/ci.yml | 10 ++++++++-- Cargo.toml | 2 +- build.rs | 19 ++++++++++++------- 3 files changed, 21 insertions(+), 10 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1b265f2..15ca4a7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,7 +17,7 @@ jobs: command: fmt args: --all -- --check clippy: - runs-on: windows-2019 + runs-on: windows-2022 steps: - name: checkout uses: actions/checkout@v2 @@ -33,7 +33,13 @@ jobs: command: clippy args: --all-targets -- -D warnings build: - runs-on: windows-2019 + # We can't use windows-latest because it currently (2022-01-09) points to Windows Server 2019 + # And we can't use 2019 because it doesn't have `wsl --export` + # + # Note that `wsldl backup` also depends on `wsl --export`, + # so it can't be used as a workaround: + # https://github.com/yuk7/wsldl/issues/116 + runs-on: windows-2022 steps: - name: checkout uses: actions/checkout@v2 diff --git a/Cargo.toml b/Cargo.toml index eb44204..5728a64 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ name = "stevedore" version = "0.0.3" description = "Docker distribution for Windows that Just Works" -edition = "2018" +edition = "2021" authors = ["Marat Radchenko "] homepage = "https://github.com/slonopotamus/stevedore" repository = "https://github.com/slonopotamus/stevedore.git" diff --git a/build.rs b/build.rs index f27acda..9f6e689 100644 --- a/build.rs +++ b/build.rs @@ -9,9 +9,10 @@ use sha2::{Digest, Sha256}; use zip::ZipArchive; const DOCKER_VERSION: &str = "20.10.12"; -const DOCKER_URL: &str = + +const DOCKER_WIN64_URL: &str = formatcp!("https://download.docker.com/win/static/stable/x86_64/docker-{DOCKER_VERSION}.zip"); -const DOCKER_SHA: &str = "bd3775ada72492aa1f3c2edb3e81663bd128b9d4f6752ef75953a6af7c219c81"; +const DOCKER_WIN64_SHA: &str = "bd3775ada72492aa1f3c2edb3e81663bd128b9d4f6752ef75953a6af7c219c81"; const DOCKER_COMPOSE_VERSION: &str = "2.2.2"; const DOCKER_COMPOSE_URL: &str = formatcp!("https://github.com/docker/compose/releases/download/v{DOCKER_COMPOSE_VERSION}/docker-compose-windows-x86_64.exe"); @@ -30,17 +31,20 @@ fn get_dest_dir() -> PathBuf { .join(build_type) } -fn download(uri: &str, sha256: &str) -> bytes::Bytes { +fn download(uri: &str, expected_sha256: &str) -> bytes::Bytes { let data = reqwest::blocking::get(uri).unwrap().bytes().unwrap(); - let hash = Sha256::digest(&data); - if format!("{:x}", hash) != sha256 { - panic!("Checksum mismatch: expected {} but got {:x}", sha256, hash); + let actual_sha256 = Sha256::digest(&data); + if format!("{:x}", actual_sha256) != expected_sha256 { + panic!( + "Checksum mismatch for {}: expected {} but got {:x}", + uri, expected_sha256, actual_sha256 + ); } data } fn build_docker(dest_dir: &Path) { - let compressed_data = download(DOCKER_URL, DOCKER_SHA); + let compressed_data = download(DOCKER_WIN64_URL, DOCKER_WIN64_SHA); let mut zip_archive = ZipArchive::new(Cursor::new(compressed_data)).unwrap(); for i in 0..zip_archive.len() { @@ -61,6 +65,7 @@ fn build_docker(dest_dir: &Path) { } fn download_file(uri: &str, sha256: &str, dest: &Path) { + // TODO: skip download if file already matches SHA let data = download(uri, sha256); let mut outfile = File::create(dest).unwrap(); outfile.write_all(&data).unwrap();