feat: Docker registry mirror (#478)
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 #478 for how this feature is tested and supposed to be used.
This commit is contained in:
parent
dc4cf3f57b
commit
6b77a2a5a8
|
|
@ -1,6 +1,6 @@
|
||||||
# Contributing
|
# Contributing
|
||||||
|
|
||||||
### Helm Verison Bumps
|
### Helm Version Bumps
|
||||||
|
|
||||||
**Chart Version :** When bumping the chart version follow semantic versioning https://semver.org/<br />
|
**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.
|
**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.
|
||||||
|
|
|
||||||
|
|
@ -591,6 +591,8 @@ spec:
|
||||||
# false (default) = Docker support is provided by a sidecar container deployed in the runner pod.
|
# 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.
|
# 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
|
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
|
# Docker sidecar container image tweaks examples below, only applicable if dockerdWithinRunnerContainer = false
|
||||||
dockerdContainerResources:
|
dockerdContainerResources:
|
||||||
limits:
|
limits:
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ package v1alpha1
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"k8s.io/apimachinery/pkg/api/resource"
|
"k8s.io/apimachinery/pkg/api/resource"
|
||||||
|
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
|
|
@ -98,6 +99,8 @@ type RunnerSpec struct {
|
||||||
// +optional
|
// +optional
|
||||||
DockerMTU *int64 `json:"dockerMTU,omitempty"`
|
DockerMTU *int64 `json:"dockerMTU,omitempty"`
|
||||||
// +optional
|
// +optional
|
||||||
|
DockerRegistryMirror *string `json:"dockerRegistryMirror,omitempty"`
|
||||||
|
// +optional
|
||||||
HostAliases []corev1.HostAlias `json:"hostAliases,omitempty"`
|
HostAliases []corev1.HostAlias `json:"hostAliases,omitempty"`
|
||||||
// +optional
|
// +optional
|
||||||
VolumeSizeLimit *resource.Quantity `json:"volumeSizeLimit,omitempty"`
|
VolumeSizeLimit *resource.Quantity `json:"volumeSizeLimit,omitempty"`
|
||||||
|
|
|
||||||
|
|
@ -706,6 +706,11 @@ func (in *RunnerSpec) DeepCopyInto(out *RunnerSpec) {
|
||||||
*out = new(int64)
|
*out = new(int64)
|
||||||
**out = **in
|
**out = **in
|
||||||
}
|
}
|
||||||
|
if in.DockerRegistryMirror != nil {
|
||||||
|
in, out := &in.DockerRegistryMirror, &out.DockerRegistryMirror
|
||||||
|
*out = new(string)
|
||||||
|
**out = **in
|
||||||
|
}
|
||||||
if in.HostAliases != nil {
|
if in.HostAliases != nil {
|
||||||
in, out := &in.HostAliases, &out.HostAliases
|
in, out := &in.HostAliases, &out.HostAliases
|
||||||
*out = make([]v1.HostAlias, len(*in))
|
*out = make([]v1.HostAlias, len(*in))
|
||||||
|
|
|
||||||
|
|
@ -436,6 +436,8 @@ spec:
|
||||||
dockerMTU:
|
dockerMTU:
|
||||||
format: int64
|
format: int64
|
||||||
type: integer
|
type: integer
|
||||||
|
dockerRegistryMirror:
|
||||||
|
type: string
|
||||||
dockerVolumeMounts:
|
dockerVolumeMounts:
|
||||||
items:
|
items:
|
||||||
description: VolumeMount describes a mounting of a Volume within a container.
|
description: VolumeMount describes a mounting of a Volume within a container.
|
||||||
|
|
|
||||||
|
|
@ -436,6 +436,8 @@ spec:
|
||||||
dockerMTU:
|
dockerMTU:
|
||||||
format: int64
|
format: int64
|
||||||
type: integer
|
type: integer
|
||||||
|
dockerRegistryMirror:
|
||||||
|
type: string
|
||||||
dockerVolumeMounts:
|
dockerVolumeMounts:
|
||||||
items:
|
items:
|
||||||
description: VolumeMount describes a mounting of a Volume within a container.
|
description: VolumeMount describes a mounting of a Volume within a container.
|
||||||
|
|
|
||||||
|
|
@ -401,6 +401,8 @@ spec:
|
||||||
dockerMTU:
|
dockerMTU:
|
||||||
format: int64
|
format: int64
|
||||||
type: integer
|
type: integer
|
||||||
|
dockerRegistryMirror:
|
||||||
|
type: string
|
||||||
dockerVolumeMounts:
|
dockerVolumeMounts:
|
||||||
items:
|
items:
|
||||||
description: VolumeMount describes a mounting of a Volume within a container.
|
description: VolumeMount describes a mounting of a Volume within a container.
|
||||||
|
|
|
||||||
|
|
@ -436,6 +436,8 @@ spec:
|
||||||
dockerMTU:
|
dockerMTU:
|
||||||
format: int64
|
format: int64
|
||||||
type: integer
|
type: integer
|
||||||
|
dockerRegistryMirror:
|
||||||
|
type: string
|
||||||
dockerVolumeMounts:
|
dockerVolumeMounts:
|
||||||
items:
|
items:
|
||||||
description: VolumeMount describes a mounting of a Volume within a container.
|
description: VolumeMount describes a mounting of a Volume within a container.
|
||||||
|
|
|
||||||
|
|
@ -436,6 +436,8 @@ spec:
|
||||||
dockerMTU:
|
dockerMTU:
|
||||||
format: int64
|
format: int64
|
||||||
type: integer
|
type: integer
|
||||||
|
dockerRegistryMirror:
|
||||||
|
type: string
|
||||||
dockerVolumeMounts:
|
dockerVolumeMounts:
|
||||||
items:
|
items:
|
||||||
description: VolumeMount describes a mounting of a Volume within a container.
|
description: VolumeMount describes a mounting of a Volume within a container.
|
||||||
|
|
|
||||||
|
|
@ -401,6 +401,8 @@ spec:
|
||||||
dockerMTU:
|
dockerMTU:
|
||||||
format: int64
|
format: int64
|
||||||
type: integer
|
type: integer
|
||||||
|
dockerRegistryMirror:
|
||||||
|
type: string
|
||||||
dockerVolumeMounts:
|
dockerVolumeMounts:
|
||||||
items:
|
items:
|
||||||
description: VolumeMount describes a mounting of a Volume within a container.
|
description: VolumeMount describes a mounting of a Volume within a container.
|
||||||
|
|
|
||||||
|
|
@ -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.
|
// /runner must be generated on runtime from /runnertmp embedded in the container image.
|
||||||
//
|
//
|
||||||
|
|
@ -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 {
|
if len(runner.Spec.Containers) != 0 {
|
||||||
|
|
|
||||||
|
|
@ -20,21 +20,17 @@ function wait_for_process () {
|
||||||
sudo /bin/bash <<SCRIPT
|
sudo /bin/bash <<SCRIPT
|
||||||
mkdir -p /etc/docker
|
mkdir -p /etc/docker
|
||||||
|
|
||||||
cat <<EOS > /etc/docker/daemon.json
|
echo "{}" > /etc/docker/daemon.json
|
||||||
{
|
|
||||||
EOS
|
|
||||||
|
|
||||||
if [ -n "${MTU}" ]; then
|
if [ -n "${MTU}" ]; then
|
||||||
cat <<EOS >> /etc/docker/daemon.json
|
jq ".\"mtu\" = ${MTU}" /etc/docker/daemon.json > /tmp/.daemon.json && mv /tmp/.daemon.json /etc/docker/daemon.json
|
||||||
"mtu": ${MTU}
|
|
||||||
EOS
|
|
||||||
# See https://docs.docker.com/engine/security/rootless/
|
# See https://docs.docker.com/engine/security/rootless/
|
||||||
echo "environment=DOCKERD_ROOTLESS_ROOTLESSKIT_MTU=${MTU}" >> /etc/supervisor/conf.d/dockerd.conf
|
echo "environment=DOCKERD_ROOTLESS_ROOTLESSKIT_MTU=${MTU}" >> /etc/supervisor/conf.d/dockerd.conf
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cat <<EOS >> /etc/docker/daemon.json
|
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
|
||||||
EOS
|
fi
|
||||||
SCRIPT
|
SCRIPT
|
||||||
|
|
||||||
INFO "Using /etc/docker/daemon.json with the following content"
|
INFO "Using /etc/docker/daemon.json with the following content"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue