forked from Dstack-TEE/dstack-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-image.sh
More file actions
executable file
·87 lines (75 loc) · 2.51 KB
/
Copy pathbuild-image.sh
File metadata and controls
executable file
·87 lines (75 loc) · 2.51 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
#!/bin/bash
# Parse command line arguments
PUSH=false
REPO=""
while [[ $# -gt 0 ]]; do
case $1 in
--push)
PUSH=true
REPO="$2"
if [ -z "$REPO" ]; then
echo "Error: --push requires a repository argument"
echo "Usage: $0 [--push <repo>[:<tag>]]"
exit 1
fi
shift 2
;;
*)
echo "Usage: $0 [--push <repo>[:<tag>]]"
exit 1
;;
esac
done
require_command() {
local cmd="$1"
if ! command -v "$cmd" >/dev/null 2>&1; then
echo "Error: required command '$cmd' not found in PATH" >&2
exit 1
fi
}
for required in docker skopeo jq git; do
require_command "$required"
done
# Check if buildkit_20 already exists before creating it
if ! docker buildx inspect buildkit_20 &>/dev/null; then
docker buildx create --use --driver-opt image=moby/buildkit:v0.20.2 --name buildkit_20
fi
touch pinned-packages.txt
git rev-parse HEAD > .GIT_REV
TEMP_TAG="dstack-ingress-temp:$(date +%s)"
docker buildx build --builder buildkit_20 --no-cache --build-arg SOURCE_DATE_EPOCH="0" \
--output type=oci,dest=./oci.tar,rewrite-timestamp=true \
--output type=docker,name="$TEMP_TAG" .
if [ "$?" -ne 0 ]; then
echo "Build failed"
rm .GIT_REV
exit 1
fi
echo "Build completed, manifest digest:"
echo ""
skopeo inspect oci-archive:./oci.tar | jq .Digest
echo ""
if [ "$PUSH" = true ]; then
echo "Pushing image to $REPO..."
skopeo copy --insecure-policy oci-archive:./oci.tar docker://"$REPO"
echo "Image pushed successfully to $REPO"
else
echo "To push the image to a registry, run:"
echo ""
echo " $0 --push <repo>[:<tag>]"
echo ""
echo "Or use skopeo directly:"
echo ""
echo " skopeo copy --insecure-policy oci-archive:./oci.tar docker://<repo>[:<tag>]"
echo ""
echo " Pushing image to dstacktee org:"
echo " skopeo copy --insecure-policy oci-archive:./oci.tar docker://dstacktee/dstack-ingress:$(date +%Y%m%d) --authfile ~/.docker/config.json"
fi
echo ""
# Extract package information from the built image
echo "Extracting package information from built image: $TEMP_TAG"
docker run --rm --entrypoint bash "$TEMP_TAG" -c "dpkg -l | grep '^ii' | awk '{print \$2\"=\"\$3}' | sort" > pinned-packages.txt
echo "Package information extracted to pinned-packages.txt ($(wc -l < pinned-packages.txt) packages)"
# Clean up the temporary image from Docker daemon
docker rmi "$TEMP_TAG" 2>/dev/null || true
rm .GIT_REV