Skip to content

Commit

Permalink
Remove slow cached compiles of rust in docker
Browse files Browse the repository at this point in the history
  • Loading branch information
dvush committed Jul 20, 2020
1 parent a1e9723 commit bc22540
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 43 deletions.
8 changes: 3 additions & 5 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
*
!target/x86_64-unknown-linux-musl/release/server
!target/x86_64-unknown-linux-musl/release/server_supervisor
!target/x86_64-unknown-linux-musl/release/plonk_step_by_step_prover
!target/x86_64-unknown-linux-musl/release/dummy_prover
!target/x86_64-unknown-linux-musl/release/dev-ticker-server
!docker/prover/prover-entry.sh
!docker/keybase-secrets/entrypoint.sh
!keys/packed
!docker/nginx/nginx.conf
!bin/
!core/
!Cargo.lock
!Cargo.toml
!contracts/build
!js/client/index.html
!js/client/dist
Expand Down
21 changes: 10 additions & 11 deletions .github/workflows/promote-stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,6 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Get env from keybase
uses: ./.github/actions/keybase-secrets
with:
repo: keybase://team/matter_labs/zk-secret
env:
KEYBASE_PAPERKEY: ${{ secrets.KEYBASE_PAPERKEY }}
KEYBASE_USERNAME: ${{ secrets.KEYBASE_USERNAME }}

- name: restore-selfhosted-runner-cache
run: tar xf ~/runner-cache.tar

- name: setup-env
run: |
echo "::set-env name=ZKSYNC_HOME::$(pwd)"
Expand All @@ -39,3 +28,13 @@ jobs:
docker login -u ${{ secrets.DOCKER_USER }} -p ${{ secrets.DOCKER_PASSWORD }}
zksync update-images
echo "::set-env name=IMAGE_TAG::$(f sh -c 'echo $IMAGE_TAG')"
- name: promote-to-gitlab
run: |
curl -X POST \
-F token=${{ secrets.GITLAB_TOKEN }} \
-F "ref=gitlab-deploy" \
-F "variables[SERVER_TAG]=$IMAGE_TAG" \
-F "variables[PROVER_TAG]=$IMAGE_TAG" \
-F "variables[EXPLORER_TAG]=$IMAGE_TAG" \
https://gitlab.com/api/v4/projects/19165314/trigger/pipeline
23 changes: 5 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,6 @@ image-keybase:
push-image-keybase: image-keybase
docker push "${KEYBASE_DOCKER_IMAGE}"

# Using RUST+Linux docker image (ekidd/rust-musl-builder) to build for Linux. More at https://github.com/emk/rust-musl-builder
docker-options = --rm -v $(shell pwd):/home/rust/src -v cargo-git:/home/rust/.cargo/git -v cargo-registry:/home/rust/.cargo/registry --env-file $(ZKSYNC_HOME)/etc/env/$(ZKSYNC_ENV).env
rust-musl-builder = @docker run $(docker-options) ekidd/rust-musl-builder


# Rust: main stuff

server:
Expand All @@ -126,19 +121,11 @@ server:
sandbox:
@cargo run --bin sandbox

# See more more at https://github.com/emk/rust-musl-builder#caching-builds
build-target: build-contracts
$(rust-musl-builder) sudo chown -R rust:rust /home/rust/src /home/rust/.cargo/git /home/rust/.cargo/registry
$(rust-musl-builder) cargo build --release

clean-target:
$(rust-musl-builder) cargo clean

image-server: build-target
@docker build -t "${SERVER_DOCKER_IMAGE}" -t "${SERVER_DOCKER_IMAGE_LATEST}" -f ./docker/server/Dockerfile .
image-server: build-contracts
@DOCKER_BUILDKIT=1 docker build -t "${SERVER_DOCKER_IMAGE}" -t "${SERVER_DOCKER_IMAGE_LATEST}" -f ./docker/server/Dockerfile .

image-prover: build-target
@docker build -t "${PROVER_DOCKER_IMAGE}" -t "${PROVER_DOCKER_IMAGE_LATEST}" -f ./docker/prover/Dockerfile .
image-prover: build-contracts
@DOCKER_BUILDKIT=1 docker build -t "${PROVER_DOCKER_IMAGE}" -t "${PROVER_DOCKER_IMAGE_LATEST}" -f ./docker/prover/Dockerfile .

