ligo/scripts/ci/create_opam_repository.tezos_deps.sh

103 lines
3.2 KiB
Bash
Raw Normal View History

#! /bin/sh
set -e
ci_dir="$(cd "$(dirname "$0")" && echo "$(pwd -P)/")"
script_dir="$(dirname "$ci_dir")"
src_dir="$(dirname "$script_dir")"
cd "$src_dir"
. "$script_dir"/version.sh
build_dir=${build_dir:-_docker_build}
2018-06-27 14:58:06 +04:00
if [ -f "$build_dir/opam_repository-tezos_deps-$ocaml_version-$opam_repository_tag.tgz" ]; then
exit 0
fi
tmp_image="opam_bundle-tezos"
tmp_dir=$(mktemp -dt tezos.opam_bundle.XXXXXXXX)
cleanup () {
set +e
rm -rf "$tmp_dir"
if ! [ -z "$container" ]; then docker rm $container; fi
# docker rmi $tmp_image || true
}
trap cleanup EXIT INT
## Creating a repository of tezos packages
repo="$tmp_dir"/opam-repository-tezos
2018-06-27 14:58:06 +04:00
opams=$(find "$src_dir/src" "$src_dir"/vendors -name \*.opam -print)
mkdir -p "$repo/packages"
echo "1.2" > "$repo/version"
packages=
for opam in $opams; do
dir=$(dirname $opam)
file=$(basename $opam)
package=${file%.opam}
destdir="$repo/packages/$package/$package.dev"
mkdir -p "$destdir"
cp -a "$opam" "$destdir/opam"
# echo "local: \"rsync://$dir\"" > "$destdir/url"
packages="$packages $package"
done
2018-02-07 17:40:30 +04:00
# Hack: it loks like there is too many cycle in the opam-repository,
# when using `opam-bundle --with-test --with-doc`, so we manually
# inline some of the test and doc dependencies.
extra_packages="depext alcotest-lwt ocp-indent odoc ounit crowbar"
2018-02-07 17:40:30 +04:00
2018-06-27 14:58:06 +04:00
git clone $opam_repository_url "$tmp_dir/opam-repository-master"
git -C "$tmp_dir"/opam-repository-master reset --hard $opam_repository_tag
rm -rf "$tmp_dir"/opam-repository-master/.git
## HACK: Once opam2 is released, we should use the `ocaml/opam` image
## instead of this custom installation of ocaml and opam.
"$ci_dir"/create_binary.opam.sh
cp -a "$build_dir"/opam-$opam_tag "$tmp_dir"/opam
echo
echo "### Building tezos_bundle.tar.gz..."
echo
cat <<EOF > "$tmp_dir"/Dockerfile
2018-06-27 14:58:06 +04:00
FROM alpine:3.7
ENV PACKAGER "Tezos <ci@tezos.com>"
COPY opam-repository-master opam-repository-master
COPY opam /usr/local/bin/opam
RUN apk add --no-cache ocaml build-base m4 tar xz bzip2 curl perl rsync
2018-06-27 14:58:06 +04:00
RUN opam init --disable-sandboxing --no-setup --yes default ./opam-repository-master
RUN opam install --yes opam-bundle
COPY opam-repository-tezos opam-repository-tezos
2018-06-27 14:58:06 +04:00
RUN opam bundle --yes --output="tezos_bundle-$ocaml_version-$opam_repository_tag" \
--repository=opam-repository-tezos \
--repository=opam-repository-master \
--ocaml=$ocaml_version \
2018-02-07 17:40:30 +04:00
$packages $extra_packages
EOF
docker build --pull -t $tmp_image "$tmp_dir"
container=$(docker create $tmp_image)
2018-06-27 14:58:06 +04:00
docker cp -L $container:/tezos_bundle-$ocaml_version-$opam_repository_tag.tar.gz "$tmp_dir"
cd "$tmp_dir"
2018-06-27 14:58:06 +04:00
tar xf tezos_bundle-$ocaml_version-$opam_repository_tag.tar.gz tezos_bundle-$ocaml_version-$opam_repository_tag/repo
# removing fake tezos packages
2018-06-27 14:58:06 +04:00
cd tezos_bundle-$ocaml_version-$opam_repository_tag/repo/packages
rm -r $packages
# Repacking the repo
cd "$tmp_dir"
2018-06-27 14:58:06 +04:00
mv tezos_bundle-$ocaml_version-$opam_repository_tag/repo opam_repository-tezos_deps
tar czf "opam_repository-tezos_deps-$ocaml_version-$opam_repository_tag.tgz" \
opam_repository-tezos_deps
cd "$src_dir"
2018-06-27 14:58:06 +04:00
mv "$tmp_dir"/opam_repository-tezos_deps-$ocaml_version-$opam_repository_tag.tgz "$build_dir"