Skip to content

Commit

Permalink
refactor!: docker build system
Browse files Browse the repository at this point in the history
- Removed previous docker images
- Created new docker image with all binaries
- Moved build files to build directory
  • Loading branch information
gligneul committed Sep 13, 2023
1 parent 37305d7 commit 661b794
Show file tree
Hide file tree
Showing 14 changed files with 183 additions and 375 deletions.
93 changes: 23 additions & 70 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: Build
name: Build and test

on:
pull_request:
push:
tags:
- v*
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
packages: write
id-token: write
contents: read

jobs:
test:
runs-on: ubuntu-22.04
env:
CARGO_REGISTRIES_CARTESI_INDEX: https://github.com/cartesi/crates-index
RUSTFLAGS: -D warnings -C debuginfo=0
defaults:
run:
Expand Down Expand Up @@ -69,6 +72,9 @@ jobs:
runs-on: ubuntu-22.04
needs:
- test
defaults:
run:
working-directory: build
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -78,10 +84,22 @@ jobs:
id: docker_meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository }}
images: |
name=ghcr.io/cartesi/rollups-node
name=docker.io/cartesi/rollups-node,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
tags: |
type=semver,pattern={{version}}
type=ref,event=branch
type=ref,event=pr
type=sha,format=long
- name: Login to Docker Hub
uses: docker/login-action@v2
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
Expand All @@ -90,79 +108,14 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}

- uses: depot/setup-action@v1
- name: Build docker images
- name: Build and push docker image
id: docker_build
uses: depot/bake-action@v1
with:
files: |
./docker-bake.hcl
${{ steps.docker_meta.outputs.bake-file }}
./docker-bake.platforms.hcl
targets: deps
targets: rollups-node
push: true
project: ${{ vars.DEPOT_PROJECT }}

- uses: snok/container-retention-policy@v1
with:
image-names: rollups
cut-off: one second ago UTC
timestamp-to-use: updated_at
account-type: org
org-name: ${{ github.repository_owner }}
token: ${{ secrets.GHCR_TOKEN }}

dispatcher:
needs: build_docker
uses: ./.github/workflows/docker.yml
with:
target: dispatcher
image-name: rollups-dispatcher
secrets: inherit

state_server:
needs: build_docker
uses: ./.github/workflows/docker.yml
with:
target: state-server
image-name: rollups-state-server
secrets: inherit

graphql_server:
needs: build_docker
uses: ./.github/workflows/docker.yml
with:
target: graphql-server
image-name: rollups-graphql-server
secrets: inherit

indexer:
needs: build_docker
uses: ./.github/workflows/docker.yml
with:
target: indexer
image-name: rollups-indexer
secrets: inherit

inspect_server:
needs: build_docker
uses: ./.github/workflows/docker.yml
with:
target: inspect-server
image-name: rollups-inspect-server
secrets: inherit

advance_runner:
needs: build_docker
uses: ./.github/workflows/docker.yml
with:
target: advance-runner
image-name: rollups-advance-runner
secrets: inherit

host_runner:
needs: build_docker
uses: ./.github/workflows/docker.yml
with:
target: host-runner
image-name: rollups-host-runner
secrets: inherit
8 changes: 1 addition & 7 deletions .github/workflows/clean-up-images.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,7 @@ jobs:
strategy:
matrix:
image:
- rollups-advance-runner
- rollups-dispatcher
- rollups-graphql-server
- rollups-host-runner
- rollups-indexer
- rollups-inspect-server
- rollups-state-server
- rollups-node
steps:
- uses: vlaurin/[email protected]
with:
Expand Down
68 changes: 0 additions & 68 deletions .github/workflows/docker.yml

This file was deleted.

2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Added authority claimer service to support reader mode
- Added support to `POST` *inspect state* requests
- Added `cartesi/rollups-node` docker image with all node binaries

### Removed

- Removed configurable inspect-server path prefix
- Remove on-chain code from the node repository
- Removed `advance-runner`, `dispatcher`, `graphql-server`, `host-runner`, `inspect-server`, `indexer`, and `state-server` docker images

## [1.0.2] 2023-09-12

Expand Down
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ git submodule update --init --recursive

### Building the Docker images

To build the Rollups Docker images, run the following command.

```
docker buildx bake --load
```
To more information on how to build the rollups-node docker image, see the [build directory](./build/README.md).

### Rust

