Skip to content

Commit 7dd8f23

Browse files
committed
Add timestamps to scripts
* setup-build-env.sh build-files/build-image.sh - Add timestamps to messages we produce
1 parent ef40b12 commit 7dd8f23

File tree

2 files changed

+37
-42
lines changed

2 files changed

+37
-42
lines changed

build-files/build-image.sh

+16-25
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
#!/bin/bash
22

33
header() {
4-
echo "+--------------------------------------------+"
5-
echo "| $*"
6-
echo "+--------------------------------------------+"
4+
TS=`date +"%Y-%m-%dT%H:%M:%S%:z"`
5+
echo "${TS} +--------------------------------------------+"
6+
echo "${TS} | $*"
7+
echo "${TS} +--------------------------------------------+"
78
echo
89
}
910

11+
msg() {
12+
echo `date +"%Y-%m-%dT%H:%M:%S%:z"` $*
13+
}
14+
1015
update_fresh_container() {
1116
header "Upgrading and installing packages"
1217
sudo DEBIAN_FRONTEND=noninteractive apt-get -qq update -y >/dev/null
@@ -17,15 +22,15 @@ update_fresh_container() {
1722
fi
1823
sudo apt autoclean
1924

20-
echo "Initializing LXD environment"
25+
msg "Initializing LXD environment"
2126
sudo lxd init --preseed </tmp/lxd-preseed.yaml
2227

23-
echo "Make sure we have lxd authority"
28+
msg "Make sure we have lxd authority"
2429
sudo usermod -G lxd -a ubuntu
2530
}
2631

2732
setup_dotnet_sdk() {
28-
echo "Using SDK - `dotnet --version`"
33+
msg "Using SDK - `dotnet --version`"
2934

3035
# fix ownership
3136
sudo chown ubuntu:ubuntu /home/ubuntu/.bashrc
@@ -52,17 +57,17 @@ build_runner() {
5257
header "Building runner binary"
5358
cd src
5459

55-
echo "dev layout"
60+
msg "dev layout"
5661
./dev.sh layout
5762

5863
if [ $? -eq 0 ]; then
59-
echo "dev package"
64+
msg "dev package"
6065
./dev.sh package
6166

6267
if [ $? -eq 0 ]; then
63-
echo "Finished building runner binary"
68+
msg "Finished building runner binary"
6469

65-
echo "Running tests"
70+
msg "Running tests"
6671
./dev.sh test
6772
fi
6873
fi
@@ -77,13 +82,12 @@ install_runner() {
7782
if [ $? -eq 0 ]; then
7883
sudo chown ubuntu:ubuntu -R /opt/runner
7984
/opt/runner/config.sh --version
80-
#TODO: Verify that the version is the _actual_ latest runner
8185
fi
8286
return $?
8387
}
8488

8589
cleanup() {
86-
rm -rf /home/ubuntu/build-image.sh /home/ubuntu/runner-${ARCH}.patch \
90+
rm -rf /home/ubuntu/build-image.sh /home/ubuntu/runner-sdk-8.patch \
8791
/tmp/runner /tmp/preseed-yaml
8892
}
8993

@@ -127,18 +131,5 @@ do
127131
done
128132
shift $(( OPTIND - 1 ))
129133

130-
if [ -z "${SDK}" ]; then
131-
case ${ARCH} in
132-
ppc64le)
133-
SDK=7
134-
;;
135-
s390x)
136-
SDK=6
137-
;;
138-
esac
139-
fi
140-
141134
run "$@"
142135
exit $?
143-
144-

setup-build-env.sh

+21-17
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ usage() {
1515
exit
1616
}
1717

18+
msg() {
19+
echo `date +"%Y-%m-%dT%H:%M:%S%:z"` $*
20+
}
21+
1822
ensure_lxd() {
1923
if ! command -v lxc version &> /dev/null
2024
then
21-
echo "LXD could not be found. Please ensure LXD exists."
25+
msg "LXD could not be found. Please ensure LXD exists."
2226
exit 1
2327
fi
2428
}
@@ -29,15 +33,15 @@ build_image_in_container() {
2933

3034
local BUILD_PREREQS_PATH="${SRCDIR}/build-files"
3135
if [ ! -d "${BUILD_PREREQS_PATH}" ]; then
32-
echo "Check the BUILD_PREREQS_PATH specification" >&2
36+
msg "Check the BUILD_PREREQS_PATH specification" >&2
3337
return 3
3438
fi
3539
local PATCH_FILE="${PATCH_FILE:-runner-sdk-8.patch}"
3640

3741
local BUILD_CONTAINER
3842
BUILD_CONTAINER="gha-builder-$(date +%s)"
3943

40-
echo "Launching build container ${LXD_CONTAINER}"
44+
msg "Launching build container ${LXD_CONTAINER}"
4145
lxc launch "${LXD_CONTAINER}" "${BUILD_CONTAINER}"
4246
lxc ls
4347

@@ -52,48 +56,48 @@ build_image_in_container() {
5256
done
5357

5458
if [ -z "${CHECK}" ]; then
55-
echo "Unable to start the build container" >&2
59+
msg "Unable to start the build container" >&2
5660
lxc delete -f ${BUILD_CONTAINER}
5761
return 2
5862
fi
5963

60-
echo "Copy the build-image script into gha-builder"
64+
msg "Copy the build-image script into gha-builder"
6165
lxc file push --mode 0755 "${BUILD_PREREQS_PATH}/build-image.sh" "${BUILD_CONTAINER}${BUILD_HOME}/build-image.sh"
6266

63-
echo "Copy the patch file into gha-builder"
67+
msg "Copy the patch file into gha-builder"
6468
lxc file push ${BUILD_PREREQS_PATH}/${PATCH_FILE} "${BUILD_CONTAINER}${BUILD_HOME}/"
6569

66-
echo "Copy the register-runner.sh script into gha-builder"
70+
msg "Copy the register-runner.sh script into gha-builder"
6771
lxc file push --mode 0755 ${BUILD_PREREQS_PATH}/register-runner.sh "${BUILD_CONTAINER}/opt/register-runner.sh"
6872

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"
7074
lxc file push --mode 0755 ${BUILD_PREREQS_PATH}/rc.local "${BUILD_CONTAINER}/etc/rc.local"
7175

72-
echo "Copy the LXD preseed configuration"
76+
msg "Copy the LXD preseed configuration"
7377
lxc file push --mode 0755 ${BUILD_PREREQS_PATH}/lxd-preseed.yaml "${BUILD_CONTAINER}/tmp/lxd-preseed.yaml"
7478

75-
echo "Copy the gha-service unit file into gha-builder"
79+
msg "Copy the gha-service unit file into gha-builder"
7680
lxc file push ${BUILD_PREREQS_PATH}/gha-runner.service "${BUILD_CONTAINER}/etc/systemd/system/gha-runner.service"
7781

78-
echo "Setting user ubuntu with sudo privileges"
82+
msg "Setting user ubuntu with sudo privileges"
7983
lxc exec "${BUILD_CONTAINER}" --user 0 --group 0 -- sh -c "echo 'ubuntu ALL=(ALL) NOPASSWD:ALL' | sudo EDITOR='tee -a' visudo"
8084

81-
echo "Running build-image.sh"
85+
msg "Running build-image.sh"
8286
lxc exec "${BUILD_CONTAINER}" --user 1000 --group 1000 -- ${BUILD_HOME}/build-image.sh -a ${ACTION_RUNNER} ${SDK}
8387
RC=$?
8488

8589
if [ ${RC} -eq 0 ]; then
8690
# 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"
8892
lxc image delete ${IMAGE_ALIAS} 2>/dev/null
8993

90-
echo "Runner build complete. Creating image snapshot."
94+
msg "Runner build complete. Creating image snapshot."
9195
lxc publish "${BUILD_CONTAINER}" -f --alias "${IMAGE_ALIAS}" description="GitHub Actions ${OS_NAME} ${OS_VERSION} Runner for ${ARCH}"
9296

93-
echo "Export the image to ${EXPORT} for use elsewhere"
97+
msg "Export the image to ${EXPORT} for use elsewhere"
9498
lxc image export "${IMAGE_ALIAS}" ${EXPORT}
9599
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
97101
fi
98102

99103
lxc delete -f "${BUILD_CONTAINER}"
@@ -126,7 +130,7 @@ prolog() {
126130

127131
X=`groups | grep -q lxd`
128132
if [ $? -eq 1 ]; then
129-
echo "Setting permissions"
133+
msg "Setting permissions"
130134
sudo chmod 0666 /var/snap/lxd/common/lxd/unix.socket
131135
fi
132136
}

0 commit comments

Comments
 (0)