Skip to content

Commit cfde0bd

Browse files
author
James Healy
authored
Merge pull request #1306 from buildkite/dualstack-parameter
Add new stack parameter for enabling dualstack docker [PLT-2325]
2 parents 0f1e594 + 6ebec1d commit cfde0bd

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

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

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,33 @@ else
6969
echo User namespace remapping not configured.
7070
fi
7171

72+
# One day we can auto-detect whether the instance is v4-only, dualstack or v6-only. To avoid a
73+
# breaking change though, we'll default to ipv4 only and users can opt into v6 support. The elastic
74+
# stack has always defaulted to v4-only so this ensures no breaking behaviour.
75+
# v6-only is currently not an option because docker doesn't support it, but maybe one day....
76+
echo Customising docker network configuration...
77+
78+
if [[ "${DOCKER_NETWORKING_PROTOCOL}" == "ipv4" ]]; then
79+
# This is the default
80+
cat <<<"$(
81+
jq \
82+
'."default-address-pools"=[{"base":"172.17.0.0/12","size":20},{"base":"192.168.0.0/16","size":24}]' \
83+
/etc/docker/daemon.json
84+
)" >/etc/docker/daemon.json
85+
elif [[ "${DOCKER_NETWORKING_PROTOCOL}" == "dualstack" ]]; then
86+
# Using v6 inside containers requires DOCKER_EXPERIMENTAL. This is configured
87+
# further down
88+
DOCKER_EXPERIMENTAL=true
89+
cat <<<"$(
90+
jq \
91+
'.ipv6=true | ."fixed-cidr-v6"="2001:db8:1::/64" | .ip6tables=true | ."default-address-pools"=[{"base":"172.17.0.0/12","size":20},{"base":"192.168.0.0/16","size":24},{"base":"2001:db8:2::/104","size":112}]' \
92+
/etc/docker/daemon.json
93+
)" >/etc/docker/daemon.json
94+
else
95+
# docker 25.0 doesn't support ipv6 only, so we don't support it either
96+
true
97+
fi
98+
7299
if [[ "${DOCKER_EXPERIMENTAL:-false}" == "true" ]]; then
73100
echo Configuring experiment flag for docker daemon...
74101
cat <<<"$(jq '.experimental=true' /etc/docker/daemon.json)" >/etc/docker/daemon.json
@@ -85,13 +112,6 @@ else
85112
echo Instance storage not configured.
86113
fi
87114

88-
echo Customising docker IP address pools...
89-
cat <<<"$(
90-
jq \
91-
'."default-address-pools"=[{"base":"172.17.0.0/12","size":20},{"base":"192.168.0.0/16","size":24}]' \
92-
/etc/docker/daemon.json
93-
)" >/etc/docker/daemon.json
94-
95115
echo Cleaning up docker images...
96116
systemctl start docker-low-disk-gc.service
97117

templates/aws-stack.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,14 @@ Parameters:
462462
- "false"
463463
Default: "true"
464464

465+
DockerNetworkingProtocol:
466+
Type: String
467+
Description: Which IP version to enable for docker containers and building docker images. Only applies to Linux instances, not Windows.
468+
AllowedValues:
469+
- "ipv4"
470+
- "dualstack"
471+
Default: "ipv4"
472+
465473
EnableSecretsPlugin:
466474
Type: String
467475
Description: Enables s3-secrets plugin for all pipelines
@@ -1205,6 +1213,7 @@ Resources:
12051213
<powershell>
12061214
$Env:DOCKER_USERNS_REMAP="${EnableDockerUserNamespaceRemap}"
12071215
$Env:DOCKER_EXPERIMENTAL="${EnableDockerExperimental}"
1216+
$Env:DOCKER_NETWORKING_PROTOCOL="${DockerNetworkingProtocol}"
12081217
powershell -file C:\buildkite-agent\bin\bk-configure-docker.ps1 >> C:\buildkite-agent\elastic-stack.log
12091218
12101219
$Env:BUILDKITE_STACK_NAME="${AWS::StackName}"
@@ -1260,6 +1269,7 @@ Resources:
12601269
#!/bin/bash -v
12611270
DOCKER_USERNS_REMAP=${EnableDockerUserNamespaceRemap} \
12621271
DOCKER_EXPERIMENTAL=${EnableDockerExperimental} \
1272+
DOCKER_NETWORKING_PROTOCOL=${DockerNetworkingProtocol} \
12631273
BUILDKITE_ENABLE_INSTANCE_STORAGE="${EnableInstanceStorage}" \
12641274
/usr/local/bin/bk-configure-docker.sh
12651275
--==BOUNDARY==

0 commit comments

Comments
 (0)