forked from paritytech/parity-bridges-common
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathDockerfile
71 lines (55 loc) · 2.27 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Builds images used by the bridge.
#
# 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 . -t local/substrate-relay --build-arg=PROJECT=substrate-relay`
#
# See the `deployments/README.md` for all the available `PROJECT` values.
# This first stage prepares our dependencies to be built by `cargo-chef`.
FROM rust as planner
WORKDIR /parity-bridges-common
RUN cargo install cargo-chef
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
# This second stage is where the dependencies actually get built.
# The reason we split it from the first stage is so that the `COPY . .`
# step doesn't blow our cache.
FROM hcastano/bridge-deps AS cacher
WORKDIR /parity-bridges-common
RUN cargo install cargo-chef
COPY --from=planner /parity-bridges-common/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json
# In this third stage we go ahead and build the actual binary we want.
# This should be fairly quick since the dependencies are being built and
# cached in the previous stage.
FROM hcastano/bridge-deps as builder
WORKDIR /parity-bridges-common
RUN cargo install cargo-chef
COPY . /parity-bridges-common
COPY --from=cacher /parity-bridges-common/target target
COPY --from=cacher $CARGO_HOME $CARGO_HOME
ARG PROJECT=ethereum-poa-relay
RUN cargo build --release --verbose -p ${PROJECT}
RUN strip ./target/release/${PROJECT}
# In this final stage we copy over the final binary and do some checks
# to make sure that everything looks good.
FROM ubuntu:xenial as runtime
# show backtraces
ENV RUST_BACKTRACE 1
RUN set -eux; \
apt-get update && \
apt-get install -y libssl-dev curl
RUN groupadd -g 1000 user \
&& useradd -u 1000 -g user -s /bin/sh -m user
# switch to non-root user
USER user
WORKDIR /home/user
ARG PROJECT=ethereum-poa-relay
COPY --chown=user:user --from=builder /parity-bridges-common/target/release/${PROJECT} ./
COPY --chown=user:user --from=builder /parity-bridges-common/deployments/local-scripts/bridge-entrypoint.sh ./
# check if executable works in this container
RUN ./${PROJECT} --version
ENV PROJECT=$PROJECT
ENTRYPOINT ["/home/user/bridge-entrypoint.sh"]