Skip to content

Commit

Permalink
Log disk stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
matthchr committed Oct 3, 2023
1 parent 49c2198 commit 58b7274
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .github/workflows/pr-validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ jobs:
fetch-depth: 0 # required to access tags
submodules: 'true'

- name: Force docker to SSD
run: scripts/v2/linux-docker-use-ssd.sh --containerd true

- name: check-changes
id: check-changes
run: scripts/v2/check-changes.sh
Expand Down Expand Up @@ -121,6 +124,9 @@ jobs:

- name: Build docker image & build configuration YAML
run: |
df -H
docker info
docker image list
container_id=${{ env.container_id }}
docker exec "$container_id" task controller:docker-build-and-save
docker exec "$container_id" task controller:run-kustomize-for-envtest
Expand Down
80 changes: 80 additions & 0 deletions scripts/v2/linux-docker-use-ssd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/usr/bin/env bash

# This artifact use the temp disk (SSD) for docker and optionally containerd if a temp disk is available
# This was copied from https://devdiv.visualstudio.com/_git/XlabImageFactory?path=%2Fartifacts%2Flinux-docker-use-ssd%2Flinux-docker-use-ssd.sh
# We should consider using a 1ES managed image so we can just use that script directly.

set -e

# check if temp disk is mounted at /mnt and if not exit early
if ! mountpoint -q /mnt; then
echo "INFO: No temp disk mounted at /mnt, skipping artifact"
exit 0
fi

# check if docker is installed
if ! command -v docker &> /dev/null; then
echo "ERROR: Docker is not installed" 1>&2
exit 1
fi

# check if jq is installed
if ! command -v jq &> /dev/null; then
echo "ERROR: jq is not installed" 1>&2
exit 1
fi

CONTAINERD="false"
while [[ $# -gt 0 ]]; do
case $1 in
--containerd)
CONTAINERD="$2"
echo -e "INFO: containerd: ${CONTAINERD}"
shift
shift
;;
*)
echo "Error: Unknown argument \"$1\"" 1>&2
exit 1
;;
esac
done

if [[ "${CONTAINERD,,}" == "true" ]]; then
CONTAINERD_CONFIG="/etc/containerd/config.toml"
CONTAINERD_ROOT="/mnt/containerd"

if ! command -v containerd &> /dev/null; then
echo "ERROR: containerd is not installed, skipping artifact" 1>&2
exit 1
fi

mkdir -p "${CONTAINERD_ROOT}"

existing_config=$(if [ -f "${CONTAINERD_CONFIG}" ]; then cat ${CONTAINERD_CONFIG}; else echo ""; fi)

# Gets all lines of the config except the one that starts with root and adds the root line to the top of the file
echo "${existing_config}" | grep -v "^root" | sed "1i root = \"${CONTAINERD_ROOT}\"" > ${CONTAINERD_CONFIG}

systemctl restart containerd
fi

DAEMON_JSON="/etc/docker/daemon.json"
DOCKER_ROOT="/mnt/docker"

if [ ! -f "${DAEMON_JSON}" ]; then
echo "INFO: Creating ${DAEMON_JSON}"
echo "{}" > "${DAEMON_JSON}"
fi

mkdir -p "${DOCKER_ROOT}"
new_config=$(jq --arg root "${DOCKER_ROOT}" '. += { "data-root": $root }' "${DAEMON_JSON}")

echo "INFO: Updated docker daemon config:"
echo "${new_config}"
echo "${new_config}" > "${DAEMON_JSON}"

echo "INFO: Restarting docker"
systemctl restart docker

docker info

0 comments on commit 58b7274

Please sign in to comment.