Skip to content

Commit 18d6e9f

Browse files
fix: reduce CI/release build times with cargo and Docker caching. Add Swatinem/rust-cache@v2 to all CI and release workflow jobs. Add Docker BuildKit GHA layer caching (cache-from/cache-to type=gha) to both docker/build-push-action steps. Replace Dockerfile stub-build trick with BuildKit --mount=type=cache for cargo registry and target directory.
1 parent 88d5672 commit 18d6e9f

File tree

11 files changed

+173
-163
lines changed

11 files changed

+173
-163
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,23 @@ jobs:
1414
- uses: dtolnay/rust-toolchain@stable
1515
with:
1616
components: clippy, rustfmt
17+
- uses: Swatinem/rust-cache@v2
1718
- run: cargo fmt --check
1819
- run: cargo clippy -- -D warnings
1920
test:
2021
runs-on: ubuntu-latest
2122
steps:
2223
- uses: actions/checkout@v4
2324
- uses: dtolnay/rust-toolchain@stable
25+
- uses: Swatinem/rust-cache@v2
2426
- run: cargo test --all
2527
build:
2628
runs-on: ubuntu-latest
2729
needs: [lint, test]
2830
steps:
2931
- uses: actions/checkout@v4
3032
- uses: dtolnay/rust-toolchain@stable
33+
- uses: Swatinem/rust-cache@v2
3134
- run: cargo build --release
3235
- uses: actions/upload-artifact@v4
3336
with:

.github/workflows/release.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ jobs:
1313
steps:
1414
- uses: actions/checkout@v4
1515
- uses: dtolnay/rust-toolchain@stable
16+
- uses: Swatinem/rust-cache@v2
1617
- run: cargo test --all
1718
- uses: docker/setup-qemu-action@v3
1819
- uses: docker/setup-buildx-action@v3
@@ -34,6 +35,8 @@ jobs:
3435
tags: |
3536
ghcr.io/kitstream/initium:${{ steps.version.outputs.VERSION }}
3637
ghcr.io/kitstream/initium:latest
38+
cache-from: type=gha,scope=docker-main
39+
cache-to: type=gha,mode=max,scope=docker-main
3740
sbom: true
3841
provenance: true
3942
- uses: docker/build-push-action@v6
@@ -47,5 +50,7 @@ jobs:
4750
tags: |
4851
ghcr.io/kitstream/initium-jyq:${{ steps.version.outputs.VERSION }}
4952
ghcr.io/kitstream/initium-jyq:latest
53+
cache-from: type=gha,scope=docker-jyq
54+
cache-to: type=gha,mode=max,scope=docker-jyq
5055
sbom: true
5156
provenance: true

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
- Added Cargo dependency caching (`Swatinem/rust-cache@v2`) to all CI and release workflow jobs for faster builds
12+
- Added Docker BuildKit layer caching (`type=gha`) to release workflow for both main and jyq image builds
13+
- Replaced Dockerfile stub-build caching layer with BuildKit `--mount=type=cache` for cargo registry and target directory, enabling cross-build cache reuse
14+
15+
### Changed
16+
- Replaced `regex` crate with manual envsubst parser in render module for smaller binary
17+
- Replaced `chrono` crate with `std::time::SystemTime` and Hinnant's civil calendar algorithm in logging module
18+
- Switched rustls from default crypto backends (aws-lc-rs + ring) to ring-only
19+
- Disabled ureq default features (gzip/brotli) to reduce dependency tree
20+
- Database drivers (sqlite, postgres, mysql) are now optional Cargo features (all enabled by default); build with `--no-default-features --features sqlite` for minimal binary
21+
1022
### Removed
1123
- Seed schema version 1 (flat `seed_sets` without phases): all seed specs now use phase-based structure
1224
- `version` field from seed spec schema: no longer required or accepted

Cargo.lock

Lines changed: 0 additions & 136 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,24 @@ license = "Apache-2.0"
99
name = "initium"
1010
path = "src/main.rs"
1111

