|
| 1 | +#!/usr/bin/env bash |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | +# Copyright Open Network Fabric Authors |
| 4 | + |
| 5 | +set -euxo pipefail |
| 6 | + |
| 7 | +# Config params |
| 8 | + |
| 9 | +declare -ri RSA_BIT_LENGTH="${RSA_BIT_LENGTH:-4096}" |
| 10 | +declare -ri CERT_DAYS="${CERT_DAYS:-30}" |
| 11 | + |
| 12 | +# end config |
| 13 | + |
| 14 | +declare SOURCE_DIR |
| 15 | +SOURCE_DIR="$(dirname "${BASH_SOURCE}")" |
| 16 | +declare -r SOURCE_DIR |
| 17 | + |
| 18 | +declare -r CERTS_DIR="${SOURCE_DIR}/root/etc/zot" |
| 19 | + |
| 20 | +mkdir -p "${CERTS_DIR}" |
| 21 | + |
| 22 | +pushd "${SOURCE_DIR}" |
| 23 | + |
| 24 | +chmod go=rw "${SOURCE_DIR}/root//etc/zot/"{*.key,*.crt,*.csr} |
| 25 | + |
| 26 | +openssl genrsa \ |
| 27 | + -out "${CERTS_DIR}/ca.key" \ |
| 28 | + "${RSA_BIT_LENGTH}" |
| 29 | + |
| 30 | +chmod u=rw,go= "${CERTS_DIR}/ca.key" |
| 31 | + |
| 32 | +openssl req \ |
| 33 | + -x509 \ |
| 34 | + -new \ |
| 35 | + -nodes \ |
| 36 | + -sha256 \ |
| 37 | + -days "${CERT_DAYS}" \ |
| 38 | + -key "${CERTS_DIR}/ca.key" \ |
| 39 | + -subj "/CN=loc" \ |
| 40 | + -out "${CERTS_DIR}/ca.crt" |
| 41 | + |
| 42 | +openssl req \ |
| 43 | + -new \ |
| 44 | + -nodes \ |
| 45 | + -sha256 \ |
| 46 | + -newkey "rsa:${RSA_BIT_LENGTH}" \ |
| 47 | + -keyout "${CERTS_DIR}/zot.key" \ |
| 48 | + -out "${CERTS_DIR}/zot.csr" \ |
| 49 | + -config "${CERTS_DIR}/cert.ini" |
| 50 | + |
| 51 | +openssl x509 \ |
| 52 | + -req \ |
| 53 | + -in "${CERTS_DIR}/zot.csr" \ |
| 54 | + -CA "${CERTS_DIR}/ca.crt" \ |
| 55 | + -CAkey "${CERTS_DIR}/ca.key" \ |
| 56 | + -CAcreateserial \ |
| 57 | + -subj "/C=CN/ST=GD/L=SZ/O=githedgehog/CN=zot.loc" \ |
| 58 | + -extfile <(printf "subjectAltName=DNS:zot,DNS:zot.loc,IP:192.168.19.1") \ |
| 59 | + -out "${CERTS_DIR}/zot.crt" \ |
| 60 | + -days "${CERT_DAYS}" \ |
| 61 | + -sha256 |
| 62 | + |
| 63 | + |
| 64 | +docker stop vlab || true |
| 65 | +docker network rm zot || true |
| 66 | +docker rm vlab || true |
| 67 | + |
| 68 | +docker network create --attachable --driver bridge --ipv4 --ip-range 192.168.19.0/31 --subnet 192.168.19.0/31 zot |
| 69 | + |
| 70 | +declare -r base="${1:-"ubuntu:25.10"}" |
| 71 | + |
| 72 | +docker pull "${base}" |
| 73 | + |
| 74 | +docker build \ |
| 75 | + --build-arg BASE_IMAGE="${base}" \ |
| 76 | + --tag vlab \ |
| 77 | + "${SOURCE_DIR}" |
| 78 | + |
| 79 | +docker run \ |
| 80 | + --network zot \ |
| 81 | + --privileged \ |
| 82 | + --mount type=bind,source="${CERTS_DIR}",target=/etc/zot/,readonly \ |
| 83 | + --mount type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock \ |
| 84 | + --mount type=volume,source=vlab,target=/vlab \ |
| 85 | + --mount type=volume,source=zot,target=/zot \ |
| 86 | + --env DOCKER_HOST="unix:///var/run/docker.sock" \ |
| 87 | + --volume ~/.docker:/root/.docker:ro \ |
| 88 | + --name vlab \ |
| 89 | + --add-host zot:192.168.19.1 \ |
| 90 | + --add-host zot.loc:192.168.19.1 \ |
| 91 | + --rm \ |
| 92 | + --interactive \ |
| 93 | + --tty \ |
| 94 | + --detach \ |
| 95 | + vlab \ |
| 96 | + zot serve /etc/zot/config.json |
| 97 | + |
| 98 | +### part 2 (in container) |
| 99 | + |
| 100 | +docker exec vlab cp /etc/zot/ca.crt /usr/local/share/ca-certificates/ |
| 101 | +docker exec vlab update-ca-certificates |
| 102 | +docker exec vlab /bin/bash -c "curl -fsSL 'https://i.hhdev.io/hhfab' | USE_SUDO=false INSTALL_DIR=. VERSION=master bash;" |
| 103 | +docker exec vlab /vlab/hhfab init --dev --registry-repo 192.168.19.1:30000 --gateway --import-host-upstream --force |
| 104 | +docker exec vlab mv fab.yaml fab.orig.yaml |
| 105 | +docker exec vlab bash -euxo pipefail -c " |
| 106 | + yq . fab.orig.yaml \ |
| 107 | + | jq --slurp ' |
| 108 | + . as \$input | |
| 109 | + \$input | |
| 110 | + ([\$input[0] | setpath([\"spec\", \"config\", \"registry\", \"upstream\", \"noTLSVerify\"]; true)] + \$input[1:]) |
| 111 | + ' \ |
| 112 | + | yq -y '.[]' \ |
| 113 | + | tee fab.yaml |
| 114 | +" |
| 115 | +docker exec vlab /vlab/hhfab vlab gen |
| 116 | +docker exec vlab /vlab/hhfab vlab up -v --controls-restricted=false -m=manual --recreate |
0 commit comments