image-rust: image-server image-prover

Expand Down Expand Up @@ -289,7 +276,7 @@ dev-build-geth:
dev-push-geth:
@docker push "${GETH_DOCKER_IMAGE}"

image-dev-ticker: build-target
image-dev-ticker:
@docker build -t "${DEV_TICKER_DOCKER_IMAGE}" -f ./docker/dev-ticker/Dockerfile .

push-image-dev-ticker: image-dev-ticker
Expand Down
15 changes: 13 additions & 2 deletions docker/dev-ticker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
FROM alpine
# syntax=docker/dockerfile:experimental
FROM rust:1.45 as builder
RUN --mount=type=cache,target=/usr/local/cargo/registry \
cargo install sccache
WORKDIR /usr/src/zksync
COPY . .
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/root/.cache/sccache \
RUSTC_WRAPPER=/usr/local/cargo/bin/sccache \
cargo build --release

FROM debian:buster-slim
EXPOSE 9876
ENV RUST_LOG info
COPY target/x86_64-unknown-linux-musl/release/dev-ticker-server /bin/
COPY --from=builder /usr/src/zksync/target/release/dev-ticker-server /bin/
ENTRYPOINT ["dev-ticker-server"]
19 changes: 15 additions & 4 deletions docker/prover/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
FROM alpine
# syntax=docker/dockerfile:experimental
FROM rust:1.45 as builder
RUN --mount=type=cache,target=/usr/local/cargo/registry \
cargo install sccache
WORKDIR /usr/src/zksync
COPY . .
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/root/.cache/sccache \
RUSTC_WRAPPER=/usr/local/cargo/bin/sccache \
cargo build --release

FROM debian:buster-slim
RUN apt-get update && apt-get install -y axel && rm -rf /var/lib/apt/lists/*
# Docs of env variables used for this image
# to test this locally just run
# docker build -t tmp_prover -f =(f envsubst < ./docker/prover/Dockerfile) .; docker run --rm tmp_prover:latest
Expand All @@ -19,14 +31,13 @@ FROM alpine
#ENV PROVER_CYCLE_WAIT $PROVER_CYCLE_WAIT
#ENV PROVER_GONE_TIMEOUT $PROVER_GONE_TIMEOUT
#ENV DOCKER_DUMMY_PROVER $DOCKER_DUMMY_PROVER
COPY target/x86_64-unknown-linux-musl/release/plonk_step_by_step_prover /bin/
COPY target/x86_64-unknown-linux-musl/release/dummy_prover /bin/
COPY --from=builder /usr/src/zksync/target/release/plonk_step_by_step_prover /bin/
COPY --from=builder /usr/src/zksync/target/release/dummy_prover /bin/
COPY docker/prover/prover-entry.sh /bin/
COPY bin/plonk-setup /bin/
COPY bin/verify-keys /bin/
COPY bin/utils.sh /bin/
COPY keys/packed /keys/packed
COPY contracts/build/ /contracts/build/
RUN apk add --no-cache axel curl bash

CMD ["prover-entry.sh"]
18 changes: 15 additions & 3 deletions docker/server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
FROM alpine
# syntax=docker/dockerfile:experimental
FROM rust:1.45 as builder
RUN --mount=type=cache,target=/usr/local/cargo/registry \
cargo install sccache
WORKDIR /usr/src/zksync
COPY . .
RUN --mount=type=cache,target=/usr/local/cargo/registry \
--mount=type=cache,target=/root/.cache/sccache \
RUSTC_WRAPPER=/usr/local/cargo/bin/sccache \
cargo build --release

FROM debian:buster-slim
RUN apt-get update && apt-get install -y libpq5 && rm -rf /var/lib/apt/lists/*
EXPOSE 3000
EXPOSE 3031
EXPOSE 3030
COPY target/x86_64-unknown-linux-musl/release/server /
COPY --from=builder /usr/src/zksync/target/release/server /usr/bin
COPY contracts/build/ /contracts/build/
COPY bin/kube-is-leader.sh /bin/
ENTRYPOINT ["/server"]
ENTRYPOINT ["server"]

0 comments on commit bc22540

Please sign in to comment.