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 public_docker_image: docker.io/tezos/tezos
stages: stages:
- prepare
- build - build
- test - test
- publish - publish
@ -22,6 +23,24 @@ stages:
tags: tags:
- docker - 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 ## Tezos
build: build:
@ -145,13 +164,14 @@ publish:docker:minimal:
- ./scripts/create_docker_image.minimal.sh - ./scripts/create_docker_image.minimal.sh
"${public_docker_image}" "${CI_BUILD_REF_NAME}" "${public_docker_image}" "${CI_BUILD_REF_NAME}"
"${CI_REGISTRY_IMAGE}/build:${CI_BUILD_REF}" "${CI_REGISTRY_IMAGE}/build:${CI_BUILD_REF}"
- mkdir ~/.docker
- echo "$CI_DOCKER_AUTH" > ~/.docker/config.json ; - echo "$CI_DOCKER_AUTH" > ~/.docker/config.json ;
- docker push "${public_docker_image}:${CI_BUILD_REF_NAME}" - docker push "${public_docker_image}:${CI_BUILD_REF_NAME}"
## Publish to github... ## Publish to github...
publish:github: publish:github:
image: ocaml/opam image: tezos/opam
stage: publish stage: publish
only: only:
- master@tezos/tezos - master@tezos/tezos
@ -179,7 +199,7 @@ publish:github:
## Relaunching the bootstrap servers of the alphanet.zeronet ## Relaunching the bootstrap servers of the alphanet.zeronet
.bootstrap_template: &bootstrap_definition .bootstrap_template: &bootstrap_definition
image: ocaml/opam image: tezos/opam
stage: deploy stage: deploy
only: only:
- alphanet@tezos/tezos - 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 FROM $base_image
COPY src /home/opam/tezos/src COPY src /home/opam/tezos/src
COPY test /home/opam/tezos/test
RUN sudo chown -R opam /home/opam/tezos && \ RUN sudo chown -R opam /home/opam/tezos && \
echo "PRODUCTION=yes" > /home/opam/tezos/src/Makefile.local && \ echo "PRODUCTION=yes" > /home/opam/tezos/src/Makefile.local && \
opam config exec -- make -C tezos/src -j4 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/test -j4 build 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 scripts/install_build_deps.sh scripts/version.sh scripts/
COPY src/tezos-deps.opam src/ COPY src/tezos-deps.opam src/
COPY Dockerfile Dockerfile RUN sudo apk update && \
RUN sudo apk add libsodium-dev snappy-dev && \ opam config exec -- ./scripts/install_build_deps.sh all && \
sudo apk add leveldb-dev \ sudo rm -f /var/cache/apk/* && \
--update-cache \ rm -fr ~/.opam/log/ && \
--repository http://nl.alpinelinux.org/alpine/edge/testing && \ rm -fr "$(opam config exec -- ocamlfind query stdlib)"/topdirs.cmi
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

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