Expand Down
108 changes: 108 additions & 0 deletions build/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
# (c) Cartesi and individual authors (see AUTHORS)
# SPDX-License-Identifier: Apache-2.0 (see LICENSE)

# syntax=docker.io/docker/dockerfile:1.4

ARG RUST_VERSION=1.71.0
ARG SERVER_MANAGER_VERSION=0.8.2
ARG ROLLUPS_CONTRACTS_VERSION=1.0.2

ARG BASE_PATH=/opt/cartesi
ARG RUST_BUILD_PATH=${BASE_PATH}/src/rollups-node/offchain
ARG DEPLOYMENT_PATH=${BASE_PATH}/share/deployments
ARG RUNTIME_DIR=/var/opt/cartesi

#
# On-chain deployment files
#
FROM debian:bookworm-slim as deployment

ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y curl

ARG DEPLOYMENT_PATH
WORKDIR ${DEPLOYMENT_PATH}

# Download deployment files from npm
ARG ROLLUPS_CONTRACTS_VERSION
RUN curl "https://registry.npmjs.org/@cartesi/rollups/-/rollups-${ROLLUPS_CONTRACTS_VERSION}.tgz" \
-o /tmp/rollups.tgz
RUN tar zxf /tmp/rollups.tgz -C /tmp
RUN cp /tmp/package/export/abi/* .

#
# Cargo chef
#
FROM rust:${RUST_VERSION}-bookworm AS rust-chef

RUN rustup component add rustfmt
RUN cargo install cargo-chef

# The workdir will be inherited by the following Rust images
ARG RUST_BUILD_PATH
WORKDIR ${RUST_BUILD_PATH}

#
# Cargo chef prepare stage
#
FROM rust-chef as rust-planner

COPY ./offchain/ .
RUN cargo chef prepare --recipe-path recipe.json

#
# Cargo chef cook stage
#
FROM rust-chef as rust-builder

ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends \
cmake libprotobuf-dev protobuf-compiler curl

# Build dependencies with cargo chef
COPY --from=rust-planner ${RUST_BUILD_PATH}/recipe.json .
RUN cargo chef cook --release --recipe-path recipe.json

# Build application
COPY ./offchain/ .
RUN cargo build --release

#
# Runtime
#
FROM cartesi/server-manager:${SERVER_MANAGER_VERSION} as rollups-node

USER root

ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends \
libpq5 ca-certificates curl
RUN rm -rf /var/lib/apt/lists/*

# Copy deployment files
ARG DEPLOYMENT_PATH
WORKDIR ${DEPLOYMENT_PATH}
COPY --from=deployment ${DEPLOYMENT_PATH}/*.json .

# Copy Rust binaries
ARG BASE_PATH
WORKDIR ${BASE_PATH}/bin
ARG RUST_BUILD_PATH
ARG BINARY_PREFIX=${RUST_BUILD_PATH}/target/release/cartesi-rollups
COPY --from=rust-builder ${BINARY_PREFIX}-advance-runner .
COPY --from=rust-builder ${BINARY_PREFIX}-dispatcher .
COPY --from=rust-builder ${BINARY_PREFIX}-graphql-server .
COPY --from=rust-builder ${BINARY_PREFIX}-host-runner .
COPY --from=rust-builder ${BINARY_PREFIX}-indexer .
COPY --from=rust-builder ${BINARY_PREFIX}-inspect-server .
COPY --from=rust-builder ${BINARY_PREFIX}-state-server .

# Setup runtime dir
ARG RUNTIME_DIR
RUN mkdir -p ${RUNTIME_DIR}
RUN chown cartesi:cartesi ${RUNTIME_DIR}
WORKDIR ${RUNTIME_DIR}

ENV PATH="${BASE_PATH}/bin:${PATH}"
USER cartesi
CMD ["/bin/bash"]
7 changes: 7 additions & 0 deletions build/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Docker Build Instructions

To build the Rollups Node Docker image, run the following command in the build directory.

```
docker buildx bake --load
```
18 changes: 18 additions & 0 deletions build/docker-bake.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# (c) Cartesi and individual authors (see AUTHORS)
# SPDX-License-Identifier: Apache-2.0 (see LICENSE)

target "docker-metadata-action" {}
target "docker-platforms" {}

group "default" {
targets = [
"rollups-node",
]
}

target "rollups-node" {
inherits = ["docker-metadata-action", "docker-platforms"]
dockerfile = "./build/Dockerfile"
target = "rollups-node"
context = ".."
}
Loading

0 comments on commit 661b794

Please sign in to comment.