Skip to content

Commit c94621d

Browse files
authored
Refactor Dockerfile for builds and enhance init.sh script (#267)
* Refactor Dockerfile for builds Enhance init.sh script * Fix Dockerfile
1 parent 98f0b0a commit c94621d

File tree

2 files changed

+43
-21
lines changed

2 files changed

+43
-21
lines changed

docker/Dockerfile

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,40 @@
1-
FROM dappforce/cargo-chef:latest AS chef
1+
FROM phusion/baseimage:jammy-1.0.1 AS builder
2+
3+
ENV DEBIAN_FRONTEND=noninteractive
4+
25
WORKDIR /subsocial
36

4-
FROM chef AS planner
5-
COPY . .
6-
RUN cargo chef prepare --recipe-path recipe.json
7+
COPY . /subsocial
8+
9+
RUN apt-get update && \
10+
apt-get upgrade -y -o Dpkg::Options::="--force-confold"
11+
12+
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
13+
RUN ./scripts/init.sh nosudo
714

8-
FROM chef AS builder
9-
COPY --from=planner /subsocial/recipe.json recipe.json
15+
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
16+
RUN . "$HOME/.cargo/env" && cargo build --release
1017

11-
# Build dependencies - this is the caching Docker layer!
12-
RUN cargo chef cook --release --recipe-path recipe.json
18+
# ==== SECOND STAGE ====
1319

14-
# Build application
15-
COPY . .
16-
RUN cargo build --release
20+
FROM phusion/baseimage:jammy-1.0.1
21+
22+
RUN mv /usr/share/ca* /tmp && \
23+
rm -rf /usr/share/* && \
24+
mv /tmp/ca-certificates /usr/share/ && \
25+
useradd -m -u 1000 -U -s /bin/sh -d /subsocial subsocial && \
26+
mkdir -p /data && chown -R subsocial:subsocial /data
1727

18-
FROM debian:buster-slim
1928
COPY --from=builder /subsocial/target/release/subsocial-collator /usr/local/bin
2029

21-
RUN useradd -m -u 1000 -U -s /bin/sh -d /subsocial subsocial && \
22-
apt update && apt install curl -y && \
23-
mkdir -p /subsocial/.local/share && \
24-
mkdir /data && \
25-
chown -R subsocial:subsocial /data && \
26-
chown -R subsocial:subsocial /bin && \
27-
ln -s /data /subsocial/.local/share/subsocial-collator
30+
# checks
31+
RUN ldd /usr/local/bin/subsocial-collator && \
32+
/usr/local/bin/subsocial-collator --version
33+
34+
# Shrinking
35+
RUN rm -rf /usr/lib/python* && rm -rf /usr/share/man
2836

2937
USER subsocial
30-
EXPOSE 40333 8833 8844
3138
VOLUME ["/data"]
3239

33-
ENTRYPOINT ["/usr/local/bin/subsocial-collator"]
40+
ENTRYPOINT ["/usr/local/bin/subsocial-collator"]

scripts/init.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,21 @@ set -e
44

55
echo "*** Initializing WASM build environment"
66

7+
if [ "$1" == "nosudo" ]; then
8+
apt-get update && \
9+
apt-get install -y build-essential clang curl libssl-dev protobuf-compiler
10+
else
11+
sudo apt-get update && \
12+
sudo apt-get install -y build-essential clang curl libssl-dev protobuf-compiler
13+
fi
14+
15+
type rustup >/dev/null 2>&1 || {
16+
echo >&2 "rustup is required, but it's not installed. Installing.";
17+
curl https://sh.rustup.rs -sSf | sh -s -- -y && \
18+
. "$HOME/.cargo/env" && \
19+
rustup show;
20+
}
21+
722
CDIR=`dirname "$0"`
823
export RUSTC_VERSION=`cat $CDIR/../RUSTC_VERSION`
924

0 commit comments

Comments
 (0)