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

chore: update docker build, ci #270

Merged
merged 1 commit into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
25 changes: 15 additions & 10 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
# Generated by Cargo, executables
target

# GitHub workflows/actions
.github

# Folder containing files for bundler spec tests
bundler-spec-tests

# Documentation
docs

# Dockerfile
Dockerfile
# Scripts
scripts

# Folder containing files for bundler spec tests
bundler-spec-tests
# Generated by Cargo, executables
target

# Third party dependencies
crates/contracts/thirdparty/account-abstraction/*
tests/thirdparty/bundler/*
# Other files
.gitignore
CODEOWNERS
CONTRIBUTING.md
docker-compose.yml
Dockerfile
rustfmt.toml
tomlfmt.toml
14 changes: 14 additions & 0 deletions .github/scripts/install_geth.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

set -eo pipefail

# install geth

GETH_VERSION="1.12.0-e501b3b0"

wget -c "https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-$GETH_VERSION.tar.gz"
tar -xf "geth-linux-amd64-$GETH_VERSION.tar.gz"
mv geth-linux-amd64-$GETH_VERSION/geth /usr/local/bin/
chmod a+x /usr/local/bin/geth

geth version
13 changes: 13 additions & 0 deletions .github/scripts/install_solc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

set -eo pipefail

# install solc

SOLC_VERSION="v0.8.20"

wget -c "https://github.com/ethereum/solidity/releases/download/$SOLC_VERSION/solc-static-linux"
mv solc-static-linux /usr/local/bin/solc
chmod a+x /usr/local/bin/solc

solc --version
34 changes: 15 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ jobs:
with:
components: clippy

- name: Setup Rust toolchain (nightly)
uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt

- name: Install cargo tools
run: |
curl -L https://github.com/DevinR528/cargo-sort/releases/download/v1.0.9/cargo-sort-x86_64-unknown-linux-gnu.tar.gz | tar -zxvf - -C ~/.cargo/bin/
Expand Down Expand Up @@ -62,16 +57,12 @@ jobs:
- name: Setup third-party dependencies
run: |
make setup-thirdparty

- name: Install Geth and solc
run: |
sudo add-apt-repository ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install solc
wget -c https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.12.0-e501b3b0.tar.gz
tar -xf geth-linux-amd64-1.12.0-e501b3b0.tar.gz
mv geth-linux-amd64-1.12.0-e501b3b0/geth /usr/local/bin/
chmod a+x /usr/local/bin/geth

- name: Install geth
run: .github/scripts/install_geth.sh

- name: Install solc
run: .github/scripts/install_solc.sh

- name: Build
run: |
Expand All @@ -82,10 +73,6 @@ jobs:
with:
name: silius
path: target/debug/silius

- name: Lint
run: |
make lint

- name: Test
run: |
Expand All @@ -94,6 +81,15 @@ jobs:
- name: Examples
run: |
make run-examples

- name: Setup Rust toolchain (nightly)
uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt

- name: Lint
run: |
make lint

bundler_spec_tests:
name: Run bundler spec tests
Expand Down
29 changes: 28 additions & 1 deletion .github/workflows/publish_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,37 @@ jobs:
run: |
echo "IMAGE_NAME_LC=${IMAGE_NAME,,}" >>${GITHUB_ENV}

- name: Fetch third-party dependencies
run: |
make fetch-thirdparty

- name: Setup Yarn cache - submodule "thirdparty/account-abstraction"
uses: actions/setup-node@v3
with:
node-version: '16.17'
cache: 'yarn'
cache-dependency-path: crates/contracts/thirdparty/account-abstraction

- name: Setup Yarn cache - submodule "thirdparty/bundler"
uses: actions/setup-node@v3
with:
node-version: '16.17'
cache: 'yarn'
cache-dependency-path: tests/thirdparty/bundler

- name: Setup third-party dependencies
run: |
make setup-thirdparty

- name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
uses: docker/build-push-action@v5
with:
context: .
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME_LC }}:${{ steps.tag.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
59 changes: 37 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,40 +1,55 @@
# build
FROM ubuntu:18.04 AS builder
FROM lukemathwalker/cargo-chef:latest-rust-1 AS chef
WORKDIR /app
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could build "locally" and just copy the target into the image. In this case, docker image is much smaller.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true. But I would keep the building inside Docker so someone who can't build Silius locally (due to unsupported architecture) can build it in Docker.


RUN apt-get update && apt-get -y upgrade && apt-get install -y build-essential software-properties-common ca-certificates curl gnupg git clang pkg-config libclang-dev libssl-dev
RUN add-apt-repository ppa:ethereum/ethereum && apt-get update && apt-get install -y solc
LABEL org.opencontainers.image.source=https://github.com/silius-rs/silius
LABEL org.opencontainers.image.licenses="MIT OR Apache-2.0"

# build cargo-chef plan
FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json

FROM chef AS builder
COPY --from=planner /app/recipe.json recipe.json

RUN mkdir -p /etc/apt/keyrings
RUN curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
RUN echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_16.x nodistro main" | tee /etc/apt/sources.list.d/nodesource.list
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
RUN echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
# Set the build profile to be release
ARG BUILD_PROFILE=release
ENV BUILD_PROFILE $BUILD_PROFILE

RUN apt-get update && apt-get install -y nodejs yarn
# Install system dependencies
RUN apt-get update && apt-get -y upgrade && apt-get install -y pkg-config libclang-dev libssl-dev

WORKDIR /rust
# Install solc
RUN wget -c "https://github.com/ethereum/solidity/releases/download/v0.8.20/solc-static-linux"
RUN mv solc-static-linux /usr/local/bin/solc
RUN chmod a+x /usr/local/bin/solc

RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV PATH="/root/.cargo/bin:$PATH"
# Builds dependencies
RUN cargo chef cook --profile $BUILD_PROFILE --recipe-path recipe.json

WORKDIR /silius
# Build application
COPY . .
RUN cargo build --profile $BUILD_PROFILE --locked

RUN make fetch-thirdparty
RUN make setup-thirdparty
RUN make build
# Copy application
RUN cp /app/target/$BUILD_PROFILE/silius /app/silius

# run
FROM frolvlad/alpine-glibc:alpine-3.17
# Use alpine as a runtime image
FROM frolvlad/alpine-glibc:alpine-3.17 AS runtime

# Create data folder
RUN mkdir -p /data/silius

# Install system dependencies
RUN apk add openssl1.1-compat

COPY --from=builder /silius/target/release/silius /usr/local/bin/silius
# Copy silus binary
COPY --from=builder /app/silius /usr/local/bin/silius

# Copy licenses
COPY LICENSE-* ./

# Expose ports
EXPOSE 3000 3001

ENTRYPOINT ["/usr/local/bin/silius"]

LABEL org.opencontainers.image.source=https://github.com/silius-rs/silius
Loading