Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cron): add support for entrypoints #255

Merged
merged 2 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions features/src/cron/devcontainer-feature.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "cron",
"name": "Cron",
"description": "Enables cron in the Dev Environment",
"version": "1.1.2",
"version": "1.2.0",
"options": {
"enabled": {
"type": "boolean",
Expand All @@ -18,9 +18,14 @@
"type": "string",
"default": "*/15 * * * *",
"description": "Interval for wp-cron.php"
},
"install-runit-service": {
"type": "boolean",
"default": true,
"description": "Whether to install a runit service for cron"
}
},
"installsAfter": [
"ghcr.io/automattic/vip-codespaces/wordpress"
"ghcr.io/automattic/vip-codespaces/entrypoints"
]
}
3 changes: 3 additions & 0 deletions features/src/cron/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

exec /usr/sbin/crond -l 8 -L /var/log/crond.log
16 changes: 12 additions & 4 deletions features/src/cron/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ if [ "$(id -u || true)" -ne 0 ]; then
fi

: "${_REMOTE_USER:?"_REMOTE_USER is required"}"
: "${ENABLED:=true}"
: "${INSTALL_RUNIT_SERVICE:=true}"

if [ "${ENABLED:-}" = 'true' ]; then
if [ "${ENABLED}" = 'true' ]; then
echo '(*) Installing cron...'

# shellcheck source=/dev/null
Expand Down Expand Up @@ -70,9 +72,15 @@ if [ "${ENABLED:-}" = 'true' ]; then
;;
esac

install -D -m 0755 -o root -g root service-run /etc/sv/cron/run
install -d -m 0755 -o root -g root /etc/service
ln -sf /etc/sv/cron /etc/service/cron
if [ "${INSTALL_RUNIT_SERVICE}" = 'true' ] && [ -d /etc/sv ]; then
install -D -m 0755 -o root -g root service-run /etc/sv/cron/run
install -d -m 0755 -o root -g root /etc/service
ln -sf /etc/sv/cron /etc/service/cron
fi

if [ -d /var/lib/entrypoint.d ]; then
install -m 0755 -o root -g root entrypoint.sh /var/lib/entrypoint.d/50-cron
fi

if [ "${RUN_WP_CRON:-}" = 'true' ] && [ -n "${WP_CRON_SCHEDULE:-}" ]; then
install -m 0755 -o root -g root wp-cron.sh /usr/local/bin/wp-cron.sh
Expand Down
1 change: 1 addition & 0 deletions features/test/cron/alpine.sh
18 changes: 12 additions & 6 deletions features/test/cron/checks.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
#!/bin/bash

check "cron is running" sudo sh -c 'sv status cron | grep -E ^run:'
sudo sv stop cron
check "cron is stopped" sudo sh -c 'sv status cron | grep -E ^down:'
sudo sv start cron
check "cron is running" sudo sh -c 'sv status cron | grep -E ^run:'
if hash sv 2>/dev/null; then
check "cron is running" sudo sh -c 'sv status cron | grep -E ^run:'
sudo sv stop cron
check "cron is stopped" sudo sh -c 'sv status cron | grep -E ^down:'
sudo sv start cron
check "cron is running" sudo sh -c 'sv status cron | grep -E ^run:'
CRON_LOG=/var/log/messages
else
check "cron is running" pgrep crond
CRON_LOG=/var/log/crond.log
fi

check "/var/log/messages has 'started' records" grep -E 'crond .* started' /var/log/messages
check "/var/log/messages has 'started' records" grep -E 'crond .* started' "${CRON_LOG}"

echo "* * * * * touch /tmp/cron-test" | crontab -
ME=$(whoami)
Expand Down
27 changes: 26 additions & 1 deletion features/test/cron/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,37 @@
"cron": {}
}
},

"ubuntu-base": {
"image": "ghcr.io/automattic/vip-codespaces/ubuntu-base:latest",
"overrideCommand": false,
"features": {
"cron": {}
}
},
"alpine": {
"image": "mcr.microsoft.com/devcontainers/base:alpine",
"features": {
"entrypoints": {},
"cron": {
"install-runit-service": false
}
},
"overrideFeatureInstallOrder": [
"./entrypoints",
"./cron"
]
},
"ubuntu": {
"image": "ubuntu:latest",
"features": {
"entrypoints": {},
"cron": {
"install-runit-service": false
}
},
"overrideFeatureInstallOrder": [
"./entrypoints",
"./cron"
]
}
}
1 change: 1 addition & 0 deletions features/test/cron/ubuntu.sh