Skip to content

Commit

Permalink
split docker build
Browse files Browse the repository at this point in the history
  • Loading branch information
fbielejec committed Nov 29, 2024
1 parent 5db6243 commit 2db02f6
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 60 deletions.
12 changes: 1 addition & 11 deletions .github/workflows/_rust-crates-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,8 @@ jobs:
contract-suite
version: nightly-31dd1f77fd9156d09836486d97963cec7f555343

# TODO: tmp
# - name: Run tmate
# uses: mxschmitt/action-tmate@v2

- name: Run tests for shielder-relayer
run: make deps && cd crates/shielder-relayer && make test

# - name: Install npm deps
# run: make deps && cd crates/shielder-relayer && make test

# - name: Build relayer image
# run: crates/shielder-relayer && make build-image
run: make deps && cd crates/shielder-relayer && BUILD=client make test

- name: Run e2e tooling tests
run: |
Expand Down
11 changes: 8 additions & 3 deletions crates/shielder-relayer/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ SHELL := /bin/bash

CARGO_FILES = ../../Cargo.toml ../../Cargo.lock Cargo.toml

BUILD ?= docker
DOCKER_USER = "$(id -u):$(id -g)"
DOCKERFILE_PATH = docker/Dockerfile

RELAYER_CONTAINER_NAME = shielder-relayer
RELAYER_DOCKER_IMAGE = shielder-relayer
Expand All @@ -26,8 +26,13 @@ lint: ## Run linter
@cargo +nightly fmt --all

.PHONY: build-image
build-image: build ## Builds a Docker image with the Relayer service binary
@cd ../.. && DOCKER_BUILDKIT=1 docker build --ssh default --tag "${RELAYER_DOCKER_IMAGE}" -f "crates/shielder-relayer/$(DOCKERFILE_PATH)" .
build-image: ## Builds a Docker image with the Relayer service binary
ifeq ($(BUILD), client)
@cargo build --release
@cd ../.. && docker build --tag "${RELAYER_DOCKER_IMAGE}" -f "crates/shielder-relayer/docker/Dockerfile.docker" .
else
@cd ../.. && DOCKER_BUILDKIT=1 docker build --ssh default --tag "${RELAYER_DOCKER_IMAGE}" -f "crates/shielder-relayer/docker/Dockerfile.docker" .
endif

.PHONY: run
run: build-image stop ## Start the Relayer service in a local Docker container
Expand Down
46 changes: 0 additions & 46 deletions crates/shielder-relayer/docker/Dockerfile

This file was deleted.

15 changes: 15 additions & 0 deletions crates/shielder-relayer/docker/Dockerfile.client
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM debian:bookworm-slim

RUN apt-get update && \
apt-get install -y \
libssl-dev \
ca-certificates && \
rm -rf /tmp/* /var/{tmp,cache}/* /var/lib/{apt,dpkg}/

COPY ./target/release/shielder-relayer /usr/local/bin
RUN chmod +x /usr/local/bin/shielder-relayer

RUN useradd server
USER server

ENTRYPOINT ["shielder-relayer"]
42 changes: 42 additions & 0 deletions crates/shielder-relayer/docker/Dockerfile.docker
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# syntax=docker/dockerfile:experimental

FROM debian:bookworm-slim AS build

RUN apt-get update && \
apt-get install -y \
curl \
libssl-dev \
ca-certificates \
build-essential \
pkg-config \
openssh-client && \
rm -rf /tmp/* /var/{tmp,cache}/* /var/lib/{apt,dpkg}/

RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain none
ENV PATH="/root/.cargo/bin:${PATH}"

COPY ./crates ./zkos/crates
COPY ./Cargo.toml ./zkos/Cargo.toml
COPY ./Cargo.lock ./zkos/Cargo.lock
COPY ./rust-toolchain.toml ./zkos/rust-toolchain.toml

# download public key for github.com
RUN mkdir -p -m 0600 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts

RUN --mount=type=ssh cd zkos && cargo build --release -p shielder-relayer

FROM debian:bookworm-slim

RUN apt-get update && \
apt-get install -y \
libssl-dev \
ca-certificates && \
rm -rf /tmp/* /var/{tmp,cache}/* /var/lib/{apt,dpkg}/

COPY --from=build /zkos/target/release/shielder-relayer /usr/local/bin
RUN chmod +x /usr/local/bin/shielder-relayer

RUN useradd server
USER server

ENTRYPOINT ["shielder-relayer"]

0 comments on commit 2db02f6

Please sign in to comment.