CI: use our own docker image of opam

This commit is contained in:
Grégoire Henry 2017-08-10 10:05:44 +02:00
parent 9ae9f3f4b7
commit 67bbf11a12
6 changed files with 102 additions and 23 deletions

View File

@ -2,6 +2,7 @@ variables:
public_docker_image: docker.io/tezos/tezos
stages:
- prepare
- build
- test
- publish
@ -22,6 +23,24 @@ stages:
tags:
- docker
## Prepare docker image with precompiled OCaml/opam
prepare:
<<: *dind_definition
stage: prepare
only:
- schedules
before_script:
- . ./scripts/version.sh
script:
- ./scripts/create_docker_image.alpine.sh
- mkdir ~/.docker
- echo "$CI_DOCKER_AUTH" > ~/.docker/config.json ;
- docker push "tezos/opam:alpine-${alpine_version}_ocaml-${ocaml_version}"
- docker tag "tezos/opam:alpine-${alpine_version}_ocaml-${ocaml_version}"
"tezos/opam:latest"
- docker push "tezos/opam:latest"
## Tezos
build:
@ -145,13 +164,14 @@ publish:docker:minimal:
- ./scripts/create_docker_image.minimal.sh
"${public_docker_image}" "${CI_BUILD_REF_NAME}"
"${CI_REGISTRY_IMAGE}/build:${CI_BUILD_REF}"
- mkdir ~/.docker
- echo "$CI_DOCKER_AUTH" > ~/.docker/config.json ;
- docker push "${public_docker_image}:${CI_BUILD_REF_NAME}"
## Publish to github...
publish:github:
image: ocaml/opam
image: tezos/opam
stage: publish
only:
- master@tezos/tezos
@ -179,7 +199,7 @@ publish:github:
## Relaunching the bootstrap servers of the alphanet.zeronet
.bootstrap_template: &bootstrap_definition
image: ocaml/opam
image: tezos/opam
stage: deploy
only:
- alphanet@tezos/tezos

View File

@ -0,0 +1,34 @@
## Based on https://github.com/ocaml/opam-dockerfiles
FROM alpine:$alpine_version
RUN apk update && apk upgrade && \
apk add alpine-sdk openssh bash nano ncurses-dev rsync xz m4 \
opam aspcud \
gmp-dev libev-dev libressl-dev linux-headers pcre-dev perl zlib-dev \
libsodium-dev snappy-dev && \
apk add leveldb-dev \
--update-cache \
--repository http://nl.alpinelinux.org/alpine/edge/testing && \
rm -f /var/cache/apk/* && \
adduser -S opam && \
echo 'opam ALL=(ALL:ALL) NOPASSWD:ALL' > /etc/sudoers.d/opam && \
chmod 440 /etc/sudoers.d/opam && \
chown root:root /etc/sudoers.d/opam && \
sed -i.bak 's/^Defaults.*requiretty//g' /etc/sudoers
USER opam
WORKDIR /home/opam
RUN mkdir .ssh && \
chmod 700 .ssh && \
git config --global user.email "docker@example.com" && \
git config --global user.name "Docker CI" && \
sudo -u opam sh -c "git clone -b master git://github.com/ocaml/opam-repository" && \
sudo -u opam sh -c "opam init -a -y --comp $ocaml_version /home/opam/opam-repository" && \
sudo -u opam sh -c "opam install -y depext travis-opam"
ENTRYPOINT [ "opam", "config", "exec", "--" ]
CMD [ "sh" ]

View File

@ -1,12 +1,9 @@
FROM $base_image
COPY src /home/opam/tezos/src
COPY test /home/opam/tezos/test
RUN sudo chown -R opam /home/opam/tezos && \
echo "PRODUCTION=yes" > /home/opam/tezos/src/Makefile.local && \
opam config exec -- make -C tezos/src -j4
COPY test /home/opam/tezos/test
RUN sudo chown -R opam /home/opam/tezos/test && \
opam config exec -- make -C tezos/src -j4 && \
opam config exec -- make -C tezos/test -j4 build

View File

@ -2,12 +2,8 @@ FROM $base_image
COPY scripts/install_build_deps.sh scripts/version.sh scripts/
COPY src/tezos-deps.opam src/
COPY Dockerfile Dockerfile
RUN sudo apk add libsodium-dev snappy-dev && \
sudo apk add leveldb-dev \
--update-cache \
--repository http://nl.alpinelinux.org/alpine/edge/testing && \
opam switch $ocaml_version && \
opam config exec -- ./scripts/install_build_deps.sh all \
rm -fr ~/.opam/log/ \
"$(opam config exec -- ocamlfind query compiler-libs)"/../topdirs.cmi
RUN sudo apk update && \
opam config exec -- ./scripts/install_build_deps.sh all && \
sudo rm -f /var/cache/apk/* && \
rm -fr ~/.opam/log/ && \
rm -fr "$(opam config exec -- ocamlfind query stdlib)"/topdirs.cmi

View File

@ -0,0 +1,30 @@
#! /bin/sh
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/opam}"
image_version="${2:-alpine-${alpine_version}_ocaml-${ocaml_version}}"
cleanup () {
set +e
echo Cleaning up...
rm -rf Dockerfile
}
trap cleanup EXIT INT
sed scripts/Dockerfile.alpine.in \
-e 's|$alpine_version|'"$alpine_version"'|g' \
-e 's|$ocaml_version|'"$ocaml_version"'|g' > Dockerfile
echo
echo "### Building base image..."
echo
docker build --pull -t "$image_name:$image_version" .
rm Dockerfile

View File

@ -9,10 +9,12 @@ cd "$src_dir"
. scripts/version.sh
image_name="${1:-tezos_build_deps}"
image_version="${2:-latest}"
shift 2
cached_image="${3:-}"
base_image="ocaml/opam:alpine-${alpine_version}_ocaml-${ocaml_version}"
docker pull "$base_image"
base_image="tezos/opam:alpine-${alpine_version}_ocaml-${ocaml_version}"
if ! docker pull "$base_image" ; then
./create_docker_image.alpine.sh
fi
cleanup () {
set +e
@ -28,7 +30,7 @@ sed scripts/Dockerfile.build_deps.in \
## Lookup for for prebuilt dependencies...
dependencies="scripts/install_build_deps.sh src/tezos-deps.opam Dockerfile"
dependencies_sha1=$(docker inspect --format="{{ .RootFS.Layers }}" --type=image $base_image | sha1sum - $dependencies | sha1sum | tr -d ' -')
for cached_image in "$@"; do
if [ ! -z "$cached_image" ]; then
echo
echo "### Looking for prebuilt dependencies ($cached_image)..."
if docker pull "$cached_image:$dependencies_sha1"; then
@ -41,7 +43,7 @@ for cached_image in "$@"; do
fi
echo "### Missing..."
echo
done
fi
echo
echo "### Building tezos dependencies..."
@ -55,11 +57,11 @@ echo
echo "### Succesfully build docker image: $image_name:$image_version"
echo
for cached_image in "$@"; do
if [ ! -z "$cached_image" ]; then
echo
echo "### Saving socker image ($cached_image)..."
echo
docker tag "$image_name:$image_version" \
"$cached_image:$dependencies_sha1"
docker push "$cached_image:$dependencies_sha1"
done
fi