Skip to content

Commit

Permalink
see #8 preparations for Linux containers
Browse files Browse the repository at this point in the history
  • Loading branch information
slonopotamus committed Jan 10, 2022
1 parent e82e4a0 commit 0e40897
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
10 changes: 8 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <marat@slonopotamus.org>"]
homepage = "https://github.com/slonopotamus/stevedore"
repository = "https://github.com/slonopotamus/stevedore.git"
Expand Down
19 changes: 12 additions & 7 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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() {
Expand All @@ -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();
Expand Down

0 comments on commit 0e40897

Please sign in to comment.