Skip to content

Commit

Permalink
feat: Docker registry mirror (actions#478)
Browse files Browse the repository at this point in the history
Changes:

- Switched to use `jq` in startup.sh
- Enable docker registry mirror configuration which is useful when e.g. avoiding the Docker Hub rate-limiting

Check actions#478 for how this feature is tested and supposed to be used.
  • Loading branch information
rofafor authored Apr 25, 2021
1 parent dc4cf3f commit 6b77a2a
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Contributing

### Helm Verison Bumps
### Helm Version Bumps

**Chart Version :** When bumping the chart version follow semantic versioning https://semver.org/<br />
**App Version :** When bumping the app version you will also need to bump the chart verison too. Again, follow semantic verisoning when bumping the chart.
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,8 @@ spec:
# false (default) = Docker support is provided by a sidecar container deployed in the runner pod.
# true = No docker sidecar container is deployed in the runner pod but docker can be used within teh runner container instead. The image summerwind/actions-runner-dind is used by default.
dockerdWithinRunnerContainer: true
# Optional Docker registry mirror, only applicable if dockerdWithinRunnerContainer = true
dockerRegistryMirror: https://mirror.gcr.io/
# Docker sidecar container image tweaks examples below, only applicable if dockerdWithinRunnerContainer = false
dockerdContainerResources:
limits:
Expand Down
3 changes: 3 additions & 0 deletions api/v1alpha1/runner_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package v1alpha1

import (
"errors"

"k8s.io/apimachinery/pkg/api/resource"

corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -98,6 +99,8 @@ type RunnerSpec struct {
// +optional
DockerMTU *int64 `json:"dockerMTU,omitempty"`
// +optional
DockerRegistryMirror *string `json:"dockerRegistryMirror,omitempty"`
// +optional
HostAliases []corev1.HostAlias `json:"hostAliases,omitempty"`
// +optional
VolumeSizeLimit *resource.Quantity `json:"volumeSizeLimit,omitempty"`
Expand Down
5 changes: 5 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,8 @@ spec:
dockerMTU:
format: int64
type: integer
dockerRegistryMirror:
type: string
dockerVolumeMounts:
items:
description: VolumeMount describes a mounting of a Volume within a container.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,8 @@ spec:
dockerMTU:
format: int64
type: integer
dockerRegistryMirror:
type: string
dockerVolumeMounts:
items:
description: VolumeMount describes a mounting of a Volume within a container.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,8 @@ spec:
dockerMTU:
format: int64
type: integer
dockerRegistryMirror:
type: string
dockerVolumeMounts:
items:
description: VolumeMount describes a mounting of a Volume within a container.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,8 @@ spec:
dockerMTU:
format: int64
type: integer
dockerRegistryMirror:
type: string
dockerVolumeMounts:
items:
description: VolumeMount describes a mounting of a Volume within a container.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,8 @@ spec:
dockerMTU:
format: int64
type: integer
dockerRegistryMirror:
type: string
dockerVolumeMounts:
items:
description: VolumeMount describes a mounting of a Volume within a container.
Expand Down
2 changes: 2 additions & 0 deletions config/crd/bases/actions.summerwind.dev_runners.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,8 @@ spec:
dockerMTU:
format: int64
type: integer
dockerRegistryMirror:
type: string
dockerVolumeMounts:
items:
description: VolumeMount describes a mounting of a Volume within a container.
Expand Down
14 changes: 14 additions & 0 deletions controllers/runner_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,15 @@ func (r *RunnerReconciler) newPod(runner v1alpha1.Runner) (corev1.Pod, error) {
}...)
}

if mirror := runner.Spec.DockerRegistryMirror; mirror != nil && dockerdInRunner {
pod.Spec.Containers[0].Env = append(pod.Spec.Containers[0].Env, []corev1.EnvVar{
{
Name: "DOCKER_REGISTRY_MIRROR",
Value: *runner.Spec.DockerRegistryMirror,
},
}...)
}

//
// /runner must be generated on runtime from /runnertmp embedded in the container image.
//
Expand Down Expand Up @@ -758,6 +767,11 @@ func (r *RunnerReconciler) newPod(runner v1alpha1.Runner) (corev1.Pod, error) {
)
}

if mirror := runner.Spec.DockerRegistryMirror; mirror != nil {
pod.Spec.Containers[1].Args = append(pod.Spec.Containers[1].Args,
fmt.Sprintf("--registry-mirror=%s", *runner.Spec.DockerRegistryMirror),
)
}
}

if len(runner.Spec.Containers) != 0 {
Expand Down
14 changes: 5 additions & 9 deletions runner/startup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,17 @@ function wait_for_process () {
sudo /bin/bash <<SCRIPT
mkdir -p /etc/docker
cat <<EOS > /etc/docker/daemon.json
{
EOS
echo "{}" > /etc/docker/daemon.json
if [ -n "${MTU}" ]; then
cat <<EOS >> /etc/docker/daemon.json
"mtu": ${MTU}
EOS
jq ".\"mtu\" = ${MTU}" /etc/docker/daemon.json > /tmp/.daemon.json && mv /tmp/.daemon.json /etc/docker/daemon.json
# 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
if [ -n "${DOCKER_REGISTRY_MIRROR}" ]; then
jq ".\"registry-mirrors\"[0] = \"${DOCKER_REGISTRY_MIRROR}\"" /etc/docker/daemon.json > /tmp/.daemon.json && mv /tmp/.daemon.json /etc/docker/daemon.json
fi
SCRIPT

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

0 comments on commit 6b77a2a

Please sign in to comment.