This repository has been archived by the owner on Aug 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·41 lines (39 loc) · 1.7 KB
/
build.sh
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
#!/bin/bash
set -eu
if [[ $# -lt 4 ]]; then
echo "Error: Too few arguments passed to script"
exit 1
else
netbootPrivateKeyPath="$1"
netbootIP="$2"
netbootUsername="$3"
netbootAssetsDirectory="$4"
fi
# Building actual image.
echo ">>>Building image"
# Used to invalidate the Docker build cache
date >date.txt
# Fetching kernel version as it's needed to install the linux-modules-package.
kernelVersion=$(curl -s --connect-timeout 2 "http://$netbootIP/kernels/latest-kernel-version.json" | jq -r .version)
if [[ "$kernelVersion" == "" ]]; then
echo "Error: could not determine latest kernel version"
exit 1
fi
docker image build --build-arg "kernelVersion=$kernelVersion" -t netboot-caching-server .
echo ">>>Running image"
containerID=$(docker run -d netboot-caching-server tail -f /dev/null)
echo ">>>Tarring container contents"
docker cp "$containerID:/" - >newfilesystemcaching.tar
echo ">>>Deleting container"
docker rm -f "$containerID"
echo ">>>Generating SquashFS"
containerID=$(docker run -d -v "$(pwd)/newfilesystemcaching.tar:/var/live/newfilesystem.tar" anymodconrst001dg.azurecr.io/planetexpress/squashfs-tools:latest /bin/sh -c "tar2sqfs --quiet newfilesystem.squashfs < /var/live/newfilesystem.tar")
docker wait "$containerID"
echo ">>>Exporting SquashFS"
docker cp "$containerID:/var/live/newfilesystem.squashfs" ./new.squashfscaching
echo ">>>Uploading SquashFS"
scp -o 'StrictHostKeyChecking=no' -i "$netbootPrivateKeyPath" ./new.squashfscaching "$netbootUsername@$netbootIP:$netbootAssetsDirectory/caching-server/casper/netboot-caching-server.squashfs"
echo ">>>Cleaning up"
docker rm -f "$containerID"
rm -f "$(pwd)"/newfilesystemcaching.tar
rm -f ./new.squashfscaching