Skip to content

Commit

Permalink
Merge pull request #254 from Automattic/add-eatmydata
Browse files Browse the repository at this point in the history
feat(base): set up eatmydata to accelerate installs
  • Loading branch information
sjinks authored Jun 22, 2024
2 parents 80d5e7f + 2344381 commit 74bbda0
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 2 deletions.
5 changes: 3 additions & 2 deletions features/src/base/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"id": "base",
"name": "VIP Codespaces Base",
"version": "1.1.1",
"version": "1.2.0",
"description": "Base feature for VIP Codespaces",
"containerEnv": {
"PAGER": "\"/usr/bin/less -R\""
"PAGER": "\"/usr/bin/less -R\"",
"LD_PRELOAD": "/usr/lib/libeatmydata/libeatmydata.so"
},
"customizations": {
"vscode": {
Expand Down
74 changes: 74 additions & 0 deletions features/src/base/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,77 @@ install -d -D -m 0755 -o "${_REMOTE_USER}" -g "${_REMOTE_USER}" "${HOME_DIR}/.lo

install -m 0644 -o "${_REMOTE_USER}" -g "${_REMOTE_USER}" .bashrc "${HOME_DIR}/.bashrc"
install -m 0644 -o "${_REMOTE_USER}" -g "${_REMOTE_USER}" 001-welcome.sh "${HOME_DIR}/.local/share/vip-codespaces/login/001-welcome.sh"

# shellcheck source=/dev/null
. /etc/os-release

: "${ID:=}"
: "${ID_LIKE:=${ID}}"

PACKAGES=""
ARCH="$(arch)"
case "${ID_LIKE}" in
"debian")
export DEBIAN_FRONTEND=noninteractive
PACKAGES=""
if ! hash eatmydata >/dev/null 2>&1; then
PACKAGES="${PACKAGES} eatmydata"
fi

if ! hash curl >/dev/null 2>&1; then
PACKAGES="${PACKAGES} curl"
fi

if ! hash update-ca-certificates >/dev/null 2>&1; then
PACKAGES="${PACKAGES} ca-certificates"
fi

if ! hash gpg >/dev/null 2>&1; then
PACKAGES="${PACKAGES} gnupg2"
fi

if ! hash lsb_release >/dev/null 2>&1; then
PACKAGES="${PACKAGES} lsb-release"
fi

if ! hash envsubst >/dev/null 2>&1; then
PACKAGES="${PACKAGES} gettext"
fi

if [ -n "${PACKAGES}" ]; then
apt-get update
# shellcheck disable=SC2086
apt-get install -y --no-install-recommends ${PACKAGES}
fi

mkdir -p /usr/lib/libeatmydata
ln -sf -t /usr/lib/libeatmydata/ "/usr/lib/${ARCH}-linux-gnu/libeatmydata.so"*
;;

"alpine")
if ! hash eatmydata >/dev/null 2>&1; then
PACKAGES="${PACKAGES} libeatmydata"
fi

if ! hash curl >/dev/null 2>&1; then
PACKAGES="${PACKAGES} curl"
fi

if ! hash envsubst >/dev/null 2>&1; then
PACKAGES="${PACKAGES} gettext"
fi

if [ -n "${PACKAGES}" ]; then
# shellcheck disable=SC2086
apk add --no-cache ${PACKAGES}
fi

mkdir -p /usr/lib/libeatmydata
ln -sf /usr/lib/libeatmydata.so /usr/lib/libeatmydata/libeatmydata.so
;;

*)
echo "Unsupported distribution: ${ID_LIKE}"
exit 1
;;
esac
4 changes: 4 additions & 0 deletions features/test/base/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ check "${HOME}/.local/share/vip-codespaces exists" test -d "${HOME}/.local/share
check "${HOME}/.local/share/vip-codespaces/login exists" test -d "${HOME}/.local/share/vip-codespaces/login"
check "${HOME}/.local/share/vip-codespaces/login/001-welcome.sh exists" test -f "${HOME}/.local/share/vip-codespaces/login/001-welcome.sh"

# shellcheck disable=SC2016
check "LD_PRELOAD is set correctly" sh -c 'echo "${LD_PRELOAD}" | grep -q "/usr/lib/libeatmydata/libeatmydata.so"'
check "/usr/lib/libeatmydata/libeatmydata.so exists" test -L /usr/lib/libeatmydata/libeatmydata.so

# Microsoft's base images contain zsh. We don't want to run this check for MS images because we have no control over the installed services.
if test -d /etc/rc2.d && ! test -e /usr/bin/zsh; then
dir="$(ls -1 /etc/rc2.d)"
Expand Down

0 comments on commit 74bbda0

Please sign in to comment.