Skip to content

Commit 44e774c

Browse files
authored
Merge pull request #25 from thediveo/develop
feat: pull-through-cache-registry
2 parents 516b36f + 2a3df0c commit 44e774c

File tree

11 files changed

+251
-15
lines changed

11 files changed

+251
-15
lines changed

.github/workflows/test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
- local-pkgsite
2727
- nerdctl
2828
- pin-github-action
29+
- pull-through-cache-registry
2930
- wal-wahl
3031
baseImage:
3132
- mcr.microsoft.com/devcontainers/base:ubuntu-24.04

README.md

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,22 @@ Alpine](https://github.com/devcontainers/features/blob/091886b3568dad70f835cc428
1212
Same unfortunate situation Microsoft's node Dev Container feature that also
1313
doesn't support Alpine.
1414

15-
| Feature | Alpine | Alma | Debian | Fedora | Ubuntu |
16-
| ----------------- | ------ | ---- | ------ | ------ | ------ |
17-
| bpftool ||||||
18-
| cni-plugins | |||||
19-
| docsify | | ? || ? ||
20-
| go-ebpf | |||||
21-
| go-mod-upgrade | |||||
22-
| gocover | |||||
23-
| goreportcard | |||||
24-
| grafanactl ||||||
25-
| lazygit ||||||
26-
| local-pkgsite | |||||
27-
| nerdctl | |||||
28-
| pin-github-action | |||||
29-
| wal-wahl | |||||
15+
| Feature | Alpine | Alma | Debian | Fedora | Ubuntu |
16+
| --------------------------- | ------ | ---- | ------ | ------ | ------ |
17+
| bpftool ||||||
18+
| cni-plugins | |||||
19+
| docsify | | ? || ? ||
20+
| go-ebpf | |||||
21+
| go-mod-upgrade | |||||
22+
| gocover | |||||
23+
| goreportcard | |||||
24+
| grafanactl ||||||
25+
| lazygit ||||||
26+
| local-pkgsite | |||||
27+
| nerdctl | |||||
28+
| pin-github-action | |||||
29+
| pull-through-cache-registry | | || ||
30+
| wal-wahl | |||||
3031

3132
- [bpftool](src/bpftool/README.md) – installs `bpftool` directly from upstream
3233
https://github.com/libbpf/bpftool binary releases, especially avoiding the
@@ -70,6 +71,10 @@ doesn't support Alpine.
7071
- [pin-github-action](src/pin-github-action/README.md) – provides mheaps's
7172
`pin-github-action` for pinning GitHub actions to specific hashes.
7273

74+
- [pull-through-cache-registry](src/pull-through-cache-registry/README.md)
75+
provides a CNCF Distribution Registry acting as pull-through cache for your
76+
Docker-in-Docker.
77+
7378
- [wal-wahl](src/wal-wahl/README.md) – install multiple Docker CE versions
7479
inside your devcontainer, quickly switching and activating one of them at a
7580
time.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
## OS Support
2+
3+
As this feature relies on the [Docker-in-Docker
4+
feature](https://github.com/devcontainers/features/tree/main/src/docker-in-docker)
5+
we only support the same Debian/Ubuntu platforms.
6+
7+
## Registry Configuration
8+
9+
- pull-through caching is enabled by passing `REGISTRY_PROXY_REMOTEURL` (a.k.a.
10+
`proxy:{remoteulr:}`).
11+
- logging is set to info level by passing `REGISTRY_LOG_LEVEL` (a.k.a.
12+
`log:{level:}`).
13+
14+
## Acknowledgement
15+
16+
[Registry as a pull through
17+
cache](https://distribution.github.io/distribution/recipes/mirror/), CNCF
18+
Distribution.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
# OCI registry pull-through cache to mirror rate-limited upstream registries, such as Docker Hub (pull-through-cache-registry)
3+
4+
provides a devcontainer-local CNCF Distribution Registry configured as a pull-through cache for the local docker-in-docker
5+
6+
## Example Usage
7+
8+
```json
9+
"features": {
10+
"ghcr.io/thediveo/devcontainer-features/pull-through-cache-registry:0": {}
11+
}
12+
```
13+
14+
## Options
15+
16+
| Options Id | Description | Type | Default Value |
17+
|-----|-----|-----|-----|
18+
| port | port to bind the CNCF Distribution Registry service to | string | 5000 |
19+
| registry-name | the Docker container name to give the CNCF Distribution Registry | string | registry-cache |
20+
| wait | maximum wait time in seconds for Docker to become available when starting the CNCF Distribution Registry service | string | 30 |
21+
22+
## OS Support
23+
24+
As this feature relies on the [Docker-in-Docker
25+
feature](https://github.com/devcontainers/features/tree/main/src/docker-in-docker)
26+
we only support the same Debian/Ubuntu platforms.
27+
28+
## Registry Configuration
29+
30+
- pull-through caching is enabled by passing `REGISTRY_PROXY_REMOTEURL` (a.k.a.
31+
`proxy:{remoteulr:}`).
32+
- logging is set to info level by passing `REGISTRY_LOG_LEVEL` (a.k.a.
33+
`log:{level:}`).
34+
35+
## Acknowledgement
36+
37+
[Registry as a pull through
38+
cache](https://distribution.github.io/distribution/recipes/mirror/), CNCF
39+
Distribution.
40+
41+
42+
---
43+
44+
_Note: This file was auto-generated from the [devcontainer-feature.json](https://github.com/thediveo/devcontainer-features/blob/main/src/pull-through-cache-registry/devcontainer-feature.json). Add additional notes to a `NOTES.md`._
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "OCI registry pull-through cache to mirror rate-limited upstream registries, such as Docker Hub",
3+
"id": "pull-through-cache-registry",
4+
"version": "0.0.1",
5+
"description": "Deploys a devcontainer-local CNCF Distribution Registry configured as a pull-through cache for the local docker-in-docker",
6+
"documentationURL": "https://github.com/thediveo/devcontainer-features/blob/master/src/registry-pull-through-cache/README.md",
7+
"options": {
8+
"proxy-remote-url": {
9+
"type": "string",
10+
"default": "https://registry-1.docker.io",
11+
"description": "URL of the upstream OCI registry"
12+
},
13+
"port": {
14+
"type": "string",
15+
"default": "5000",
16+
"description": "port to bind the CNCF Distribution Registry service to",
17+
"proposals": ["5000", "9999"]
18+
},
19+
"registry-name": {
20+
"type": "string",
21+
"default": "registry-cache",
22+
"description": "the Docker container name to give the CNCF Distribution Registry"
23+
},
24+
"wait": {
25+
"type": "string",
26+
"default": "30",
27+
"description": "maximum wait time in seconds for Docker to become available when starting the CNCF Distribution Registry service"
28+
}
29+
},
30+
"postCreateCommand": "/usr/local/bin/registry-pull-through-cache",
31+
"dependsOn": {
32+
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
33+
}
34+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
REGISTRYDEPLOYSCRIPT_PATH="/usr/local/bin/registry-pull-through-cache"
6+
7+
PROXY_REMOTE_URL=${PROXY_REMOTE_URL:-"https://registry-1.docker.io"}
8+
PORT=${PORT:-5000}
9+
REGISTRY_NAME=${REGISTRY_NAME:-"registry-cache"}
10+
WAIT=${WAIT:-30}
11+
12+
echo "installing feature registry-pull-through-cache"
13+
14+
cat <<EOF >"${REGISTRYDEPLOYSCRIPT_PATH}"
15+
PROXY_REMOTE_URL=${PROXY_REMOTE_URL}
16+
PORT="${PORT}"
17+
REGISTRY_NAME="${REGISTRY_NAME}"
18+
19+
timeout=${WAIT}
20+
echo "waiting up to ${WAIT}s for Docker daemon to become responsive..."
21+
while ! docker ps >/dev/null 2>&1; do
22+
sleep 1
23+
timeout=$((timeout-1))
24+
if [ "$timeout" -le 0 ]; then
25+
echo "Docker did not become responsive, aborting"
26+
exit 1
27+
fi
28+
done
29+
30+
if docker ps -a --format '{{.Names}}' | grep -q "^\${REGISTRY_NAME}$"; then
31+
echo "(re)starting pull-through cache registry container"
32+
docker start "\${REGISTRY_NAME}"
33+
else
34+
echo "running pull-through cache registry container"
35+
docker run -d \
36+
--restart always \
37+
--name "\${REGISTRY_NAME}" \
38+
-p \${PORT}:5000 \
39+
-e REGISTRY_PROXY_REMOTEURL="\${PROXY_REMOTE_URL}" \
40+
-e REGISTRY_LOG_LEVEL=info \
41+
-e OTEL_TRACES_EXPORTER=none \
42+
registry:3
43+
fi
44+
echo "pull-through cache registry started"
45+
EOF
46+
47+
echo generating /etc/docker/daemon.json configuring registry-mirrors
48+
cat <<EOF >/etc/docker/daemon.json
49+
{
50+
"registry-mirrors": [ "http://localhost:${PORT}" ]
51+
}
52+
EOF
53+
54+
chmod 0755 "${REGISTRYDEPLOYSCRIPT_PATH}"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
source dev-container-features-test-lib
5+
6+
check "registry service is up" bash -c "source ./wait.sh && whalewaiting registry-cache"
7+
check "registry service responds" bash -c "source ./wait.sh && registrywaiting http://localhost:9999"
8+
9+
reportResults
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
source dev-container-features-test-lib
5+
6+
check "registry service is up" bash -c "source ./wait.sh && whalewaiting registry-cache"
7+
check "registry service responds" bash -c "source ./wait.sh && registrywaiting http://localhost:5000"
8+
check "pulling an image" bash -c "docker pull quay.io/libpod/busybox | tee >(grep 'quay.io/libpod/busybox:latest')"
9+
10+
reportResults
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"9999": {
3+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu-24.04",
4+
"features": {
5+
"pull-through-cache-registry": {
6+
"port": "9999"
7+
}
8+
}
9+
},
10+
"quay.io": {
11+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu-24.04",
12+
"features": {
13+
"pull-through-cache-registry": {
14+
"proxy-remote-url": "https://quay.io"
15+
}
16+
}
17+
}
18+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
source dev-container-features-test-lib
5+
6+
check "registry service is up" bash -c "source ./wait.sh && whalewaiting registry-cache"
7+
check "registry service responds" bash -c "source ./wait.sh && registrywaiting http://localhost:5000"
8+
9+
reportResults

0 commit comments

Comments
 (0)