-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild
executable file
·68 lines (59 loc) · 1.96 KB
/
build
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
#!/bin/bash
#
# Build an Arch Linux WSL tar image
set -eu
# Generate a Windows Terminal profile
# https://learn.microsoft.com/windows/wsl/build-custom-distro#generate-a-windows-terminal-profile
pushd terminal-profile || exit 1
npm install
node index.js >../root/usr/lib/wsl/terminal-profile.json
popd || exit 1
# Create an Arch Linux image based on its latest base Docker image
[[ -f .env ]] && source .env
token=$(curl \
-d "{ \"username\": \"${DOCKER_HUB_USERNAME}\", \"password\": \"${DOCKER_HUB_PAT}\" }" \
-H "Content-Type: application/json" \
-Ss \
https://hub.docker.com/v2/users/login/ |
jq -r .token)
digest=$(curl \
-H "Authorization: Bearer ${token}" \
-Ss \
https://hub.docker.com/v2/namespaces/library/repositories/archlinux/tags/base |
jq -r .digest)
tag=$(curl \
-H "Authorization: Bearer ${token}" \
-Ss \
https://hub.docker.com/v2/namespaces/library/repositories/archlinux/tags/?page=1\&page_size=100 |
jq -r ".results[] | select(.digest == \"${digest}\") | .name" |
grep "^base-.*$")
echo "${tag}" >imagetag.txt
dockerfile=$(cat Dockerfile)
dockerfile="${dockerfile/FROM archlinux:base/FROM archlinux:${tag}}"
docker buildx build -t "archwsl:${tag}" -f - . <<<"${dockerfile}"
# Export the tar from the container
# https://learn.microsoft.com/windows/wsl/use-custom-distro#export-the-tar-from-a-container
docker run -t --name wsl_export "archwsl:${tag}" ls /
docker export wsl_export >archlinux.tar
docker rm wsl_export
docker rmi "archwsl:${tag}"
# Apply configuration file recommendations
# https://learn.microsoft.com/windows/wsl/build-custom-distro#configuration-file-recommendations
[[ -d rootfs ]] && rm -rf rootfs
mkdir rootfs
pushd rootfs || exit 1
trim=$(
cat <<EOF
tar -xf ../archlinux.tar &&
rm -f etc/resolv.conf &&
rm -f .dockerenv &&
rm -rf boot &&
rm -rf dev &&
rm -rf run &&
tar --numeric-owner --absolute-names -c -- * |
gzip --best >../archlinux-${tag}.wsl
EOF
)
fakeroot bash -c "${trim}"
popd || exit 1
rm archlinux.tar