Skip to content

Commit

Permalink
Better docker + CI (#23)
Browse files Browse the repository at this point in the history
* wip

* wip

* wip

* wip
  • Loading branch information
Fraccaman authored May 17, 2024
1 parent 096c270 commit 7c6d2a1
Show file tree
Hide file tree
Showing 10 changed files with 239 additions and 61 deletions.
72 changes: 72 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: Build and format

on:
pull_request:
branches:
- main

concurrency:
group: ${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}

jobs:
clippy:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: taiki-e/install-action@just
- name: Install Protoc
uses: heliaxdev/setup-protoc@v2
with:
version: "25.0"
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
cache: true
cache-workspaces: true
- run: just clippy

format:
name: Format
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: taiki-e/install-action@just
- name: Install Protoc
uses: heliaxdev/setup-protoc@v2
with:
version: "25.0"
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: nightly
components: rustfmt
cache: true
cache-workspaces: true
- run: just fmt

build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: taiki-e/install-action@just
- name: Install Protoc
uses: heliaxdev/setup-protoc@v2
with:
version: "25.0"
repo-token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions-rust-lang/setup-rust-toolchain@v1
with:
cache: true
cache-workspaces: true
- run: just build

dependencies:
name: Dependencies
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Machete
uses: bnjbvr/cargo-machete@main
80 changes: 80 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Build docker images

on:
push:
branches:
- main
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'
merge_group:


env:
GIT_LFS_SKIP_SMUDGE: 1
REGISTRY_URL: ghcr.io


jobs:
build-docker:
runs-on: ubuntu-latest

permissions:
contents: read
packages: write
attestations: write

strategy:
fail-fast: true
matrix:
docker:
[
{ image: namada-indexer-chain, context: chain },
{ image: namada-indexer-governance, context: governance },
{ image: namada-indexer-pos, context: pos },
{ image: namada-indexer-rewards, context: rewards },
{ image: namada-indexer-seeder, context: seeder },
{ image: namada-indexer-webserver, context: webserver },
]

steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ secrets.REGISTRY_URL }}/${{ matrix.docker.image }}
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=raw,value=latest
- name: Build and Push
id: push
uses: docker/build-push-action@v5
with:
context: .
file: ${{ matrix.docker.context }}/Dockerfile
push: false # ${{ github.ref == 'refs/heads/main' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Generate artifact attestation
if: ${{ github.ref == 'refs/heads/main' }}
uses: actions/attest-build-provenance@v1
with:
subject-name: ${{ secrets.REGISTRY_URL }}/${{ matrix.docker.image }}
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
23 changes: 13 additions & 10 deletions chain/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
FROM rust:1.78-bookworm AS builder
FROM lukemathwalker/cargo-chef:latest-rust-1.78-bookworm AS chef
WORKDIR /app

RUN apt-get update && apt-get install -y protobuf-compiler build-essential clang-tools-14
FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json

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

WORKDIR /app
RUN apt-get update && apt-get install -y protobuf-compiler build-essential clang-tools-14

RUN DEBIAN_FRONTEND=noninteractive apt-get update
RUN cargo chef cook --release --recipe-path recipe.json

COPY . .
RUN cargo build --release --package chain

FROM debian:bookworm-slim

RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y ca-certificates libpq5

FROM debian:bookworm-slim AS runtime
WORKDIR /app
COPY --from=builder /app/target/release/chain /app/chain
COPY --from=builder /app/artifacts/checksums.json /app/checksums.json

WORKDIR /app

CMD ["./chain"]
22 changes: 13 additions & 9 deletions governance/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
FROM rust:1.78-bookworm AS builder
FROM lukemathwalker/cargo-chef:latest-rust-1.78-bookworm AS chef
WORKDIR /app

RUN apt-get update && apt-get install -y protobuf-compiler build-essential clang-tools-14
FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json

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

WORKDIR /app
RUN apt-get update && apt-get install -y protobuf-compiler build-essential clang-tools-14

