-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
77450cb
commit c50bce0
Showing
3 changed files
with
117 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,53 +7,48 @@ ARG SUBSTRATE_CLI_GIT_COMMIT_HASH | |
# Incremental compilation here isn't helpful | ||
ENV CARGO_INCREMENTAL=0 | ||
|
||
WORKDIR /subcoin | ||
WORKDIR /src | ||
|
||
RUN \ | ||
apt-get update && \ | ||
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ | ||
ca-certificates \ | ||
protobuf-compiler \ | ||
clang \ | ||
cmake \ | ||
curl \ | ||
git \ | ||
llvm \ | ||
clang \ | ||
cmake \ | ||
protobuf-compiler \ | ||
make && \ | ||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y | ||
|
||
# Copy the source code | ||
COPY . . | ||
|
||
RUN /root/.cargo/bin/cargo build --locked --profile=$PROFILE | ||
# Compile the binary and move it to /subcoin. | ||
RUN /root/.cargo/bin/cargo build \ | ||
--locked \ | ||
--bin subcoin \ | ||
--profile=$PROFILE \ | ||
--target $(uname -p)-unknown-linux-gnu && \ | ||
mv target/*/*/subcoin /subcoin && \ | ||
rm -rf target | ||
|
||
# This is the 2nd stage: a very small image where we copy the binary. | ||
FROM docker.io/library/ubuntu:22.04 | ||
LABEL description="Multistage Docker image for Subcoin Node" \ | ||
image.type="builder" \ | ||
image.authors="[email protected]" \ | ||
image.vendor="Subcoin Contributors" \ | ||
image.description="Multistage Docker image for Subnode Node" \ | ||
image.source="https://github.com/subcoin-project/subcoin" \ | ||
image.documentation="https://subcoin-project.github.io/subcoin" | ||
FROM ubuntu:22.04 | ||
|
||
ARG PROFILE=production | ||
LABEL org.opencontainers.image.source="https://github.com/subcoin-project/subcoin" | ||
LABEL org.opencontainers.image.description="Multistage Docker image for Subcoin Node" \ | ||
|
||
# Copy the node binary. | ||
COPY --from=builder /subcoin/target/$PROFILE/subcoin /usr/local/bin | ||
COPY --from=builder /subcoin /subcoin | ||
|
||
RUN mkdir /node-data && chown nobody:nogroup /node-data | ||
|
||
RUN useradd -m -u 1000 -U -s /bin/sh -d /node-dev node-dev && \ | ||
mkdir -p /chain-data /node-dev/.local/share && \ | ||
chown -R node-dev:node-dev /chain-data && \ | ||
ln -s /chain-data /node-dev/.local/share/subcoin && \ | ||
# unclutter and minimize the attack surface | ||
rm -rf /usr/bin /usr/sbin && \ | ||
# check if executable works in this container | ||
/usr/local/bin/subcoin --help | ||
VOLUME ["/node-data"] | ||
|
||
USER node-dev | ||
USER nobody:nogroup | ||
|
||
EXPOSE 30333 9933 9944 9615 | ||
VOLUME ["/chain-data"] | ||
|
||
ENTRYPOINT ["/usr/local/bin/subcoin"] | ||
ENTRYPOINT ["/subcoin"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# This is a base image to build Subcoin node | ||
FROM ubuntu:22.04 AS builder | ||
|
||
ARG PROFILE=production | ||
ARG SUBSTRATE_CLI_GIT_COMMIT_HASH | ||
|
||
# Incremental compilation here isn't helpful | ||
ENV CARGO_INCREMENTAL=0 | ||
|
||
WORKDIR /src | ||
|
||
RUN \ | ||
apt-get update && \ | ||
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ | ||
ca-certificates \ | ||
clang \ | ||
cmake \ | ||
curl \ | ||
git \ | ||
llvm \ | ||
protobuf-compiler \ | ||
make && \ | ||
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y | ||
|
||
# Create a cache stage for dependencies | ||
FROM builder AS cache | ||
|
||
COPY Cargo.toml Cargo.lock ./ | ||
RUN mkdir src && echo "fn main() {}" > src/main.rs | ||
RUN /root/.cargo/bin/cargo build --release | ||
|
||
# Use the cache stage to build the actual binary | ||
FROM builder AS build | ||
|
||
# Copy the source code | ||
COPY . . | ||
|
||
# Copy the cached dependencies | ||
COPY --from=cache /src/target /src/target | ||
COPY --from=cache /root/.cargo /root/.cargo | ||
|
||
ENV RUSTFLAGS="-C linker=aarch64-linux-gnu-gcc" | ||
ENV PKG_CONFIG_ALLOW_CROSS=true | ||
|
||
# Dependencies necessary for successful cross-compilation | ||
RUN \ | ||
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \ | ||
g++-aarch64-linux-gnu \ | ||
gcc-aarch64-linux-gnu \ | ||
libc6-dev-arm64-cross | ||
|
||
RUN /root/.cargo/bin/rustup target add aarch64-unknown-linux-gnu | ||
|
||
# Compile the binary and move it to /subcoin. | ||
RUN /root/.cargo/bin/cargo build \ | ||
--locked \ | ||
--bin subcoin \ | ||
--profile=$PROFILE \ | ||
--target aarch64-unknown-linux-gnu && \ | ||
mv target/*/*/subcoin /subcoin && \ | ||
rm -rf target | ||
|
||
# This is the 2nd stage: a very small image where we copy the binary. | ||
FROM arm64v8/ubuntu:22.04 | ||
|
||
LABEL org.opencontainers.image.source="https://github.com/subcoin-project/subcoin" | ||
LABEL org.opencontainers.image.description="Multistage Docker image for Subcoin Node" | ||
|
||
# Copy the node binary. | ||
COPY --from=builder /subcoin /subcoin | ||
|
||
RUN mkdir /node-data && chown nobody:nogroup /node-data | ||
|
||
VOLUME ["/node-data"] | ||
|
||
USER nobody:nogroup | ||
|
||
EXPOSE 30333 9933 9944 9615 | ||
|
||
ENTRYPOINT ["/subcoin"] |