Skip to content

Instantly share code, notes, and snippets.

@aerickson
Last active March 2, 2022 19:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aerickson/3f785dd2fb75de27c30468dbac91cb96 to your computer and use it in GitHub Desktop.
Save aerickson/3f785dd2fb75de27c30468dbac91cb96 to your computer and use it in GitHub Desktop.
docker_build_package_caching
#!/usr/bin/env bash
#
# script to build docker images and use a polipo proxy if present
# - works well for caching package fetches during apt install, etc
#
set -e
# set -x
container_name="fun_container_99"
SCRIPTPATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
cd "${SCRIPTPATH}"
# cache http requests if proxy server is running
# see if the proxy is up
status=0
nc -v -z localhost 8123 || status=$?
if [ "$status" == 0 ] ; then
# proxy is running
echo "* using proxy"
echo ""
proxy_host=host.docker.internal
export http_proxy="http://localhost:8123"
export https_proxy="http://localhost:8123"
docker build --build-arg http_proxy=http://$proxy_host:8123 \
--build-arg https_proxy=http://$proxy_host:8123 \
-t "$container_name" .
else
# proxy is not running
echo "* not using proxy"
echo ""
docker build -t "$container_name" .
fi
# docker run -it "$container_name"
diskCacheRoot=/tmp/cache/polipo
logLevel=4
#!/usr/bin/env bash
# runs polipo (https://www.irif.fr/~jch/software/polipo/) with a basic config
# `brew install polipo` works on OS X to install
set -e
mkdir -p /tmp/cache/polipo
polipo -c polipo.conf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment