Skip to content
This repository has been archived by the owner on Aug 24, 2023. It is now read-only.

Commit

Permalink
chore(dockerfile): multi-stage meta-node docker build (#163)
Browse files Browse the repository at this point in the history
<!--  Thanks for sending a pull request! -->

#### What this PR does / why we need it:

> Experimental

As per the title. This PR adds multi-stage Docker build for
`./meta-node`. All docker images now utilize Docker to build.

Fixes #61

Signed-off-by: Fuxing Loh <[email protected]>
Co-authored-by: Diehard073055 <[email protected]>
  • Loading branch information
fuxingloh and DieHard073055 authored Nov 23, 2022
1 parent a12ecd6 commit 419304b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 49 deletions.
42 changes: 3 additions & 39 deletions .github/workflows/release-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,6 @@ jobs:
- name: Checkout
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0

- name: Cache
uses: actions/cache@9b0c1fce7a93df8e3bb8926b0d6e9d89e92f20a7 # v3.0.11
with:
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Set up rust toolchain
uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af # v1.0.7
with:
profile: minimal
toolchain: nightly-2022-09-22
target: wasm32-unknown-unknown
default: true
override: true
components: rustfmt, clippy

- name: Cargo build
uses: actions-rs/cargo@844f36862e911db73fe0815f00a4a2602c279505 # v1.0.3
with:
command: build
args: --release --all

- name: Save binary
run: |
mkdir -p build
cp target/release/meta-node build/
- name: Set up QEMU
uses: docker/setup-qemu-action@e81a89b1732b9c48d79cd809d8d81d79c4647a18 # v2.1.0

Expand All @@ -80,21 +48,17 @@ jobs:
}
return `${prefix}:latest,${prefix}:${semver.replace('v','')}`
}
if (context.eventName === 'push' && context.ref === 'refs/heads/main') {
return `${prefix}:main,${prefix}:${context.sha}`
}
if (context.eventName === 'pull_request') {
return `${prefix}:${context.payload.number},${prefix}:${context.sha}`
}
result-encoding: string

- name: Support multi-platform
run: |
sed -i 's/FROM /FROM --platform=$BUILDPLATFORM /g' ./Dockerfile
- name: Build & Publish
uses: docker/build-push-action@c56af957549030174b10d6867f20e78cfd7debc5 # v3.2.0
with:
Expand All @@ -103,7 +67,7 @@ jobs:
push: true
platforms: |
linux/amd64
linux/arm64
# linux/arm64 TODO: enable after we can limit parallelization to 1
tags: ${{ steps.tags.outputs.result }}
cache-from: type=registry,ref=ghcr.io/defich/metachain:buildcache
cache-to: type=registry,ref=ghcr.io/defich/metachain:buildcache,mode=max
Expand Down
34 changes: 24 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
FROM ubuntu:22.04
FROM ubuntu:22.04 AS builder

WORKDIR /metachain
RUN apt update && apt upgrade -y
RUN apt install -y curl

# Requires copy the binary to `build` folder beforehand
COPY build/* /metachain
WORKDIR /metachain
RUN curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain none --profile minimal -y

# 30333 for p2p traffic
# 9933 for RPC call
# 9944 for Websocket
# 9615 for Prometheus (metrics)
EXPOSE 30333 9933 9944
ENV PATH=$PATH:/root/.cargo/bin
RUN apt install -y cmake clang

COPY rust-toolchain.toml Cargo.toml Cargo.lock ./
# TODO: docker layer cache, blocked by https://github.com/rust-lang/cargo/issues/2644
# RUN cargo fetch

COPY meta ./meta
ARG PROFILE=release
ENV PROFILE ${PROFILE}
RUN cargo build --$PROFILE --all

VOLUME ["/data"]

FROM ubuntu:22.04 AS runner
WORKDIR /metachain
COPY --from=builder /metachain/target/release/meta-node .

# Ports to open from https://github.com/DeFiCh/metachain/blob/d3f4a9b36eb25d7340a8b138795882cada7c60e5/packages/network/src/NetworkConfig.ts
EXPOSE 30333 9333 9944 9615 39333 19933 19944

VOLUME ["/data"]
ENTRYPOINT ["/metachain/meta-node"]

0 comments on commit 419304b

Please sign in to comment.