Skip to content

Commit 1dbe63b

Browse files
authored
Merge pull request #587 from cloudfoundry/add-ubuntu-server-resilience
Add apt retries, optional mirror for debootstrap
2 parents 120a43d + 2b41de6 commit 1dbe63b

8 files changed

Lines changed: 20 additions & 11 deletions

File tree

bosh-stemcell/lib/bosh/stemcell/builder_options.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def ovf_options
6161
def environment_variables
6262
{
6363
"UBUNTU_ISO" => environment["UBUNTU_ISO"],
64-
"UBUNTU_MIRROR" => environment["UBUNTU_MIRROR"],
64+
"UBUNTU_DEBOOTSTRAP_MIRROR" => environment["UBUNTU_DEBOOTSTRAP_MIRROR"],
6565
"UBUNTU_ADVANTAGE_TOKEN" => environment["UBUNTU_ADVANTAGE_TOKEN"],
6666
"UBUNTU_FIPS_USE_IAAS_KERNEL" => environment["UBUNTU_FIPS_USE_IAAS_KERNEL"]
6767
}

bosh-stemcell/spec/bosh/stemcell/builder_options_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def self.it_sets_correct_environment_variables
6464
let(:env) do
6565
{
6666
"UBUNTU_ISO" => "fake_ubuntu_iso",
67-
"UBUNTU_MIRROR" => "fake_ubuntu_mirror",
67+
"UBUNTU_DEBOOTSTRAP_MIRROR" => "fake_ubuntu_mirror",
6868
"RUBY_BIN" => "fake_ruby_bin"
6969
}
7070
end
@@ -76,7 +76,7 @@ def self.it_sets_correct_environment_variables
7676
expect(result["stemcell_infrastructure"]).to eq(infrastructure.name)
7777
expect(result["stemcell_hypervisor"]).to eq(infrastructure.hypervisor)
7878
expect(result["UBUNTU_ISO"]).to eq("fake_ubuntu_iso")
79-
expect(result["UBUNTU_MIRROR"]).to eq("fake_ubuntu_mirror")
79+
expect(result["UBUNTU_DEBOOTSTRAP_MIRROR"]).to eq("fake_ubuntu_mirror")
8080
expect(result["ruby_bin"]).to eq("fake_ruby_bin")
8181
expect(result["image_create_disk_size"]).to eq(default_disk_size)
8282
expect(result["os_image_tgz"]).to eq("fake/os_image.tgz")

ci/pipelines/builder.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ jobs:
248248
params:
249249
OPERATING_SYSTEM_NAME: ubuntu
250250
OPERATING_SYSTEM_VERSION: (@= data.values.stemcell_details.os_short_name @)
251+
UBUNTU_DEBOOTSTRAP_MIRROR: http://gce.archive.ubuntu.com/ubuntu # Ubuntu's GCP-internal mirror, must change if we change Concourse IaaS!
251252
privileged: true
252253
vars:
253254
image_os_tag: (@= data.values.stemcell_details.os_short_name @)

ci/tasks/os-images/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ params:
1919
OPERATING_SYSTEM_VERSION: replace-me
2020
ESM_TOKEN:
2121
UBUNTU_ADVANTAGE_TOKEN:
22+
UBUNTU_DEBOOTSTRAP_MIRROR:

stemcell_builder/lib/prelude_apply.bash

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,23 @@ fi
2222
# Mark /opt/bosh as a safe git repo to avoid "fatal: unsafe repository ('/opt/bosh' is owned by someone else)"
2323
git config --global --add safe.directory /opt/bosh
2424

25+
# Apt retry / timeout options applied to every apt-get invocation during the
26+
# build. Passed via -o so nothing leaks into the resulting OS image, and so
27+
# that flaky upstream mirrors (notably snapshot.ubuntu.com) don't take down
28+
# multi-hour builds on a single transient 503. Acquire::Retries::Delay=true
29+
# enables exponential backoff (apt >= 2.0).
30+
APT_RETRY_OPTS='-o Acquire::Retries=10 -o Acquire::Retries::Delay=true -o Acquire::http::Timeout=120 -o Acquire::https::Timeout=120'
31+
2532
function pkg_mgr {
26-
run_in_chroot $chroot "apt-get update"
27-
run_in_chroot $chroot "export DEBIAN_FRONTEND=noninteractive; apt-get --fix-broken --no-install-recommends --assume-yes $*"
33+
run_in_chroot $chroot "apt-get $APT_RETRY_OPTS update"
34+
run_in_chroot $chroot "export DEBIAN_FRONTEND=noninteractive; apt-get $APT_RETRY_OPTS --fix-broken --no-install-recommends --assume-yes $*"
2835
run_in_chroot $chroot "apt-get clean"
2936
}
3037

3138
# checks if an OS package with the given name exists in the current database of available packages.
3239
# returns 0 if package exists (whether or not is is installed); 1 otherwise
3340
function pkg_exists {
34-
run_in_chroot $chroot "apt-get update"
41+
run_in_chroot $chroot "apt-get $APT_RETRY_OPTS update"
3542
result=`run_in_chroot $chroot "if apt-cache show $1 2>/dev/null >/dev/null; then echo exists; else echo does not exist; fi"`
3643
if [[ "$result" == *"exists"* ]]; then
3744
return 0

stemcell_builder/lib/prelude_fips.bash

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fi
2222
function ua_attach() {
2323
echo "Setting up Ubuntu Advantage ..."
2424

25-
DEBIAN_FRONTEND=noninteractive run_in_chroot ${chroot} "apt-get install --assume-yes ubuntu-pro-client"
25+
DEBIAN_FRONTEND=noninteractive run_in_chroot ${chroot} "apt-get $APT_RETRY_OPTS install --assume-yes ubuntu-pro-client"
2626

2727
run_in_chroot ${chroot} "ua attach --no-auto-enable ${UBUNTU_ADVANTAGE_TOKEN}"
2828
}
@@ -117,7 +117,7 @@ PSUEDO_GRUB_PROBE
117117

118118
function mock_grub_probe() {
119119
# make sure /usr/sbin/grub-probe is installed in the chroot
120-
DEBIAN_FRONTEND=noninteractive run_in_chroot ${chroot} "apt-get install --assume-yes grub-common"
120+
DEBIAN_FRONTEND=noninteractive run_in_chroot ${chroot} "apt-get $APT_RETRY_OPTS install --assume-yes grub-common"
121121
gprobe="${chroot}/usr/sbin/grub-probe"
122122
if [ -f "${gprobe}" ]; then
123123
mv "${gprobe}" "${gprobe}.dist"

stemcell_builder/stages/base_debootstrap/apply.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ cleanup_debootstrap() {
7676
}
7777
trap cleanup_debootstrap EXIT
7878

79-
debootstrap --arch="$base_debootstrap_arch" "$base_debootstrap_suite" "$chroot" ""
79+
debootstrap --arch="$base_debootstrap_arch" "$base_debootstrap_suite" "$chroot" "${UBUNTU_DEBOOTSTRAP_MIRROR:-}"
8080

8181
cleanup_debootstrap
8282
trap - EXIT

stemcell_builder/stages/base_debootstrap/config.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ then
1313
persist UBUNTU_ISO
1414
fi
1515

16-
if [ ! -z "${UBUNTU_MIRROR:-}" ]
16+
if [ ! -z "${UBUNTU_DEBOOTSTRAP_MIRROR:-}" ]
1717
then
18-
persist UBUNTU_MIRROR
18+
persist UBUNTU_DEBOOTSTRAP_MIRROR
1919
fi
2020

2121
base_debootstrap_arch=amd64

0 commit comments

Comments
 (0)