-
Notifications
You must be signed in to change notification settings - Fork 181
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: dockerize iroh services (#494)
- Loading branch information
Showing
8 changed files
with
289 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
**/target* | ||
# ignore edits to dockerfiles so they don't invalidate cache | ||
# dockerfiles shouldn't be in the build image anyway | ||
**/docker/Dockerfile* |
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
################################################################################ | ||
## Builder | ||
################################################################################ | ||
FROM rust:latest AS builder | ||
|
||
RUN update-ca-certificates | ||
|
||
# install latest protocol buffer compiler. | ||
ARG TARGETPLATFORM | ||
COPY ../docker/install_protoc.sh . | ||
RUN ./install_protoc.sh | ||
|
||
# set build env vars | ||
ENV RUST_BACKTRACE=1 \ | ||
PROTOC=/usr/local/bin/protoc \ | ||
PROTOC_INCLUDE=/usr/local/include | ||
|
||
# has the side effect of updating the crates.io index & installing rust toolchain | ||
# called in a separate step for nicer caching. the command itself will fail, | ||
# b/c empty-library is not a dependency, so we override with an exit code 0 | ||
RUN cargo install empty-library; exit 0 | ||
|
||
WORKDIR /iroh | ||
|
||
COPY ../ . | ||
|
||
RUN cargo build --bin iroh-gateway --profile=docker | ||
|
||
################################################################################ | ||
## Final image | ||
################################################################################ | ||
FROM gcr.io/distroless/cc | ||
|
||
WORKDIR /iroh | ||
|
||
# Copy our build, changing owndership to distroless-provided "nonroot" user, | ||
# (65532:65532) | ||
COPY --from=builder --chown=65532:65532 /iroh/target/docker/iroh-gateway ./ | ||
|
||
# Use nonroot (unprivileged) user | ||
USER nonroot | ||
|
||
# expose the default RPC port and default gateway HTTP port | ||
EXPOSE 4400 9050 | ||
|
||
CMD ["/iroh/iroh-gateway"] |
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,52 @@ | ||
################################################################################ | ||
## Builder | ||
################################################################################ | ||
# FROM --platform=linux/amd64 rust:latest AS builder | ||
FROM rust:latest AS builder | ||
|
||
RUN update-ca-certificates | ||
|
||
# rocksDB needs libclang | ||
RUN apt-get update && \ | ||
apt-get install -y \ | ||
clang libclang-dev | ||
|
||
# install latest protocol buffer compiler. | ||
ARG TARGETPLATFORM | ||
COPY ../docker/install_protoc.sh . | ||
RUN ./install_protoc.sh | ||
|
||
# set build env vars | ||
ENV RUST_BACKTRACE=1 \ | ||
PROTOC=/usr/local/bin/protoc \ | ||
PROTOC_INCLUDE=/usr/local/include | ||
|
||
# has the side effect of updating the crates.io index & installing rust toolchain | ||
# called in a separate step for nicer caching. the command itself will fail, | ||
# b/c empty-library is not a dependency, so we override with an exit code 0 | ||
RUN cargo install empty-library; exit 0 | ||
|
||
WORKDIR /iroh | ||
|
||
COPY ../ . | ||
|
||
RUN cargo build --bin iroh-one --profile=docker | ||
|
||
################################################################################ | ||
## Final image | ||
################################################################################ | ||
FROM gcr.io/distroless/cc | ||
|
||
WORKDIR /iroh | ||
|
||
# Copy our build, changing owndership to distroless-provided "nonroot" user, | ||
# (65532:65532) | ||
COPY --from=builder --chown=65532:65532 /iroh/target/docker/iroh-one ./ | ||
|
||
# Use nonroot (unprivileged) user | ||
USER nonroot | ||
|
||
# expose gateway, p2p & all default RPC ports | ||
EXPOSE 4400 4401 4402 4403 4444 9050 | ||
|
||
CMD ["/iroh/iroh-one"] |
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,53 @@ | ||
################################################################################ | ||
## Builder | ||
################################################################################ | ||
FROM rust:latest AS builder | ||
|
||
RUN update-ca-certificates | ||
|
||
# install latest protocol buffer compiler. | ||
ARG TARGETPLATFORM | ||
COPY ../docker/install_protoc.sh . | ||
RUN ./install_protoc.sh | ||
|
||
# set build env vars | ||
ENV RUST_BACKTRACE=1 \ | ||
PROTOC=/usr/local/bin/protoc \ | ||
PROTOC_INCLUDE=/usr/local/include | ||
|
||
# has the side effect of updating the crates.io index & installing rust toolchain | ||
# called in a separate step for nicer caching. the command itself will fail, | ||
# b/c empty-library is not a dependency, so we override with an exit code 0 | ||
RUN cargo install empty-library; exit 0 | ||
|
||
WORKDIR /iroh | ||
|
||
COPY ../ . | ||
|
||
RUN cargo build --bin iroh-p2p --profile=docker | ||
|
||
################################################################################ | ||
## Final image | ||
################################################################################ | ||
FROM gcr.io/distroless/cc | ||
|
||
WORKDIR /iroh | ||
|
||
# Copy our build, changing owndership to distroless-provided "nonroot" user, | ||
# (65532:65532) | ||
COPY --from=builder --chown=65532:65532 /iroh/target/docker/iroh-p2p ./ | ||
|
||
# TODO (b5) - investigate max file descriptor limits within the container image | ||
# libp2p needs lots of FDs for open ports, and we should be maxing them out. | ||
# I have no idea if distroless honors ERL_MAX_PORTS, consider this a starting | ||
# point for experimentation | ||
# ENV ERL_MAX_PORTS=65536 | ||
|
||
# Use nonroot (unprivileged) user | ||
USER nonroot | ||
|
||
# expose the default RPC port | ||
EXPOSE 4401 4444 | ||
EXPOSE 4444/udp | ||
|
||
CMD ["/iroh/iroh-p2p"] |
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,51 @@ | ||
################################################################################ | ||
## Builder | ||
################################################################################ | ||
FROM rust:latest AS builder | ||
|
||
RUN update-ca-certificates | ||
|
||
# rocksDB needs libclang | ||
RUN apt-get update && \ | ||
apt-get install -y \ | ||
clang libclang-dev | ||
|
||
# install latest protocol buffer compiler. | ||
ARG TARGETPLATFORM | ||
COPY ../docker/install_protoc.sh . | ||
RUN ./install_protoc.sh | ||
|
||
# set build env vars | ||
ENV RUST_BACKTRACE=1 \ | ||
PROTOC=/usr/local/bin/protoc \ | ||
PROTOC_INCLUDE=/usr/local/include | ||
|
||
# has the side effect of updating the crates.io index & installing rust toolchain | ||
# called in a separate step for nicer caching. the command itself will fail, | ||
# b/c empty-library is not a dependency, so we override with an exit code 0 | ||
RUN cargo install empty-library; exit 0 | ||
|
||
WORKDIR /iroh | ||
|
||
COPY ../ . | ||
|
||
RUN cargo build --bin iroh-store --profile=docker | ||
|
||
################################################################################ | ||
## Final image | ||
################################################################################ | ||
FROM gcr.io/distroless/cc | ||
|
||
WORKDIR /iroh | ||
|
||
# Copy our build, changing owndership to distroless-provided "nonroot" user, | ||
# (65532:65532) | ||
COPY --from=builder --chown=65532:65532 /iroh/target/docker/iroh-store ./ | ||
|
||
# Use nonroot (unprivileged) user | ||
USER nonroot | ||
|
||
# expose the default RPC port | ||
EXPOSE 4402 | ||
|
||
CMD ["/iroh/iroh-store"] |
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,14 @@ | ||
# install latest protocol buffer compiler. Yes, it's really this irritating. | ||
# recent build URLs are missing "3" version prefix. version is actually "3.21.9" | ||
PROTOC_VERSION=21.9 | ||
case ${TARGETPLATFORM} in | ||
"linux/amd64") PROTOC_ZIP=protoc-21.9-linux-x86_64.zip ;; | ||
"linux/arm64") PROTOC_ZIP=protoc-21.9-linux-aarch_64.zip ;; | ||
*) exit 1 | ||
esac | ||
|
||
curl -OL https://github.com/protocolbuffers/protobuf/releases/download/v$PROTOC_VERSION/$PROTOC_ZIP | ||
unzip -o $PROTOC_ZIP -d /usr/local bin/protoc | ||
unzip -o $PROTOC_ZIP -d /usr/local 'include/*' | ||
rm -f $PROTOC_ZIP | ||
echo "installed $($PROTOC --version)" |
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