@@ -15,10 +15,14 @@ usage() {
15
15
exit
16
16
}
17
17
18
+ msg () {
19
+ echo ` date +" %Y-%m-%dT%H:%M:%S%:z" ` $*
20
+ }
21
+
18
22
ensure_lxd () {
19
23
if ! command -v lxc version & > /dev/null
20
24
then
21
- echo " LXD could not be found. Please ensure LXD exists."
25
+ msg " LXD could not be found. Please ensure LXD exists."
22
26
exit 1
23
27
fi
24
28
}
@@ -29,15 +33,15 @@ build_image_in_container() {
29
33
30
34
local BUILD_PREREQS_PATH=" ${SRCDIR} /build-files"
31
35
if [ ! -d " ${BUILD_PREREQS_PATH} " ]; then
32
- echo " Check the BUILD_PREREQS_PATH specification" >&2
36
+ msg " Check the BUILD_PREREQS_PATH specification" >&2
33
37
return 3
34
38
fi
35
39
local PATCH_FILE=" ${PATCH_FILE:- runner-sdk-8.patch} "
36
40
37
41
local BUILD_CONTAINER
38
42
BUILD_CONTAINER=" gha-builder-$( date +%s) "
39
43
40
- echo " Launching build container ${LXD_CONTAINER} "
44
+ msg " Launching build container ${LXD_CONTAINER} "
41
45
lxc launch " ${LXD_CONTAINER} " " ${BUILD_CONTAINER} "
42
46
lxc ls
43
47
@@ -52,48 +56,48 @@ build_image_in_container() {
52
56
done
53
57
54
58
if [ -z " ${CHECK} " ]; then
55
- echo " Unable to start the build container" >&2
59
+ msg " Unable to start the build container" >&2
56
60
lxc delete -f ${BUILD_CONTAINER}
57
61
return 2
58
62
fi
59
63
60
- echo " Copy the build-image script into gha-builder"
64
+ msg " Copy the build-image script into gha-builder"
61
65
lxc file push --mode 0755 " ${BUILD_PREREQS_PATH} /build-image.sh" " ${BUILD_CONTAINER}${BUILD_HOME} /build-image.sh"
62
66
63
- echo " Copy the patch file into gha-builder"
67
+ msg " Copy the patch file into gha-builder"
64
68
lxc file push ${BUILD_PREREQS_PATH} /${PATCH_FILE} " ${BUILD_CONTAINER}${BUILD_HOME} /"
65
69
66
- echo " Copy the register-runner.sh script into gha-builder"
70
+ msg " Copy the register-runner.sh script into gha-builder"
67
71
lxc file push --mode 0755 ${BUILD_PREREQS_PATH} /register-runner.sh " ${BUILD_CONTAINER} /opt/register-runner.sh"
68
72
69
- echo " Copy the /etc/rc.local - required in case podman is used"
73
+ msg " Copy the /etc/rc.local - required in case podman is used"
70
74
lxc file push --mode 0755 ${BUILD_PREREQS_PATH} /rc.local " ${BUILD_CONTAINER} /etc/rc.local"
71
75
72
- echo " Copy the LXD preseed configuration"
76
+ msg " Copy the LXD preseed configuration"
73
77
lxc file push --mode 0755 ${BUILD_PREREQS_PATH} /lxd-preseed.yaml " ${BUILD_CONTAINER} /tmp/lxd-preseed.yaml"
74
78
75
- echo " Copy the gha-service unit file into gha-builder"
79
+ msg " Copy the gha-service unit file into gha-builder"
76
80
lxc file push ${BUILD_PREREQS_PATH} /gha-runner.service " ${BUILD_CONTAINER} /etc/systemd/system/gha-runner.service"
77
81
78
- echo " Setting user ubuntu with sudo privileges"
82
+ msg " Setting user ubuntu with sudo privileges"
79
83
lxc exec " ${BUILD_CONTAINER} " --user 0 --group 0 -- sh -c " echo 'ubuntu ALL=(ALL) NOPASSWD:ALL' | sudo EDITOR='tee -a' visudo"
80
84
81
- echo " Running build-image.sh"
85
+ msg " Running build-image.sh"
82
86
lxc exec " ${BUILD_CONTAINER} " --user 1000 --group 1000 -- ${BUILD_HOME} /build-image.sh -a ${ACTION_RUNNER} ${SDK}
83
87
RC=$?
84
88
85
89
if [ ${RC} -eq 0 ]; then
86
90
# Until we are at lxc >= 5.19 we can't use the --reuse option on the publish command
87
- echo " Deleting old image"
91
+ msg " Deleting old image"
88
92
lxc image delete ${IMAGE_ALIAS} 2> /dev/null
89
93
90
- echo " Runner build complete. Creating image snapshot."
94
+ msg " Runner build complete. Creating image snapshot."
91
95
lxc publish " ${BUILD_CONTAINER} " -f --alias " ${IMAGE_ALIAS} " description=" GitHub Actions ${OS_NAME} ${OS_VERSION} Runner for ${ARCH} "
92
96
93
- echo " Export the image to ${EXPORT} for use elsewhere"
97
+ msg " Export the image to ${EXPORT} for use elsewhere"
94
98
lxc image export " ${IMAGE_ALIAS} " ${EXPORT}
95
99
else
96
- echo " Build process failed with RC: $? - review log to determine cause of failure" >&2
100
+ msg " Build process failed with RC: $? - review log to determine cause of failure" >&2
97
101
fi
98
102
99
103
lxc delete -f " ${BUILD_CONTAINER} "
@@ -126,7 +130,7 @@ prolog() {
126
130
127
131
X=` groups | grep -q lxd`
128
132
if [ $? -eq 1 ]; then
129
- echo " Setting permissions"
133
+ msg " Setting permissions"
130
134
sudo chmod 0666 /var/snap/lxd/common/lxd/unix.socket
131
135
fi
132
136
}
0 commit comments