Skip to content

Commit 8c77ec4

Browse files
authored
Merge pull request #1231 from buildkite/pdp-1788-fix-qemu-binfmt-image-is-pulled-during-elastic-ci-stack
2 parents d21ab45 + b8a728f commit 8c77ec4

File tree

6 files changed

+40
-19
lines changed

6 files changed

+40
-19
lines changed

packer/linux/conf/bin/bk-configure-docker.sh

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,31 @@ trap '[[ $? = 0 ]] && on_exit' EXIT
2525
# See https://alestic.com/2010/12/ec2-user-data-output/
2626
exec > >(tee -a /var/log/elastic-stack.log | logger -t user-data -s 2>/dev/console) 2>&1
2727

28+
echo "Starting ${BASH_SOURCE[0]}..."
2829

29-
echo Reading variables from AMI creation...
30+
echo Sourcing /usr/local/lib/bk-configure-docker.sh...
31+
echo This file is written by the scripts in packer/scripts.
32+
echo Note that the path is /usr/local/lib, not /usr/local/bin.
33+
echo Contents of /usr/local/lib/bk-configure-docker.sh:
34+
cat /usr/local/lib/bk-configure-docker.sh
3035
# shellcheck disable=SC1091
3136
source /usr/local/lib/bk-configure-docker.sh
3237

38+
echo Installing qemu binfmt for multiarch...
39+
if ! docker run \
40+
--privileged \
41+
--userns=host \
42+
--pull=never \
43+
--rm \
44+
"tonistiigi/binfmt@${QEMU_BINFMT_DIGEST}" \
45+
--install all
46+
then
47+
echo Failed to install binfmt.
48+
echo Avaliable docker images:
49+
docker image ls
50+
exit 1
51+
fi
52+
3353
if [[ "${DOCKER_USERNS_REMAP:-false}" == "true" ]]; then
3454
echo Configuring user namespace remapping...
3555

@@ -72,17 +92,11 @@ cat <<<"$(jq \
7292
/etc/docker/daemon.json \
7393
)" >/etc/docker/daemon.json
7494

75-
# See https://docs.docker.com/build/building/multi-platform/
76-
echo Installing qemu binfmt for multiarch...
77-
docker run \
78-
--privileged \
79-
--userns=host \
80-
--rm \
81-
"tonistiigi/binfmt:${QEMU_BINFMT_TAG}" \
82-
--install all
83-
8495
echo Cleaning up docker images...
8596
systemctl start docker-low-disk-gc.service
8697

98+
echo Enabling docker-gc timers...
99+
systemctl enable docker-gc.timer docker-low-disk-gc.timer
100+
87101
echo Restarting docker daemon...
88102
systemctl restart docker

packer/linux/conf/bin/bk-install-elastic-stack.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ trap '[[ $? = 0 ]] && on_exit' EXIT
4141
# See https://alestic.com/2010/12/ec2-user-data-output/
4242
exec > >(tee -a /var/log/elastic-stack.log | logger -t user-data -s 2>/dev/console) 2>&1
4343

44+
echo "Starting ${BASH_SOURCE[0]}..."
45+
4446
# This needs to happen first so that the error reporting works
4547
token=$(curl -X PUT -H "X-aws-ec2-metadata-token-ttl-seconds: 60" --fail --silent --show-error --location http://169.254.169.254/latest/api/token)
4648
INSTANCE_ID=$(curl -H "X-aws-ec2-metadata-token: $token" --fail --silent --show-error --location http://169.254.169.254/latest/meta-data/instance-id)

packer/linux/conf/bin/bk-mount-instance-storage.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ trap '[[ $? = 0 ]] && on_exit' EXIT
2222
# See https://alestic.com/2010/12/ec2-user-data-output/
2323
exec > >(tee -a /var/log/elastic-stack.log | logger -t user-data -s 2>/dev/console) 2>&1
2424

25+
echo "Starting ${BASH_SOURCE[0]}..."
26+
2527
# Mount instance storage if we can
2628
# https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/InstanceStorage.html
2729

packer/linux/conf/docker/systemd/docker-gc.service

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,3 @@ Wants=docker-gc.timer
55
[Service]
66
Type=oneshot
77
ExecStart=/usr/local/bin/docker-gc
8-
9-
[Install]
10-
WantedBy=multi-user.target

packer/linux/conf/docker/systemd/docker-low-disk-gc.service

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,3 @@ Wants=docker-low-disk-gc.timer
55
[Service]
66
Type=oneshot
77
ExecStart=/usr/local/bin/docker-low-disk-gc
8-
9-
[Install]
10-
WantedBy=multi-user.target

packer/linux/scripts/install-docker.sh

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ echo "Adding docker systemd timers..."
2020
sudo cp /tmp/conf/docker/scripts/* /usr/local/bin
2121
sudo cp /tmp/conf/docker/systemd/docker-* /etc/systemd/system
2222
sudo chmod +x /usr/local/bin/docker-*
23-
sudo systemctl daemon-reload
24-
sudo systemctl enable docker-gc.timer docker-low-disk-gc.timer
2523

2624
echo "Installing docker buildx..."
2725
DOCKER_CLI_DIR=/usr/libexec/docker/cli-plugins
@@ -47,11 +45,22 @@ sudo cp /tmp/conf/bin/docker-compose /usr/local/bin/docker-compose
4745
sudo chmod +x /usr/local/bin/docker-compose
4846
docker-compose version
4947

48+
# Writing QEMU container version info to /usr/local/lib/bk-configure-docker.sh.
49+
# We only pull this image when we build the AMI. It will be run in
50+
# /usr/local/bin/bk-configure-docker.sh, but it needs to know the image digest
51+
# to make sure it does not pull in another image instead.
52+
# NOTE: the executable file is in /usr/local/bin and it sources as file of the
53+
# same name in /usr/local/lib. These are not the same file.
5054
# See https://docs.docker.com/build/building/multi-platform/
55+
56+
echo Contents of /usr/local/lib/bk-configure-docker.sh:
57+
cat <<'EOF' | sudo tee -a /usr/local/lib/bk-configure-docker.sh
5158
QEMU_BINFMT_VERSION=7.0.0-28
5259
QEMU_BINFMT_DIGEST=sha256:66e11bea77a5ea9d6f0fe79b57cd2b189b5d15b93a2bdb925be22949232e4e55
5360
QEMU_BINFMT_TAG="qemu-v${QEMU_BINFMT_VERSION}@${QEMU_BINFMT_DIGEST}"
61+
EOF
62+
# shellcheck disable=SC1091
63+
source /usr/local/lib/bk-configure-docker.sh
5464
sudo mkdir -p /usr/local/lib
55-
echo "QEMU_BINFMT_TAG=\"$QEMU_BINFMT_TAG\"" | sudo tee -a /usr/local/lib/bk-configure-docker.sh
5665
echo Pulling qemu binfmt for multiarch...
5766
sudo docker pull "tonistiigi/binfmt:${QEMU_BINFMT_TAG}"

0 commit comments

Comments
 (0)