Added Dockerfiles for building and running tezos binaries

This commit is contained in:
damian 2016-11-23 01:54:22 -08:00 committed by Grégoire Henry
parent 6efa84fa37
commit 87254788b9
6 changed files with 132 additions and 59 deletions

View File

@ -0,0 +1,20 @@
FROM alpine:3.4
# FIXME: I'm currently guessing the version of alpine that the opam image we've
# built the tezos binaries on is based on. if that becomes newer (e.g. alpine
# 3.5), the binaries built on that version of alpine could (will) depend on
# library symbols that won't be in alpine 3.4
LABEL distro_style="apk" distro="alpine" distro_long="alpine-3.4" arch="x86_64" operatingsystem="linux"
RUN apk update && \
apk upgrade && \
apk add sudo bash libsodium gmp && \
adduser -S tezos && \
echo 'tezos ALL=(ALL:ALL) NOPASSWD:ALL' > /etc/sudoers.d/tezos && \
chmod 440 /etc/sudoers.d/tezos && \
chown root:root /etc/sudoers.d/tezos && \
sed -i.bak 's/^Defaults.*requiretty//g' /etc/sudoers
USER tezos
ADD built-bin /usr/local/bin
WORKDIR /home/tezos

View File

@ -0,0 +1,13 @@
FROM tezos_build:$base_image
ADD tezos /home/opam/tezos
ENV HOME /home/opam
WORKDIR $HOME/tezos
RUN sudo HOME="$HOME" opam config exec -- make clean && \
sudo rm -fr ~/.opam/log && \
sudo chown -R opam /home/opam
RUN opam config exec -- make
RUN mkdir -p ~/bin && \
(cp tezos-client tezos-node tezos-protocol-compiler tezos-webclient ~/bin || true)
WORKDIR $HOME/bin

View File

@ -0,0 +1,11 @@
FROM ocaml/opam:$base_image
COPY install_build_deps.sh /tmp
COPY tezos-deps.opam /tmp/src/tezos-deps.opam
WORKDIR /tmp
RUN opam config exec -- ./install_build_deps.sh pin && rm -fr ~/.opam/log/
USER root
ENV HOME /home/opam
RUN opam config exec -- ./install_build_deps.sh depext && rm -fr ~/.opam/log/
RUN apk add libsodium-dev
USER opam
RUN opam config exec -- ./install_build_deps.sh all && rm -fr ~/.opam/log/

View File

@ -1,32 +1,23 @@
#! /bin/sh #! /bin/sh
set -x set -x
set -e
dir=$(mktemp -d) dir="$(mktemp -d)"
cur_dir="$(dirname "$(readlink -f "$0")")" src_dir="$(dirname "$(readlink -f "$0")")"
image_name=${1:=tezos_build} image_name="${1:-tezos_build}"
ocaml_version=${2:=alpine_ocaml-4.03.0} base_image="${2:-alpine_ocaml-4.03.0}"
image_version=$3 image_version="$3"
docker pull ocaml/opam:${ocaml_version} docker pull ocaml/opam:"$base_image"
cp ${cur_dir}/install_build_deps.sh ${dir} cd "$dir"
cp ${cur_dir}/../src/tezos-deps.opam ${dir}
cat > ${dir}/Dockerfile <<EOF
FROM ocaml/opam:${ocaml_version}
COPY install_build_deps.sh /tmp
COPY tezos-deps.opam /tmp/src/tezos-deps.opam
RUN cd /tmp && opam config exec -- ./install_build_deps.sh pin \
&& rm -fr ~/.opam/log/
USER root
ENV HOME /home/opam
RUN cd /tmp && opam config exec -- ./install_build_deps.sh depext \
&& rm -fr ~/.opam/log/
RUN apk add libsodium-dev
USER opam
RUN cd /tmp && opam config exec -- ./install_build_deps.sh install \
&& rm -fr ~/.opam/log/
EOF
docker build -t ${image_name}:${ocaml_version}${image_version} ${dir} cp "$src_dir"/install_build_deps.sh "$dir"
cp "$src_dir"/../src/tezos-deps.opam "$dir"
cp "$src_dir"/Dockerfile.build_deps.in "$dir"
sed Dockerfile.build_deps.in -e 's/$base_image/'"$base_image"'/g' > Dockerfile.build_deps
docker build -f Dockerfile.build_deps -t "$image_name:$base_image$image_version" "$dir"

View File