RUN DEBIAN_FRONTEND=noninteractive apt-get update
RUN cargo chef cook --release --recipe-path recipe.json

COPY . .
RUN cargo build --release --package governance

FROM debian:bookworm-slim

RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y ca-certificates libpq5

FROM debian:bookworm-slim AS runtime
WORKDIR /app
COPY --from=builder /app/target/release/governance /app/governance

WORKDIR /app

CMD ["./governance"]
13 changes: 8 additions & 5 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
build:
cargo build
cargo build --all

check:
cargo check
cargo check --all

fmt:
cargo +nightly fmt
cargo +nightly fmt --all

clippy:
cargo clippy

clippy-fix:
cargo clippy --fix --allow-dirty --allow-staged
cargo clippy --all --fix --allow-dirty --allow-staged

docker-up:
docker compose up
docker compose up

clean:
cargo clean
22 changes: 13 additions & 9 deletions pos/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
FROM rust:1.78-bookworm AS builder
FROM lukemathwalker/cargo-chef:latest-rust-1.78-bookworm AS chef
WORKDIR /app

RUN apt-get update && apt-get install -y protobuf-compiler build-essential clang-tools-14
FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json

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

WORKDIR /app
RUN apt-get update && apt-get install -y protobuf-compiler build-essential clang-tools-14

RUN DEBIAN_FRONTEND=noninteractive apt-get update
RUN cargo chef cook --release --recipe-path recipe.json

COPY . .
RUN cargo build --release --package pos

FROM debian:bookworm-slim

RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y ca-certificates libpq5

FROM debian:bookworm-slim AS runtime
WORKDIR /app
COPY --from=builder /app/target/release/pos /app/pos

WORKDIR /app

CMD ["./pos"]
22 changes: 13 additions & 9 deletions rewards/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
FROM rust:1.78-bookworm AS builder
FROM lukemathwalker/cargo-chef:latest-rust-1.78-bookworm AS chef
WORKDIR /app

RUN apt-get update && apt-get install -y protobuf-compiler build-essential clang-tools-14
FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json

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

WORKDIR /app
RUN apt-get update && apt-get install -y protobuf-compiler build-essential clang-tools-14

RUN DEBIAN_FRONTEND=noninteractive apt-get update
RUN cargo chef cook --release --recipe-path recipe.json

COPY . .
RUN cargo build --release --package rewards

FROM debian:bookworm-slim

RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y ca-certificates libpq5

FROM debian:bookworm-slim AS runtime
WORKDIR /app
COPY --from=builder /app/target/release/rewards /app/rewards

WORKDIR /app

CMD ["./rewards"]
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[toolchain]
channel = "1.78.0"
components = ["rustc", "cargo", "rust-std", "rust-docs", "rls", "rust-src", "rust-analysis"]
components = ["rustc", "cargo", "rust-std", "rust-docs", "rls", "rust-src", "rust-analysis", "clippy", "rustfmt"]
targets = []
22 changes: 13 additions & 9 deletions seeder/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
FROM rust:1.78-bookworm AS builder
FROM lukemathwalker/cargo-chef:latest-rust-1.78-bookworm AS chef
WORKDIR /app

RUN apt-get update && apt-get install -y protobuf-compiler build-essential clang-tools-14
FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json

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

WORKDIR /app
RUN apt-get update && apt-get install -y protobuf-compiler build-essential clang-tools-14

RUN DEBIAN_FRONTEND=noninteractive apt-get update
RUN cargo chef cook --release --recipe-path recipe.json

COPY . .
RUN cargo build --release --package seeder

FROM debian:bookworm-slim

RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y ca-certificates libpq5

FROM debian:bookworm-slim AS runtime
WORKDIR /app
COPY --from=builder /app/target/release/seeder /app/seeder

WORKDIR /app

CMD ["./seeder"]
Loading

0 comments on commit 7c6d2a1

Please sign in to comment.