diff --git a/blueprints/registry/docker-compose.yml b/blueprints/registry/docker-compose.yml index 08c5c368..a86455d4 100644 --- a/blueprints/registry/docker-compose.yml +++ b/blueprints/registry/docker-compose.yml @@ -1,19 +1,35 @@ services: registry: - restart: always - image: registry:2 - ports: - - 5000 - volumes: - - ../files/auth/registry.password:/auth/registry.password - - registry-data:/var/lib/registry + image: registry:3 + restart: unless-stopped environment: - REGISTRY_STORAGE_DELETE_ENABLED: true - REGISTRY_HEALTH_STORAGEDRIVER_ENABLED: false - REGISTRY_HTTP_SECRET: ${REGISTRY_HTTP_SECRET} - REGISTRY_AUTH: htpasswd - REGISTRY_AUTH_HTPASSWD_REALM: Registry Realm - REGISTRY_AUTH_HTPASSWD_PATH: /auth/registry.password + - USERNAME=${USERNAME} + - PASSWORD=${PASSWORD} + - REGISTRY_AUTH=htpasswd + - REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm + - REGISTRY_AUTH_HTPASSWD_PATH=/auth/registry.password + - REGISTRY_HTTP_RELATIVEURLS=true + entrypoint: ["sh", "/entrypoint.sh"] + volumes: + - registry-data:/var/lib/registry + - type: bind + source: ../files/entrypoint.sh + target: /entrypoint.sh + - type: bind + source: ../files/config.yml + target: /etc/docker/registry/config.yml + expose: + - 5000 + healthcheck: + test: + - CMD + - wget + - "-q" + - "--spider" + - "http://localhost:5000/" + interval: 5s + timeout: 20s + retries: 10 volumes: - registry-data: \ No newline at end of file + registry-data: diff --git a/blueprints/registry/template.toml b/blueprints/registry/template.toml index a61ca406..a2a16530 100644 --- a/blueprints/registry/template.toml +++ b/blueprints/registry/template.toml @@ -1,6 +1,7 @@ [variables] main_domain = "${domain}" -registry_http_secret = "${password:30}" +username = "${username}" +password = "${password:32}" [[config.domains]] serviceName = "registry" @@ -8,11 +9,48 @@ port = 5_000 host = "${main_domain}" [config.env] -REGISTRY_HTTP_SECRET = "${registry_http_secret}" +USERNAME = "${username}" +PASSWORD = "${password}" [[config.mounts]] -filePath = "/auth/registry.password" +filePath = "./config.yml" content = """ -# from: docker run --rm --entrypoint htpasswd httpd:2 -Bbn docker password -docker:$2y$10$qWZoWev/u5PV7WneFoRAMuoGpRcAQOgUuIIdLnU7pJXogrBSY23/2 +version: 0.1 + +log: + fields: + service: registry +storage: + cache: + blobdescriptor: inmemory + filesystem: + rootdirectory: /var/lib/registry +http: + addr: :5000 + headers: + X-Content-Type-Options: [nosniff] +health: + storagedriver: + enabled: true + interval: 10s + threshold: 3 +""" + +[[config.mounts]] +filePath = "./entrypoint.sh" +content = """ +#!/usr/bin/env sh + +set -e + +if [ -z "$USERNAME" ] || [ -z "$PASSWORD" ]; then + echo "Error: USERNAME and PASSWORD environment variables must be set" + exit 1 +fi + +apk add --no-cache apache2-utils +mkdir -p "$(dirname "$REGISTRY_AUTH_HTPASSWD_PATH")" +chmod 755 "$(dirname "$REGISTRY_AUTH_HTPASSWD_PATH")" +htpasswd -Bbc "$REGISTRY_AUTH_HTPASSWD_PATH" "$USERNAME" "$PASSWORD" +registry serve /etc/docker/registry/config.yml """