Skip to content

Instantly share code, notes, and snippets.

@robertgzr
Last active October 15, 2021 11:26
Show Gist options
  • Save robertgzr/66e5ffb41f837052cc04b2b823b43f80 to your computer and use it in GitHub Desktop.
Save robertgzr/66e5ffb41f837052cc04b2b823b43f80 to your computer and use it in GitHub Desktop.
private registry cache

registry compose file

version: '2.4'

services:
  cache:
    image: registry:2
    network_mode: host
    environment:
      - 'REGISTRY_HTTP_ADDR=:5000'
      - 'REGISTRY_STORAGE_CACHE_BLOBDESCRIPTOR=inmemory'
      - 'REGISTRY_STORAGE_FILESYSTEM_BLOBDESCRIPTOR=inmemory'
      - 'REGISTRY_PROXY_REMOTEURL=http://localhost:5001'
    depends_on:
      - upstream

  upstream:
    image: registry:2
    network_mode: host
    environment:
      - 'REGISTRY_HTTP_ADDR=:5001'
      - 'REGISTRY_STORAGE_CACHE_BLOBDESCRIPTOR=inmemory'
      - 'REGISTRY_STORAGE_FILESYSTEM_BLOBDESCRIPTOR=inmemory'

load an image into the upstream registry

skopeo copy --src-creds '[user]:[pass]' --dest-tls-verify=false docker://registry2.balena-cloud.com/v2/879e1c2d65b2afd59b19b4f0da57feab docker://localhost:5001/test
Getting image source signatures
Copying blob cdab0651f977 skipped: already exists  
Copying blob 339de151aab4 skipped: already exists  
Copying blob 5e5288ebfc4a [--------------------------------------] 0.0b / 0.0b
Copying config 054f048586 [======================================] 2.0KiB / 2.0KiB
Writing manifest to image destination
Storing signatures

daemon.json

{
  "registries": [
    {
      "prefix": "http://localhost:5001",
      "mirrors": [{
        "url": "http://localhost:5000"
      }]
    }
  ]
}

engine cli + daemon logs

/src # balena pull localhost:5000/test
DEBU[2021-10-15T11:15:29.693077255Z] Calling HEAD /_ping                          
Using default tag: latest
DEBU[2021-10-15T11:15:29.697825130Z] Calling POST /v1.40/images/create?fromImage=localhost%3A5000%2Ftest&tag=latest 
DEBU[2021-10-15T11:15:29.711355600Z] Trying to pull localhost:5000/test from https://localhost:5000 v2 
WARN[2021-10-15T11:15:29.718005740Z] Error getting v2 registry: Get https://localhost:5000/v2/: http: server gave HTTP response to HTTPS client 
INFO[2021-10-15T11:15:29.718040204Z] Attempting next endpoint for pull after error: Get https://localhost:5000/v2/: http: server gave HTTP response to HTTPS client 
DEBU[2021-10-15T11:15:29.718064802Z] Trying to pull localhost:5000/test from http://localhost:5000 v2 
INFO[2021-10-15T11:15:29.761421646Z] Pulling ref localhost:5000/test:latest from V2 registry http://localhost:5000 
latest: Pulling from test
DEBU[2021-10-15T11:15:29.774256587Z] pulling blob "sha256:cdab0651f97721570bd78f6d20e04bee6c9f0ca3270be0a48994eb59a5c2d086" 
339de151aab4: DEBU[2021-10-15T11:15:29.774261894Z] pulling blob "sha256:339de151aab4bc06eed8409daae147c408478cb538dacb90cc63f19ad4eba80b" 
5e5288ebfc4a: Pulling fs layer 
339de151aab4: Ready to download 
5e5288ebfc4a: Ready to download 
339de151aab4: Extracting [==================================================>]  2.801MB/2.801MB
DEBU[2021-10-15T11:15:29.789317945Z] Applying tar in /var/lib/docker/overlay2/7207af300619bf2c07781ecd18a4e498f551057b51339de151aab4: Pull complete 
Total:  [===============================>                   ]  2.195MB/3.524MB
DEBU[2021-10-15T11:15:29.942963036Z] Applied tar sha256:32f366d666a541852cad754ee1cdb53a736110b550f0c2d5a46bc5ba519896b65e5288ebfc4a: Extracting [==================================================>]  723.1kB/723.1kB
DEBU[2021-10-15T11:15:29.965668453Z] Applying tar in /var/lib/docker/overlay2/abd52aa0c72c15a85dd2cc3f79d815c9cc755a33895e5288ebfc4a: Pull complete 
cdab0651f977: Extracting [==================================================>]     357B/357B
Total:  [==================================================>]  3.524MB/3.524MB
cdab0651f977: Extracting [==================================================>]     357B/357B
313b4ad7f252c8d6ab912f/diff  storage-driver=overlay2
cdab0651f977: Pull complete 
 to 63c5ef51999395102082c041efc28909477ddc7fe5313b4ad7f252c8d6ab912f, size: 234 
