Skip to content

Commit

Permalink
feat: local registry mirror
Browse files Browse the repository at this point in the history
  • Loading branch information
satanTime committed Jul 15, 2023
1 parent 2e3cc01 commit b25d78e
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 54 deletions.
13 changes: 1 addition & 12 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,12 +1 @@
.dockerignore
.git
.gitignore
.url
Docker.template
LICENSE
README.md
build.sh
hashes
mirror
mirror-data
buildx-data
*
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ tab_width = 2
trim_trailing_whitespace = true

[*.sh]
indent_size = 4
tab_width = 4
indent_size = 2
tab_width = 2

[*.md]
max_line_length = 70
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/.env
/.url
/Dockerfile
/mirror-data
/buildx-data
/mirror-data
/registry-data
89 changes: 50 additions & 39 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,37 +1,54 @@
#!/bin/bash

detectVersion () {
# detection the major version of the image
version=""
if [[ "${version}" == "" ]] && [[ -f hashes/$1 ]] && [[ "$2" == "" ]]; then
version=$(cat hashes/$1 | grep 'version' | sed -e 's/^version://')
fi
if [[ "${version}" == "" ]]; then
docker image pull node:$1 > /dev/null
version=$(
docker run --rm node:$1 cat /etc/os-release | \
grep 'VERSION=' | \
grep -oE '\(.*\)' | \
grep -oE '\w+' || \
echo ''
)
fi
if [[ "${version}" == "" ]]; then
docker image pull node:$1 > /dev/null
version=$(
docker run --rm node:$1 cat /etc/os-release | \
grep 'PRETTY_NAME=' | \
grep -oE '\w+/\w+"' | \
grep -oE '\w+/' | \
grep -oE '\w+' || \
echo ''
)
fi
if [[ "${version}" == "" ]]; then
version=$(cat hashes/$1 | grep 'version' | sed -e 's/^version://')
fi
versions=$(
echo 'bookworm' && \
echo 'bullseye' && \
echo 'buster' && \
echo 'stretch' && \
echo 'jessie' && \
echo 'wheezy'
)

echo $version
detectVersion () {
# detection the major version of the image
version=""
if [[ "${version}" == "" ]] && [[ -f hashes/$1 ]] && [[ "$2" == "" ]]; then
version=$(cat hashes/$1 | grep 'version' | sed -e 's/^version://')
fi
if [[ "${version}" == "" ]]; then
for possibleVersion in $versions; do
if [[ $1 == *"${possibleVersion}"* ]]; then
version="${possibleVersion}"
fi
done
fi

if [[ "${version}" == "" ]]; then
docker image pull node:$1 > /dev/null
version=$(
docker run --rm node:$1 cat /etc/os-release | \
grep 'VERSION=' | \
grep -oE '\(.*\)' | \
grep -oE '\w+' || \
echo ''
)
fi
if [[ "${version}" == "" ]]; then
docker image pull node:$1 > /dev/null
version=$(
docker run --rm node:$1 cat /etc/os-release | \
grep 'PRETTY_NAME=' | \
grep -oE '\w+/\w+"' | \
grep -oE '\w+/' | \
grep -oE '\w+' || \
echo ''
)
fi
if [[ "${version}" == "" ]]; then
version=$(cat hashes/$1 | grep 'version' | sed -e 's/^version://')
fi

echo $version
}

detectDockerfile () {
Expand All @@ -56,14 +73,7 @@ fi
tagsInclude=""
if [[ $URL == "" ]]; then
URL=https://registry.hub.docker.com/v2/repositories/library/node/tags
tagsInclude=$(
echo 'bookworm' && \
echo 'bullseye' && \
echo 'buster' && \
echo 'stretch' && \
echo 'jessie' && \
echo 'wheezy'
)
tagsInclude="${versions}"
fi

while [[ $URL != "" ]]; do
Expand Down Expand Up @@ -200,6 +210,7 @@ while [[ $URL != "" ]]; do
cat $dockerfile >> Dockerfile && \
$(
docker buildx build \
--builder puppeteer-node \
${digestBuildX} \
--cache-to type=local,dest=./buildx-data \
--add-host archive.debian.org.lo:172.16.0.1 \
Expand Down
12 changes: 12 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
version: '3'

services:

debian:
build:
context: ./mirror
Expand All @@ -9,3 +10,14 @@ services:
volumes:
- ./mirror-data:/mirror
- ./mirror-data/cache:/var/cache/nginx

registry:
image: registry:2.8.2
environment:
- REGISTRY_PROXY_REMOTEURL="https://registry-1.docker.io"
- REGISTRY_PROXY_USERNAME=${DOCKER_HUB_USERNAME}
- REGISTRY_PROXY_PASSWORD=${DOCKER_HUB_ACCESS_TOKEN}
ports:
- 172.16.0.1:5000:5000
volumes:
- ./registry-data:/var/lib/registry

0 comments on commit b25d78e

Please sign in to comment.