@ -0,0 +1,41 @@
#! /bin/sh
set -x
set -e
dir="$(mktemp -d)"
src_dir="$(dirname "$(readlink -f "$0")")"
image_name="${1:-tezos_build}"
base_image="${2:-alpine_ocaml-4.03.0}"
image_version="$3"
tezos_build_img="tezos_build:$base_image"
if ! (docker images | grep -- "^tezos_build \+$base_image "); then
echo "Docker image not found: $tezos_build_img" >&2
echo "Aborting" >&2
exit 1
fi
cd "$dir"
git clone "$src_dir"/.. "$dir"/tezos
rm -fr "$dir"/tezos/.git
cp "$src_dir"/Dockerfile.build_bin.in "$dir"
sed Dockerfile.build_bin.in -e 's/$base_image/'"$base_image"'/g' > Dockerfile.build_bin
docker build -f Dockerfile.build_bin -t "tezos_build_bin:$base_image$image_version" "$dir"
mkdir -p "$dir"/built-bin
docker run -i --rm -v "$dir"/built-bin:/built-bin "tezos_build_bin:$base_image$image_version" /bin/bash << EOF
sudo cp -v /home/opam/bin/tezos-* /built-bin/
sudo chown opam:nogroup /built-bin/tezos-*
sudo chmod a+rwx /built-bin/tezos-*
EOF
cp "$src_dir"/Dockerfile.binaries.in "$dir"
sed Dockerfile.binaries.in -e 's/$base_image/'"$base_image"'/g' > Dockerfile.binaries
docker build -f Dockerfile.binaries -t "tezos_binaries:$base_image$image_version" "$dir"

View File

@ -1,38 +1,35 @@
#!/bin/sh #! /bin/sh
if ! [ -f 'src/tezos-deps.opam' ]; then OCAML_VERSION=4.03.0
echo if [ "$(ocaml -vnum)" != "$OCAML_VERSION" ]; then
echo " Please run from the project's root directory. Aborting." echo ;
echo echo " Unexpected compiler version ($(ocaml -vnum))";
exit 1 echo " You should use ocaml-$OCAML_VERSION.";
fi echo ;
exit 1;
ocaml_version=4.03.0
if [ "$(ocaml -vnum)" != "$ocaml_version" ]; then
echo
echo " Unexpected compiler version ($(ocaml -vnum))"
echo " You should use ocaml-$ocaml_version."
echo
exit 1
fi fi
cmd="$1" cmd="$1"
if [ -z "$cmd" ]; then cmd=all; fi if [ -z "$cmd" ]; then cmd=all; fi
case "$cmd" in pin=false
depext=false
install=false
case $cmd in
pin) pin)
pin=yes pin=true
;; ;;
depext) depext)
depext=yes depext=true
;; ;;
install) install)
install=yes install=true
;; ;;
all) all)
pin=yes pin=true
depext=yes depext=true
install=yes install=true
;; ;;
*) *)
echo "Unknown command '$cmd'." echo "Unknown command '$cmd'."
@ -43,7 +40,7 @@ esac
set -e set -e
set -x set -x
if ! [ -z "$pin" ]; then if "$pin"; then
opam pin --yes remove --no-action --dev-repo ocplib-resto || true opam pin --yes remove --no-action --dev-repo ocplib-resto || true
opam pin --yes add --no-action --dev-repo sodium opam pin --yes add --no-action --dev-repo sodium
opam pin --yes add --no-action --dev-repo ocp-ocamlres opam pin --yes add --no-action --dev-repo ocp-ocamlres
@ -56,15 +53,15 @@ if ! [ -z "$pin" ]; then
opam pin --yes add --no-action tezos-deps src opam pin --yes add --no-action tezos-deps src
fi fi
if ! [ -z "$depext" ]; then if "$depext"; then
## In our CI, this rule is executed as user 'root'
## The other rules are executed as user 'opam'.
opam list --installed depext || opam install depext opam list --installed depext || opam install depext
opam depext tezos-deps opam depext $DEPEXTOPT tezos-deps
fi fi
if ! [ -z "$install" ]; then if "$install"; then
if opam list --installed tezos-deps ; then
opam upgrade $(opam list -s --required-by tezos-deps | grep -ve '^ocaml *$')
else
opam install tezos-deps opam install tezos-deps
## This seems broken in the current opam-repo (2016-12-09) fi
## opam install --build-test tezos-deps
fi fi