-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathJustfile
More file actions
140 lines (122 loc) · 5.02 KB
/
Justfile
File metadata and controls
140 lines (122 loc) · 5.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# Build the project
build profile="dev":
cargo build --profile {{ profile }}
# Check code formatting
fmt:
cargo fmt --check
# Run unit tests
check:
cargo test
# Run clippy linter
clippy:
cargo clippy -- -D warnings
# Lint shell scripts
shellcheck:
shellcheck --external-sources --enable=all $(git ls-files '*.sh')
# Lint markdown files
markdownlint:
markdownlint $(git ls-files '*.md')
# Verify Cargo.lock, README, and spec file versions match Cargo.toml
versioncheck:
#!/bin/bash
set -euo pipefail
cargo update chunkah --locked
cargo_version=$(cargo metadata --no-deps --format-version=1 | jq -r '.packages[0].version')
line=$(grep -E '^\s+https://github\.com/coreos/chunkah/releases/download/v[0-9]+\.[0-9]+\.[0-9]+/Containerfile\.splitter$' README.md) \
|| { echo "Could not find Containerfile.splitter download URL in README.md"; exit 1; }
readme_version=$(echo "${line}" | grep -oP 'download/v\K[0-9]+\.[0-9]+\.[0-9]+')
if [[ "${cargo_version}" != "${readme_version}" ]]; then
echo "Version mismatch: Cargo.toml has ${cargo_version}, README.md has ${readme_version}"
exit 1
fi
spec_version=$(grep -oP '^Version:\s+\K[0-9]+\.[0-9]+\.[0-9]+' packaging/chunkah.spec) \
|| { echo "Could not find Version field in packaging/chunkah.spec"; exit 1; }
if [[ "${cargo_version}" != "${spec_version}" ]]; then
echo "Version mismatch: Cargo.toml has ${cargo_version}, packaging/chunkah.spec has ${spec_version}"
exit 1
fi
# Run all checks (shellcheck, unit tests, fmt, clippy, markdownlint, versioncheck)
checkall: shellcheck check fmt clippy markdownlint versioncheck
# Build chunkah container image (use --no-chunk to skip chunking for faster builds)
[arg("no_chunk", long="no-chunk", value="true")]
buildimg no_chunk="" *ARGS:
#!/bin/bash
set -euo pipefail
buildah="${BUILDAH:-buildah}"
args=(-t chunkah --layers=true {{ if no_chunk == "true" { "--target=rootfs" } else { "--skip-unused-stages=false" } }})
cache_id=$(realpath "$PWD" | sha256sum | cut -f1 -d' ')
args+=(--build-arg CACHE_ID=chunkah-target-${cache_id})
# drop this once we can assume 1.44
version=$(${buildah} version --json | jq -r '.version')
if [[ $(echo -e "${version}\n1.44" | sort -V | head -n1) != "1.44" ]]; then
args+=(-v "$PWD:/run/src" --security-opt=label=disable)
fi
args+=({{ ARGS }})
echo ${buildah} build "${args[@]}" .
${buildah} build "${args[@]}" .
rm -f out.ociarchive
# Run end-to-end tests with built chunkah image
test *ARGS:
./tests/e2e/run.sh {{ ARGS }}
# Profile chunkah with flamegraph (outputs flamegraph.svg)
profile *ARGS:
just -f tools/perf/Justfile profile {{ ARGS }}
# Benchmark chunkah with hyperfine
benchmark *ARGS:
just -f tools/perf/Justfile benchmark {{ ARGS }}
# Compare two container images for equivalence
diff +ARGS:
#!/bin/bash
set -euo pipefail
img="localhost/chunkah-differ:latest"
if ! podman image exists "${img}"; then
podman build -t "${img}" tools/differ
fi
# Split args: first two are image names, rest are passed through
args=({{ ARGS }})
image1="${args[0]}"
image2="${args[1]}"
# Compare OCI image config
metadata_rc=0
config1=$(skopeo inspect --config "containers-storage:${image1}" | jq -S '.config')
config2=$(skopeo inspect --config "containers-storage:${image2}" | jq -S '.config')
if ! diff <(echo "${config1}") <(echo "${config2}"); then
echo "image config differs"
metadata_rc=1
fi
# Compare manifest annotations
annot1=$(skopeo inspect --raw "containers-storage:${image1}" | jq -S '.annotations // {}')
annot2=$(skopeo inspect --raw "containers-storage:${image2}" | jq -S '.annotations // {}')
if ! diff <(echo "${annot1}") <(echo "${annot2}"); then
echo "manifest annotations differ"
metadata_rc=1
fi
# Compare filesystem trees
fs_rc=0
podman run --rm -v /var/tmp \
--mount=type=image,src="${image1}",target=/image1 \
--mount=type=image,src="${image2}",target=/image2 \
"${img}" /image1 /image2 "${args[@]:2}" || fs_rc=$?
exit $(( metadata_rc | fs_rc ))
# Split an existing image using the splitter Containerfile
split IMG *ARGS:
#!/bin/bash
set -euo pipefail
shopt -s inherit_errexit
buildah="${BUILDAH:-buildah}"
args=(--skip-unused-stages=false --from "{{ IMG }}")
args+=(--build-arg CHUNKAH=localhost/chunkah)
args+=(--build-arg "CHUNKAH_CONFIG_STR=$(podman inspect {{ IMG }})")
if [[ -n "{{ ARGS }}" ]]; then
args+=(--build-arg "CHUNKAH_ARGS={{ ARGS }}")
fi
# drop this once we can assume 1.44
version=$(${buildah} version --json | jq -r '.version')
if [[ $(echo -e "${version}\n1.44" | sort -V | head -n1) != "1.44" ]]; then
args+=(-v "$PWD:/run/src" --security-opt=label=disable)
fi
${buildah} build "${args[@]}" Containerfile.splitter
rm -f out.ociarchive
# Cut a release (use --no-push to prepare without pushing)
release *ARGS:
./tools/release.py {{ ARGS }}