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

Avoid running apt-get more than once per day #2281

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ permalink: /docs/en-US/changelog/
* Install WP-CLI doctor package ( #2051 )
* Enhanced database backup terminal output ( #2256 )
* Sites with no `hosts` defined will now default to `{sitename}.test` ( #2267 )
* Avoid `apt-get update` to run on the main provisioner on every provision ( #2272 )

### Deprecations

Expand Down
26 changes: 22 additions & 4 deletions provision/provision-helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export GREEN="\033[38;5;2m"
export RED="\033[38;5;9m"
export CRESET="\033[0m"
export BOLD="\033[1m"
export VVV_APT_GET_EVERY=$((60*60*24)) # every day

VVV_CONFIG=/vagrant/vvv-custom.yml
if [[ -f /vagrant/config.yml ]]; then
Expand Down Expand Up @@ -152,6 +153,25 @@ function noroot() {
}
export -f noroot

function vvv_maybe_run_apt_update() {
curr_date=$(date +%s)
last_apt_update=0
if [ -f /vvv/apt_update_last_run ]; then
last_apt_update=$(stat -c %Y "/vvv/apt_update_last_run")
fi
diff=$((curr_date-last_apt_update));

if [ "$diff" -lt "$VVV_APT_GET_EVERY" ]; then
return
fi
touch /vvv/apt_update_last_run

echo " * Running apt-get update..."
rm -rf /var/lib/apt/lists/*
apt-get update -y --fix-missing
}
export -f vvv_maybe_run_apt_update

function vvv_apt_keys_has() {
local keys=$( apt-key list )
if [[ ! $( echo "${keys}" | grep "$1") ]]; then
Expand Down Expand Up @@ -280,10 +300,8 @@ vvv_package_install() {
echo " * Updating apt keys"
apt-key update -y

# Update all of the package references before installing anything
echo " * Running apt-get update..."
rm -rf /var/lib/apt/lists/*
apt-get update -y --fix-missing
# Maybe update all of the package references before installing anything
vvv_maybe_run_apt_update

# Install required packages
echo " * Installing apt-get packages..."
Expand Down
1 change: 1 addition & 0 deletions provision/provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
. "/srv/config/bash_aliases"

# cleanup
mkdir -p /vvv
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imo this should go in /vagrant and the move to /vvv should be a separate issue where we symlink it to /vagrant, that way we aren't spreading things across multiple folders

mkdir -p /vagrant
rm -rf /vagrant/failed_provisioners
mkdir -p /vagrant/failed_provisioners
Expand Down