Skip to content

Commit

Permalink
Backport: building images from locally built binaries (paritytech#2513)
Browse files Browse the repository at this point in the history
* local.Dockerfile for building images from locally built binaries (paritytech#2154)

* local.Dockerfile for building images from locally built binaries

* fix doc

* moved compatibility comment

* 1000 -> 1001

* use host Ubuntu version to build images with prebuilt binaries (paritytech#2232)

* build-containers.sh - backport simplification

---------

Co-authored-by: Svyatoslav Nikolsky <svyatonik@gmail.com>
  • Loading branch information
serban300 and svyatonik authored Aug 31, 2023
1 parent 5fdbaf4 commit d65db28
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 4 deletions.
50 changes: 50 additions & 0 deletions local.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Builds images used by the bridge using locally built binaries.
#
# In particular, it can be used to build Substrate nodes and bridge relayers. The binary that gets
# built can be specified with the `PROJECT` build-arg. For example, to build the `substrate-relay`
# you would do the following:
#
# `docker build . -f local.Dockerfile -t local/substrate-relay --build-arg=PROJECT=substrate-relay`
#
# See the `deployments/README.md` for all the available `PROJECT` values.
#
# You may use `scripts/build-containers.sh` to build all binaries and images at once.

# This image needs to be binary compatible with the host machine (where images are built).
ARG UBUNTU_RELEASE=20.04
FROM docker.io/library/ubuntu:${UBUNTU_RELEASE} as runtime

USER root
WORKDIR /home/root

# show backtraces
ENV RUST_BACKTRACE 1
ENV DEBIAN_FRONTEND=noninteractive

RUN set -eux; \
apt-get update && \
apt-get install -y --no-install-recommends \
curl ca-certificates libssl-dev && \
update-ca-certificates && \
groupadd -g 1001 user && \
useradd -u 1001 -g user -s /bin/sh -m user && \
# apt clean up
apt-get autoremove -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# switch to non-root user
USER user

WORKDIR /home/user

ARG PROFILE=release
ARG PROJECT=substrate-relay

COPY --chown=user:user ./target/${PROFILE}/${PROJECT} ./

# check if executable works in this container
RUN ./${PROJECT} --version

ENV PROJECT=$PROJECT
ENTRYPOINT ["/bin/sh"]
6 changes: 6 additions & 0 deletions local.Dockerfile.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# This file only works for `local.Dockerfile` when docker buildkit is used (see ./scripts/build-containers.sh for details)
*
!target/release/millau-bridge-node
!target/release/rialto-bridge-node
!target/release/rialto-parachain-collator
!target/release/substrate-relay
31 changes: 27 additions & 4 deletions scripts/build-containers.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,30 @@
#!/bin/sh
set -eux

time docker build . -t local/substrate-relay --build-arg=PROJECT=substrate-relay
time docker build . -t local/rialto-bridge-node --build-arg=PROJECT=rialto-bridge-node
time docker build . -t local/millau-bridge-node --build-arg=PROJECT=millau-bridge-node
time docker build . -t local/rialto-parachain-collator --build-arg=PROJECT=rialto-parachain-collator
if [ -z "${LOCAL:-}" ]; then
time docker build . -t local/substrate-relay --build-arg=PROJECT=substrate-relay
time docker build . -t local/rialto-bridge-node --build-arg=PROJECT=rialto-bridge-node
time docker build . -t local/millau-bridge-node --build-arg=PROJECT=millau-bridge-node
time docker build . -t local/rialto-parachain-collator --build-arg=PROJECT=rialto-parachain-collator
else
if [ -z "${SKIP_BUILD:-}" ]; then
time cargo build -p substrate-relay -p rialto-bridge-node -p millau-bridge-node -p rialto-parachain-collator --release
fi

# (try to) use docker image matching the host os
export UBUNTU_RELEASE=`lsb_release -r -s`

# following (using DOCKER_BUILDKIT) requires docker 19.03 or above
DOCKER_BUILDKIT=1 time docker build . -f local.Dockerfile -t local/substrate-relay \
--build-arg=PROJECT=substrate-relay \
--build-arg=UBUNTU_RELEASE=${UBUNTU_RELEASE}
DOCKER_BUILDKIT=1 time docker build . -f local.Dockerfile -t local/rialto-bridge-node \
--build-arg=PROJECT=rialto-bridge-node \
--build-arg=UBUNTU_RELEASE=${UBUNTU_RELEASE}
DOCKER_BUILDKIT=1 time docker build . -f local.Dockerfile -t local/millau-bridge-node \
--build-arg=PROJECT=millau-bridge-node \
--build-arg=UBUNTU_RELEASE=${UBUNTU_RELEASE}
DOCKER_BUILDKIT=1 time docker build . -f local.Dockerfile -t local/rialto-parachain-collator \
--build-arg=PROJECT=rialto-parachain-collator \
--build-arg=UBUNTU_RELEASE=${UBUNTU_RELEASE}
fi

0 comments on commit d65db28

Please sign in to comment.