Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor Dockerfile for builds and enhance init.sh script #267

Merged
merged 2 commits into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 29 additions & 21 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,33 +1,41 @@
FROM dappforce/cargo-chef:latest AS chef
FROM phusion/baseimage:jammy-1.0.1 AS builder

ENV DEBIAN_FRONTEND=noninteractive

WORKDIR /subsocial

FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
COPY . /subsocial

RUN apt-get update && \
apt-get upgrade -y -o Dpkg::Options::="--force-confold"

SHELL ["/bin/bash", "-o", "pipefail", "-c"]
RUN ./scripts/init.sh nosudo

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

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

# Build application
COPY . .
RUN cargo build --release
FROM phusion/baseimage:jammy-1.0.1

RUN mv /usr/share/ca* /tmp && \
rm -rf /usr/share/* && \
mv /tmp/ca-certificates /usr/share/ && \
useradd -m -u 1000 -U -s /bin/sh -d /subsocial subsocial

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

RUN useradd -m -u 1000 -U -s /bin/sh -d /subsocial subsocial && \
apt update && apt install curl -y && \
mkdir -p /subsocial/.local/share && \
mkdir /data && \
chown -R subsocial:subsocial /data && \
chown -R subsocial:subsocial /bin && \
ln -s /data /subsocial/.local/share/subsocial-collator
# checks
RUN ldd /usr/local/bin/subsocial-collator && \
/usr/local/bin/subsocial-collator --version

# Shrinking
RUN rm -rf /usr/lib/python* && rm -rf /usr/share/man

USER subsocial
EXPOSE 40333 8833 8844
RUN mkdir -p /data

VOLUME ["/data"]

ENTRYPOINT ["/usr/local/bin/subsocial-collator"]
ENTRYPOINT ["/usr/local/bin/subsocial-collator"]
15 changes: 15 additions & 0 deletions scripts/init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ set -e

echo "*** Initializing WASM build environment"

if [ "$1" == "nosudo" ]; then
apt-get update && \
apt-get install -y build-essential clang curl libssl-dev protobuf-compiler
else
sudo apt-get update && \
sudo apt-get install -y build-essential clang curl libssl-dev protobuf-compiler
fi

type rustup >/dev/null 2>&1 || {
echo >&2 "rustup is required, but it's not installed. Installing.";
curl https://sh.rustup.rs -sSf | sh -s -- -y && \
. "$HOME/.cargo/env" && \
rustup show;
}

CDIR=`dirname "$0"`
export RUSTC_VERSION=`cat $CDIR/../RUSTC_VERSION`

Expand Down
Loading