Skip to content

Commit 7c6d2a1

Browse files
authored
Better docker + CI (#23)
* wip * wip * wip * wip
1 parent 096c270 commit 7c6d2a1

File tree

10 files changed

+239
-61
lines changed

10 files changed

+239
-61
lines changed

.github/workflows/checks.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Build and format
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
8+
concurrency:
9+
group: ${{ github.ref }}
10+
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
11+
12+
jobs:
13+
clippy:
14+
name: Clippy
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: taiki-e/install-action@just
19+
- name: Install Protoc
20+
uses: heliaxdev/setup-protoc@v2
21+
with:
22+
version: "25.0"
23+
repo-token: ${{ secrets.GITHUB_TOKEN }}
24+
- uses: actions-rust-lang/setup-rust-toolchain@v1
25+
with:
26+
cache: true
27+
cache-workspaces: true
28+
- run: just clippy
29+
30+
format:
31+
name: Format
32+
runs-on: ubuntu-latest
33+
steps:
34+
- uses: actions/checkout@v4
35+
- uses: taiki-e/install-action@just
36+
- name: Install Protoc
37+
uses: heliaxdev/setup-protoc@v2
38+
with:
39+
version: "25.0"
40+
repo-token: ${{ secrets.GITHUB_TOKEN }}
41+
- uses: actions-rust-lang/setup-rust-toolchain@v1
42+
with:
43+
toolchain: nightly
44+
components: rustfmt
45+
cache: true
46+
cache-workspaces: true
47+
- run: just fmt
48+
49+
build:
50+
name: Build
51+
runs-on: ubuntu-latest
52+
steps:
53+
- uses: actions/checkout@v4
54+
- uses: taiki-e/install-action@just
55+
- name: Install Protoc
56+
uses: heliaxdev/setup-protoc@v2
57+
with:
58+
version: "25.0"
59+
repo-token: ${{ secrets.GITHUB_TOKEN }}
60+
- uses: actions-rust-lang/setup-rust-toolchain@v1
61+
with:
62+
cache: true
63+
cache-workspaces: true
64+
- run: just build
65+
66+
dependencies:
67+
name: Dependencies
68+
runs-on: ubuntu-latest
69+
steps:
70+
- uses: actions/checkout@v4
71+
- name: Machete
72+
uses: bnjbvr/cargo-machete@main

.github/workflows/docker.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Build docker images
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- 'v[0-9]+.[0-9]+.[0-9]+'
9+
merge_group:
10+
11+
12+
env:
13+
GIT_LFS_SKIP_SMUDGE: 1
14+
REGISTRY_URL: ghcr.io
15+
16+
17+
jobs:
18+
build-docker:
19+
runs-on: ubuntu-latest
20+
21+
permissions:
22+
contents: read
23+
packages: write
24+
attestations: write
25+
26+
strategy:
27+
fail-fast: true
28+
matrix:
29+
docker:
30+
[
31+
{ image: namada-indexer-chain, context: chain },
32+
{ image: namada-indexer-governance, context: governance },
33+
{ image: namada-indexer-pos, context: pos },
34+
{ image: namada-indexer-rewards, context: rewards },
35+
{ image: namada-indexer-seeder, context: seeder },
36+
{ image: namada-indexer-webserver, context: webserver },
37+
]
38+
39+
steps:
40+
- name: Checkout repo
41+
uses: actions/checkout@v4
42+
- name: Set up Docker Buildx
43+
uses: docker/setup-buildx-action@v3
44+
- name: Log in to the Container registry
45+
uses: docker/login-action@v3
46+
with:
47+
registry: ${{ env.REGISTRY }}
48+
username: ${{ github.actor }}
49+
password: ${{ secrets.GITHUB_TOKEN }}
50+
- name: Docker meta
51+
id: meta
52+
uses: docker/metadata-action@v4
53+
with:
54+
images: ${{ secrets.REGISTRY_URL }}/${{ matrix.docker.image }}
55+
tags: |
56+
type=schedule
57+
type=ref,event=branch
58+
type=ref,event=pr
59+
type=semver,pattern={{version}}
60+
type=semver,pattern={{major}}.{{minor}}
61+
type=semver,pattern={{major}}
62+
type=raw,value=latest
63+
- name: Build and Push
64+
id: push
65+
uses: docker/build-push-action@v5
66+
with:
67+
context: .
68+
file: ${{ matrix.docker.context }}/Dockerfile
69+
push: false # ${{ github.ref == 'refs/heads/main' }}
70+
tags: ${{ steps.meta.outputs.tags }}
71+
labels: ${{ steps.meta.outputs.labels }}
72+
cache-from: type=gha
73+
cache-to: type=gha,mode=max
74+
- name: Generate artifact attestation
75+
if: ${{ github.ref == 'refs/heads/main' }}
76+
uses: actions/attest-build-provenance@v1
77+
with:
78+
subject-name: ${{ secrets.REGISTRY_URL }}/${{ matrix.docker.image }}
79+
subject-digest: ${{ steps.push.outputs.digest }}
80+
push-to-registry: true

chain/Dockerfile

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
1-
FROM rust:1.78-bookworm AS builder
1+
FROM lukemathwalker/cargo-chef:latest-rust-1.78-bookworm AS chef
2+
WORKDIR /app
23

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

5-
COPY . /app
8+
FROM chef AS builder
9+
COPY --from=planner /app/recipe.json recipe.json
610

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

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

15+
COPY . .
1116
RUN cargo build --release --package chain
1217

13-
FROM debian:bookworm-slim
14-
15-
RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y ca-certificates libpq5
16-
18+
FROM debian:bookworm-slim AS runtime
19+
WORKDIR /app
1720
COPY --from=builder /app/target/release/chain /app/chain
18-
COPY --from=builder /app/artifacts/checksums.json /app/checksums.json
21+
1922
WORKDIR /app
2023

2124
CMD ["./chain"]

governance/Dockerfile

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1-
FROM rust:1.78-bookworm AS builder
1+
FROM lukemathwalker/cargo-chef:latest-rust-1.78-bookworm AS chef
2+
WORKDIR /app
23

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

5-
COPY . /app
8+
FROM chef AS builder
9+
COPY --from=planner /app/recipe.json recipe.json
610

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

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

15+
COPY . .
1116
RUN cargo build --release --package governance
1217

13-
FROM debian:bookworm-slim
14-
15-
RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y ca-certificates libpq5
16-
18+
FROM debian:bookworm-slim AS runtime
19+
WORKDIR /app
1720
COPY --from=builder /app/target/release/governance /app/governance
21+
1822
WORKDIR /app
1923

2024
CMD ["./governance"]

justfile

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
build:
2-
cargo build
2+
cargo build --all
33

44
check:
5-
cargo check
5+
cargo check --all
66

77
fmt:
8-
cargo +nightly fmt
8+
cargo +nightly fmt --all
99

1010
clippy:
1111
cargo clippy
1212

1313
clippy-fix:
14-
cargo clippy --fix --allow-dirty --allow-staged
14+
cargo clippy --all --fix --allow-dirty --allow-staged
1515

1616
docker-up:
17-
docker compose up
17+
docker compose up
18+
19+
clean:
20+
cargo clean

pos/Dockerfile

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1-
FROM rust:1.78-bookworm AS builder
1+
FROM lukemathwalker/cargo-chef:latest-rust-1.78-bookworm AS chef
2+
WORKDIR /app
23

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

5-
COPY . /app
8+
FROM chef AS builder
9+
COPY --from=planner /app/recipe.json recipe.json
610

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

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

15+
COPY . .
1116
RUN cargo build --release --package pos
1217

13-
FROM debian:bookworm-slim
14-
15-
RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y ca-certificates libpq5
16-
18+
FROM debian:bookworm-slim AS runtime
19+
WORKDIR /app
1720
COPY --from=builder /app/target/release/pos /app/pos
21+
1822
WORKDIR /app
1923

2024
CMD ["./pos"]

rewards/Dockerfile

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1-
FROM rust:1.78-bookworm AS builder
1+
FROM lukemathwalker/cargo-chef:latest-rust-1.78-bookworm AS chef
2+
WORKDIR /app
23

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

5-
COPY . /app
8+
FROM chef AS builder
9+
COPY --from=planner /app/recipe.json recipe.json
610

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

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

15+
COPY . .
1116
RUN cargo build --release --package rewards
1217

13-
FROM debian:bookworm-slim
14-
15-
RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y ca-certificates libpq5
16-
18+
FROM debian:bookworm-slim AS runtime
19+
WORKDIR /app
1720
COPY --from=builder /app/target/release/rewards /app/rewards
21+
1822
WORKDIR /app
1923

2024
CMD ["./rewards"]

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[toolchain]
22
channel = "1.78.0"
3-
components = ["rustc", "cargo", "rust-std", "rust-docs", "rls", "rust-src", "rust-analysis"]
3+
components = ["rustc", "cargo", "rust-std", "rust-docs", "rls", "rust-src", "rust-analysis", "clippy", "rustfmt"]
44
targets = []

seeder/Dockerfile

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
1-
FROM rust:1.78-bookworm AS builder
1+
FROM lukemathwalker/cargo-chef:latest-rust-1.78-bookworm AS chef
2+
WORKDIR /app
23

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

5-
COPY . /app
8+
FROM chef AS builder
9+
COPY --from=planner /app/recipe.json recipe.json
610

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

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

15+
COPY . .
1116
RUN cargo build --release --package seeder
1217

13-
FROM debian:bookworm-slim
14-
15-
RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y ca-certificates libpq5
16-
18+
FROM debian:bookworm-slim AS runtime
19+
WORKDIR /app
1720
COPY --from=builder /app/target/release/seeder /app/seeder
21+
1822
WORKDIR /app
1923

2024
CMD ["./seeder"]

0 commit comments

Comments
 (0)