2018-01-16 18:45:42 +04:00
|
|
|
#!/bin/sh
|
2017-08-04 20:32:52 +04:00
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
script_dir="$(cd "$(dirname "$0")" && echo "$(pwd -P)/")"
|
|
|
|
src_dir="$(dirname "$script_dir")"
|
|
|
|
cd "$src_dir"
|
|
|
|
|
|
|
|
. scripts/version.sh
|
|
|
|
image_name="${1:-tezos_build_deps}"
|
|
|
|
image_version="${2:-latest}"
|
2017-08-10 12:05:44 +04:00
|
|
|
cached_image="${3:-}"
|
2017-08-04 20:32:52 +04:00
|
|
|
|
2017-08-10 12:05:44 +04:00
|
|
|
base_image="tezos/opam:alpine-${alpine_version}_ocaml-${ocaml_version}"
|
|
|
|
if ! docker pull "$base_image" ; then
|
2018-01-16 18:45:42 +04:00
|
|
|
./scripts/create_docker_image.alpine.opam2.sh
|
2017-08-10 12:05:44 +04:00
|
|
|
fi
|
2017-08-04 20:32:52 +04:00
|
|
|
|
|
|
|
cleanup () {
|
|
|
|
set +e
|
|
|
|
echo Cleaning up...
|
2018-01-16 18:45:42 +04:00
|
|
|
rm -f Dockerfile opams.tar.gz scripts.tar.gz
|
2017-08-04 20:32:52 +04:00
|
|
|
}
|
|
|
|
trap cleanup EXIT INT
|
|
|
|
|
2018-01-16 18:45:42 +04:00
|
|
|
dependencies="scripts/install_build_deps.sh scripts/version.sh scripts/opam-pin.sh scripts/opam-unpin.sh scripts/opam-remove.sh"
|
|
|
|
tar czvf scripts.tar.gz $dependencies
|
2017-12-06 22:52:00 +04:00
|
|
|
|
2018-01-16 18:45:42 +04:00
|
|
|
opams=$(find -name \*.opam -type f)
|
|
|
|
tar czvf opams.tar.gz $opams
|
2017-12-06 22:52:00 +04:00
|
|
|
|
2018-01-16 18:45:42 +04:00
|
|
|
cat <<EOF >Dockerfile
|
|
|
|
FROM $base_image
|
|
|
|
|
|
|
|
# these two archives are created in the file
|
|
|
|
# scripts/create_docker_image.build_deps.sh and removed
|
|
|
|
# automatically after
|
|
|
|
ADD opams.tar.gz tezos/
|
|
|
|
ADD scripts.tar.gz tezos/
|
|
|
|
|
|
|
|
USER opam
|
|
|
|
|
|
|
|
RUN opam config exec -- ./tezos/scripts/install_build_deps.sh
|
|
|
|
ENV OPAMYES=yes
|
|
|
|
RUN opam config exec -- opam install ocp-indent && \
|
|
|
|
rm -fr ~/.opam/log/ && \
|
|
|
|
rm -fr "\$(opam config exec -- ocamlfind query stdlib)"/topdirs.cmi
|
|
|
|
|
|
|
|
EOF
|
2017-08-04 20:32:52 +04:00
|
|
|
|
|
|
|
## Lookup for for prebuilt dependencies...
|
2017-08-08 19:04:11 +04:00
|
|
|
dependencies_sha1=$(docker inspect --format="{{ .RootFS.Layers }}" --type=image $base_image | sha1sum - $dependencies | sha1sum | tr -d ' -')
|
2017-08-10 12:05:44 +04:00
|
|
|
if [ ! -z "$cached_image" ]; then
|
2017-08-08 19:04:11 +04:00
|
|
|
echo
|
|
|
|
echo "### Looking for prebuilt dependencies ($cached_image)..."
|
|
|
|
if docker pull "$cached_image:$dependencies_sha1"; then
|
|
|
|
echo
|
|
|
|
echo "### Found $cached_image:$dependencies_sha1"
|
|
|
|
echo
|
|
|
|
docker tag "$cached_image:$dependencies_sha1" \
|
|
|
|
"$image_name:$image_version"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
echo "### Missing..."
|
|
|
|
echo
|
2017-08-10 12:05:44 +04:00
|
|
|
fi
|
2017-08-04 20:32:52 +04:00
|
|
|
|
|
|
|
echo
|
2018-01-16 18:45:42 +04:00
|
|
|
echo "### Building tezos dependencies... $image_name:$image_version"
|
2017-08-04 20:32:52 +04:00
|
|
|
echo
|
|
|
|
|
2018-01-16 18:45:42 +04:00
|
|
|
docker build --pull -t "$image_name:$image_version" .
|
2017-08-04 20:32:52 +04:00
|
|
|
|
2018-01-16 18:45:42 +04:00
|
|
|
rm -f Dockerfile opams.tar.gz scripts.tar.gz
|
2017-08-04 20:32:52 +04:00
|
|
|
|
|
|
|
echo
|
|
|
|
echo "### Succesfully build docker image: $image_name:$image_version"
|
|
|
|
echo
|
2017-08-08 19:04:11 +04:00
|
|
|
|
2017-08-10 12:05:44 +04:00
|
|
|
if [ ! -z "$cached_image" ]; then
|
2017-08-08 19:04:11 +04:00
|
|
|
echo
|
2017-08-16 16:18:34 +04:00
|
|
|
echo "### Saving docker image ($cached_image)..."
|
2017-08-08 19:04:11 +04:00
|
|
|
echo
|
|
|
|
docker tag "$image_name:$image_version" \
|
|
|
|
"$cached_image:$dependencies_sha1"
|
|
|
|
docker push "$cached_image:$dependencies_sha1"
|
2017-08-10 12:05:44 +04:00
|
|
|
fi
|