12+
[features]
13+
default = ["sqlite", "postgres", "mysql"]
14+
sqlite = ["dep:rusqlite"]
15+
postgres = ["dep:postgres"]
16+
mysql = ["dep:mysql"]
17+
1218
[dependencies]
1319
clap = { version = "4", features = ["derive"] }
1420
serde = { version = "1", features = ["derive"] }
1521
serde_json = "1"
1622
serde_yaml = "0.9"
17-
regex = "1"
18-
chrono = { version = "0.4", default-features = false, features = ["clock"] }
1923
rand = "0.8"
20-
ureq = { version = "2", features = ["tls"] }
21-
rustls = "0.23"
24+
ureq = { version = "2", features = ["tls"], default-features = false }
25+
rustls = { version = "0.23", default-features = false, features = ["ring", "logging", "std", "tls12"] }
2226
minijinja = "2"
23-
rusqlite = { version = "0.31", features = ["bundled"] }
24-
postgres = "0.19"
25-
mysql = "25"
27+
rusqlite = { version = "0.31", features = ["bundled"], optional = true }
28+
postgres = { version = "0.19", optional = true }
29+
mysql = { version = "25", optional = true }
2630

2731
[dev-dependencies]
2832
tempfile = "3"

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ ARG VERSION=dev
33
RUN apk add --no-cache musl-dev openssl-dev openssl-libs-static perl
44
WORKDIR /src
55
COPY Cargo.toml Cargo.lock ./
6-
RUN mkdir src && echo 'fn main() {}' > src/main.rs && cargo build --release && rm -rf src
76
COPY . .
8-
RUN touch src/main.rs && \
7+
RUN --mount=type=cache,target=/usr/local/cargo/registry \
8+
--mount=type=cache,target=/src/target \
99
cargo build --release && \
1010
cp target/release/initium /initium
1111
FROM scratch

README.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ kubectl apply -f https://raw.githubusercontent.com/kitstream/initium/main/exampl
4444
| **Structured logging** | `echo` statements | JSON or text with timestamps |
4545
| **Security** | Runs as root, full shell | Non-root, no shell, read-only FS |
4646
| **Secret handling** | Easily leaked in logs | Automatic redaction |
47-
| **Multiple tools** | Install curl, netcat, psql… | Single 2MB image |
47+
| **Multiple tools** | Install curl, netcat, psql… | Single small image |
4848
| **Reproducibility** | Shell differences across distros | Single Rust binary, `FROM scratch` |
4949
| **Vulnerability surface** | Full OS + shell utils | Zero OS packages |
5050

@@ -78,6 +78,27 @@ initium wait-for \
7878
initium wait-for --target https://vault:8200/v1/sys/health --insecure-tls
7979
```
8080

81+
## Cargo Features
82+
83+
Database drivers are optional Cargo features, all enabled by default. Disable unused drivers for a smaller binary:
84+
85+
```bash
86+
# All drivers (default)
87+
cargo build --release
88+
89+
# PostgreSQL + SQLite only (no MySQL)
90+
cargo build --release --no-default-features --features postgres,sqlite
91+
92+
# SQLite only (smallest binary)
93+
cargo build --release --no-default-features --features sqlite
94+
```
95+
96+
| Feature | Default | Description |
97+
| ---------- | ------- | ------------------ |
98+
| `sqlite` || SQLite driver |
99+
| `postgres` || PostgreSQL driver |
100+
| `mysql` || MySQL/MariaDB driver |
101+
81102
## Helm Chart
82103

83104
The Helm chart makes it easy to inject Initium initContainers into your deployments.

jyq.Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ ARG VERSION=dev
33
RUN apk add --no-cache musl-dev openssl-dev openssl-libs-static perl
44
WORKDIR /src
55
COPY Cargo.toml Cargo.lock ./
6-
RUN mkdir src && echo 'fn main() {}' > src/main.rs && cargo build --release && rm -rf src
76
COPY . .
8-
RUN touch src/main.rs && \
7+
RUN --mount=type=cache,target=/usr/local/cargo/registry \
8+
--mount=type=cache,target=/src/target \
99
cargo build --release && \
1010
cp target/release/initium /initium
1111
FROM alpine:3.21

0 commit comments

Comments
 (0)