From b460633fdc8d04192a853624e3887a6538cd3dfe Mon Sep 17 00:00:00 2001 From: Pietro Abate Date: Tue, 18 Jun 2024 10:00:31 +0200 Subject: [PATCH 1/2] scripts: Add kisscache wrapper --- scripts/kiss-fetch.sh | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100755 scripts/kiss-fetch.sh diff --git a/scripts/kiss-fetch.sh b/scripts/kiss-fetch.sh new file mode 100755 index 000000000000..3958bf21c782 --- /dev/null +++ b/scripts/kiss-fetch.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# This script is a wrapper for opam to use +# a kisscache server, for example located at +# http://localhost:8001/api/v1/fetch/?url= + +# kisscache: https://gitlab.com/Linaro/kisscache + +# To enable this wrapper +# +# export OPAMFETCH="scripts/kiss-fetch.sh" +# +# before invoking opam +# +# Use the evn var KISSCACHE to specify a remote kisscache server. + +KISSCACHE=${KISSCACHE:-http://localhost:8001} + +# Original URL passed by opam +original_url=${*: -1} +arguments=${*:1:$#-1} + +# Mangle the URL by prepending the base URL +encoded_url=$(echo "$original_url" | sed 's/ /%20/g; s/?/%3F/g; s/&/%26/g; s/=/%3D/g; s/#/%23/g; s//%3E/g; s/"/%22/g; s/\//%2F/g; s/:/%3A/g') +mangled_url="${KISSCACHE}/api/v1/fetch?url=${encoded_url}" + +# shellcheck disable=SC2086 +if curl --output /dev/null --silent --head --fail "$KISSCACHE"; then + # Use curl to fetch the mangled URL + echo "curl -L $arguments $mangled_url" >> /tmp/kiss.log + curl -L $arguments $mangled_url +else + echo "Kisscache server unreachable, falling back to fetch using mangled URL" >> /tmp/kiss.log + curl -L $arguments $mangled_url +fi -- GitLab From 4d9e5d582a41c289f984a00cbf7e31ed28203f1c Mon Sep 17 00:00:00 2001 From: Pietro Abate Date: Wed, 5 Mar 2025 15:04:25 +0100 Subject: [PATCH 2/2] ci: add wrapper in ci images --- images/ci/Dockerfile.prebuild | 4 ++++ images/ci/scripts/create_opam_repo.sh | 6 ++++++ images/ci/scripts/kiss-fetch.sh | 1 + 3 files changed, 11 insertions(+) create mode 120000 images/ci/scripts/kiss-fetch.sh diff --git a/images/ci/Dockerfile.prebuild b/images/ci/Dockerfile.prebuild index 7aaeb632b3bb..0de15b2c00a9 100644 --- a/images/ci/Dockerfile.prebuild +++ b/images/ci/Dockerfile.prebuild @@ -91,6 +91,10 @@ WORKDIR /home/tezos COPY --chown=tezos:tezos scripts/create_opam_repo.sh scripts/version.sh octez-deps.opam.locked ./ COPY --chown=tezos:tezos stdcompat.opam.locked ./ +COPY --chown=tezos:tezos scripts/kiss-fetch.sh /tmp/ + +ENV OPAMFETCH="/tmp/kiss-fetch.sh" +ENV KISSCACHE="http://kisscache.kisscache.svc.cluster.local" # Run the script, then clean up; we only need the result of the script (the opam repository). RUN ./create_opam_repo.sh \ diff --git a/images/ci/scripts/create_opam_repo.sh b/images/ci/scripts/create_opam_repo.sh index 403567d0bdfb..329935795696 100755 --- a/images/ci/scripts/create_opam_repo.sh +++ b/images/ci/scripts/create_opam_repo.sh @@ -2,6 +2,12 @@ set -eu +# use opam proxy, if available +# shellcheck disable=SC2034 +OPAMFETCH="/tmp/kiss-fetch.sh" +# shellcheck disable=SC2034 +KISSCACHE="http://kisscache.kisscache.svc.cluster.local" + # When running the script manually, version.sh is in: scripts/ # But in the Dockerfile, the script is copied to: ./ if [ -e scripts/version.sh ]; then diff --git a/images/ci/scripts/kiss-fetch.sh b/images/ci/scripts/kiss-fetch.sh new file mode 120000 index 000000000000..7aac704fd8a6 --- /dev/null +++ b/images/ci/scripts/kiss-fetch.sh @@ -0,0 +1 @@ +../../../scripts/kiss-fetch.sh \ No newline at end of file -- GitLab