Skip to content

Commit

Permalink
Fix MTU configuration for dockerd (actions#421)
Browse files Browse the repository at this point in the history
Resolves actions#393
  • Loading branch information
mumoshu authored Mar 31, 2021
1 parent da4dfb3 commit 156e2c1
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
11 changes: 11 additions & 0 deletions acceptance/testdata/runnerdeploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,14 @@ spec:
template:
spec:
repository: mumoshu/actions-runner-controller-ci
#
# dockerd within runner container
#
## Replace `mumoshu/actions-runner-dind:dev` with your dind image
#dockerdWithinRunnerContainer: true
#image: mumoshu/actions-runner-dind:dev

#
# Set the MTU used by dockerd-managed network interfaces (including docker-build)
#
#dockerMTU: 1450
7 changes: 7 additions & 0 deletions controllers/runner_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,7 @@ func (r *RunnerReconciler) newPod(runner v1alpha1.Runner) (corev1.Pod, error) {
pod.Spec.Containers = append(pod.Spec.Containers, corev1.Container{
Name: "docker",
Image: r.DockerImage,
Args: []string{"dockerd"},
VolumeMounts: []corev1.VolumeMount{
{
Name: "work",
Expand Down Expand Up @@ -731,11 +732,17 @@ func (r *RunnerReconciler) newPod(runner v1alpha1.Runner) (corev1.Pod, error) {

if mtu := runner.Spec.DockerMTU; mtu != nil {
pod.Spec.Containers[1].Env = append(pod.Spec.Containers[1].Env, []corev1.EnvVar{
// See https://docs.docker.com/engine/security/rootless/
{
Name: "DOCKERD_ROOTLESS_ROOTLESSKIT_MTU",
Value: fmt.Sprintf("%d", *runner.Spec.DockerMTU),
},
}...)

pod.Spec.Containers[1].Args = append(pod.Spec.Containers[1].Args,
"--mtu",
fmt.Sprintf("%d", *runner.Spec.DockerMTU),
)
}

}
Expand Down
30 changes: 30 additions & 0 deletions runner/startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,34 @@ function wait_for_process () {
return 0
}

sudo /bin/bash <<SCRIPT
mkdir -p /etc/docker
cat <<EOS > /etc/docker/daemon.json
{
EOS
if [ -n "${MTU}" ]; then
cat <<EOS >> /etc/docker/daemon.json
"mtu": ${MTU}
EOS
# See https://docs.docker.com/engine/security/rootless/
echo "environment=DOCKERD_ROOTLESS_ROOTLESSKIT_MTU=${MTU}" >> /etc/supervisor/conf.d/dockerd.conf
fi
cat <<EOS >> /etc/docker/daemon.json
}
EOS
SCRIPT

INFO "Using /etc/docker/daemon.json with the following content"

cat /etc/docker/daemon.json

INFO "Using /etc/supervisor/conf.d/dockerd.conf with the following content"

cat /etc/supervisor/conf.d/dockerd.conf

INFO "Starting supervisor"
sudo /usr/bin/supervisord -n >> /dev/null 2>&1 &

Expand All @@ -27,6 +55,8 @@ for process in "${processes[@]}"; do
wait_for_process "$process"
if [ $? -ne 0 ]; then
ERROR "$process is not running after max time"
ERROR "Dumping /var/log/dockerd.err.log to help investigation"
cat /var/log/dockerd.err.log
exit 1
else
INFO "$process is running"
Expand Down

0 comments on commit 156e2c1

Please sign in to comment.