Digest: sha256:33f45fc95d30025ce16d06291d9cbb27d391095a81cdc8e053638a0cd7a152fa
Status: Downloaded newer image for localhost:5000/test:latest
localhost:5000/test:latest

registry logs

cache_1     | time="2021-10-15T11:15:29.723604626Z" level=info msg="response completed" go.version=go1.11.2 http.request.host="localhost:5000" http.request.id=df34a86f-96b6-4464-b265-9e7409c4f2de http.request.method=GET http.request.remoteaddr="[::1]:36334" http.request.uri="/v2/" http.request.useragent="balenaEngine/dev go/go1.12.17 git-commit/dirty kernel/5.10.61-gentoo os/linux arch/amd64 UpstreamClient(Docker-Client/dev \(linux\))" http.response.contenttype="application/json; charset=utf-8" http.response.duration=1.273065ms http.response.status=200 http.response.written=2 
cache_1     | ::1 - - [15/Oct/2021:11:15:29 +0000] "GET /v2/ HTTP/1.1" 200 2 "" "balenaEngine/dev go/go1.12.17 git-commit/dirty kernel/5.10.61-gentoo os/linux arch/amd64 UpstreamClient(Docker-Client/dev \\(linux\\))"
upstream_1  | time="2021-10-15T11:15:29.739404809Z" level=info msg="response completed" go.version=go1.11.2 http.request.host="localhost:5001" http.request.id=1e9f32bf-cc69-4182-a7cb-ae7738ea845f http.request.method=GET http.request.remoteaddr="[::1]:51258" http.request.uri="/v2/" http.request.useragent="Go-http-client/1.1" http.response.contenttype="application/json; charset=utf-8" http.response.duration=1.423581ms http.response.status=200 http.response.written=2 
upstream_1  | ::1 - - [15/Oct/2021:11:15:29 +0000] "GET /v2/ HTTP/1.1" 200 2 "" "Go-http-client/1.1"
cache_1     | time="2021-10-15T11:15:29.739741099Z" level=info msg="Challenge established with upstream : {http   localhost:5001 /v2/  %!s(bool=false)  } &{{{%!s(int32=0) %!s(uint32=0)} %!s(uint32=0) %!s(uint32=0) %!s(int32=0) %!s(int32=0)} map[http://localhost:5001/v2/:[]]}" go.version=go1.11.2 http.request.host="localhost:5000" http.request.id=3492bc15-65bc-40c1-b627-5ec5b59332d8 http.request.method=GET http.request.remoteaddr="[::1]:36336" http.request.uri="/v2/test/manifests/latest" http.request.useragent="balenaEngine/dev go/go1.12.17 git-commit/dirty kernel/5.10.61-gentoo os/linux arch/amd64 UpstreamClient(Docker-Client/dev \(linux\))" vars.name=test vars.reference=latest 
upstream_1  | ::1 - - [15/Oct/2021:11:15:29 +0000] "HEAD /v2/test/manifests/latest HTTP/1.1" 200 945 "" "Go-http-client/1.1"
upstream_1  | time="2021-10-15T11:15:29.747506884Z" level=info msg="response completed" go.version=go1.11.2 http.request.host="localhost:5001" http.request.id=27a28662-5cb6-4959-beeb-e37d2bf0737d http.request.method=HEAD http.request.remoteaddr="[::1]:51260" http.request.uri="/v2/test/manifests/latest" http.request.useragent="Go-http-client/1.1" http.response.contenttype="application/vnd.docker.distribution.manifest.v2+json" http.response.duration=3.070296ms http.response.status=200 http.response.written=945 
cache_1     | time="2021-10-15T11:15:29.760497173Z" level=info msg="response completed" go.version=go1.11.2 http.request.host="localhost:5000" http.request.id=3492bc15-65bc-40c1-b627-5ec5b59332d8 http.request.method=GET http.request.remoteaddr="[::1]:36336" http.request.uri="/v2/test/manifests/latest" http.request.useragent="balenaEngine/dev go/go1.12.17 git-commit/dirty kernel/5.10.61-gentoo os/linux arch/amd64 UpstreamClient(Docker-Client/dev \(linux\))" http.response.contenttype="application/vnd.docker.distribution.manifest.v2+json" http.response.duration=30.684601ms http.response.status=200 http.response.written=945 
cache_1     | ::1 - - [15/Oct/2021:11:15:29 +0000] "GET /v2/test/manifests/latest HTTP/1.1" 200 945 "" "balenaEngine/dev go/go1.12.17 git-commit/dirty kernel/5.10.61-gentoo os/linux arch/amd64 UpstreamClient(Docker-Client/dev \\(linux\\))"
cache_1     | time="2021-10-15T11:15:29.773077027Z" level=info msg="response completed" go.version=go1.11.2 http.request.host="localhost:5000" http.request.id=d6014597-54c2-4357-a482-c55529085b56 http.request.method=GET http.request.remoteaddr="[::1]:36342" http.request.uri="/v2/test/blobs/sha256:054f0485869ea84df5b542f5102fbbeb4a5febfa716b068e56db4372979649d5" http.request.useragent="balenaEngine/dev go/go1.12.17 git-commit/dirty kernel/5.10.61-gentoo os/linux arch/amd64 UpstreamClient(Docker-Client/dev \(linux\))" http.response.contenttype="application/octet-stream" http.response.duration=7.437402ms http.response.status=200 http.response.written=2093 
cache_1     | ::1 - - [15/Oct/2021:11:15:29 +0000] "GET /v2/test/blobs/sha256:054f0485869ea84df5b542f5102fbbeb4a5febfa716b068e56db4372979649d5 HTTP/1.1" 200 2093 "" "balenaEngine/dev go/go1.12.17 git-commit/dirty kernel/5.10.61-gentoo os/linux arch/amd64 UpstreamClient(Docker-Client/dev \\(linux\\))"
cache_1     | ::1 - - [15/Oct/2021:11:15:29 +0000] "GET /v2/test/blobs/sha256:339de151aab4bc06eed8409daae147c408478cb538dacb90cc63f19ad4eba80b HTTP/1.1" 200 2800567 "" "balenaEngine/dev go/go1.12.17 git-commit/dirty kernel/5.10.61-gentoo os/linux arch/amd64 UpstreamClient(Docker-Client/dev \\(linux\\))"
cache_1     | time="2021-10-15T11:15:29.789924585Z" level=info msg="response completed" go.version=go1.11.2 http.request.host="localhost:5000" http.request.id=d83801ca-6a1a-4d98-b694-3eb83f6a3895 http.request.method=GET http.request.remoteaddr="[::1]:36344" http.request.uri="/v2/test/blobs/sha256:339de151aab4bc06eed8409daae147c408478cb538dacb90cc63f19ad4eba80b" http.request.useragent="balenaEngine/dev go/go1.12.17 git-commit/dirty kernel/5.10.61-gentoo os/linux arch/amd64 UpstreamClient(Docker-Client/dev \(linux\))" http.response.contenttype="application/octet-stream" http.response.duration=6.989547ms http.response.status=200 http.response.written=2800567 
cache_1     | ::1 - - [15/Oct/2021:11:15:29 +0000] "GET /v2/test/blobs/sha256:5e5288ebfc4ac34f5fc79adf9cee81ef8a0bb4a0c733fff14f59b3048e7adb5e HTTP/1.1" 200 723051 "" "balenaEngine/dev go/go1.12.17 git-commit/dirty kernel/5.10.61-gentoo os/linux arch/amd64 UpstreamClient(Docker-Client/dev \\(linux\\))"
cache_1     | time="2021-10-15T11:15:29.965571809Z" level=info msg="response completed" go.version=go1.11.2 http.request.host="localhost:5000" http.request.id=0796aa6b-18d8-4bbe-bed8-e92913ae5bcb http.request.method=GET http.request.remoteaddr="[::1]:36346" http.request.uri="/v2/test/blobs/sha256:5e5288ebfc4ac34f5fc79adf9cee81ef8a0bb4a0c733fff14f59b3048e7adb5e" http.request.useragent="balenaEngine/dev go/go1.12.17 git-commit/dirty kernel/5.10.61-gentoo os/linux arch/amd64 UpstreamClient(Docker-Client/dev \(linux\))" http.response.contenttype="application/octet-stream" http.response.duration=11.440287ms http.response.status=200 http.response.written=723051 
cache_1     | time="2021-10-15T11:15:30.046781036Z" level=info msg="response completed" go.version=go1.11.2 http.request.host="localhost:5000" http.request.id=69b5b434-f938-4266-8f88-8deddc1dd859 http.request.method=GET http.request.remoteaddr="[::1]:36348" http.request.uri="/v2/test/blobs/sha256:cdab0651f97721570bd78f6d20e04bee6c9f0ca3270be0a48994eb59a5c2d086" http.request.useragent="balenaEngine/dev go/go1.12.17 git-commit/dirty kernel/5.10.61-gentoo os/linux arch/amd64 UpstreamClient(Docker-Client/dev \(linux\))" http.response.contenttype="application/octet-stream" http.response.duration=3.283346ms http.response.status=200 http.response.written=357 
cache_1     | ::1 - - [15/Oct/2021:11:15:30 +0000] "GET /v2/test/blobs/sha256:cdab0651f97721570bd78f6d20e04bee6c9f0ca3270be0a48994eb59a5c2d086 HTTP/1.1" 200 357 "" "balenaEngine/dev go/go1.12.17 git-commit/dirty kernel/5.10.61-gentoo os/linux arch/amd64 UpstreamClient(Docker-Client/dev \\(linux\\))"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment