Skip to content

Commit 5cfb5fd

Browse files
committed
ci: add container build workflow
Add prebuilt build images and a publish workflow to speed CI by reusing heavy dependencies.
1 parent 30969dc commit 5cfb5fd

File tree

9 files changed

+182
-0
lines changed

9 files changed

+182
-0
lines changed

.github/workflows/containers.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: containers
2+
3+
on:
4+
push:
5+
branches:
6+
- dev
7+
paths:
8+
- packages/containers/**
9+
- .github/workflows/containers.yml
10+
workflow_dispatch:
11+
12+
permissions:
13+
contents: read
14+
packages: write
15+
16+
jobs:
17+
build:
18+
runs-on: blacksmith-4vcpu-ubuntu-2404
19+
env:
20+
REGISTRY: ghcr.io/${{ github.repository_owner }}
21+
TAG: "24.04"
22+
steps:
23+
- uses: actions/checkout@v4
24+
25+
- uses: ./.github/actions/setup-bun
26+
27+
- name: Login to GHCR
28+
uses: docker/login-action@v3
29+
with:
30+
registry: ghcr.io
31+
username: ${{ github.repository_owner }}
32+
password: ${{ secrets.GITHUB_TOKEN }}
33+
34+
- name: Build and push containers
35+
run: bun ./packages/containers/script/build.ts --push
36+
env:
37+
REGISTRY: ${{ env.REGISTRY }}
38+
TAG: ${{ env.TAG }}

packages/containers/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# CI containers
2+
3+
Prebuilt images intended to speed up GitHub Actions jobs by baking in
4+
large, slow-to-install dependencies. These are designed for Linux jobs
5+
that can use `job.container` in workflows.
6+
7+
Images
8+
9+
- `base`: Ubuntu 24.04 with common build tools and utilities
10+
- `bun-node`: `base` plus Bun and Node.js 24
11+
- `rust`: `bun-node` plus Rust (stable, minimal profile)
12+
- `tauri-linux`: `rust` plus Tauri Linux build dependencies
13+
- `publish`: `bun-node` plus Docker CLI and AUR tooling
14+
15+
Build
16+
17+
```
18+
REGISTRY=ghcr.io/anomalyco TAG=24.04 bun ./packages/containers/script/build.ts
19+
```
20+
21+
Workflow usage
22+
23+
```
24+
jobs:
25+
build-cli:
26+
runs-on: ubuntu-latest
27+
container:
28+
image: ghcr.io/anomalyco/build/bun-node:24.04
29+
```
30+
31+
Notes
32+
33+
- These images only help Linux jobs. macOS and Windows jobs cannot run
34+
inside Linux containers.
35+
- If a job uses Docker Buildx, the container needs access to the host
36+
Docker daemon (or `docker-in-docker` with privileged mode).
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM ubuntu:24.04
2+
3+
ARG DEBIAN_FRONTEND=noninteractive
4+
5+
RUN apt-get update \
6+
&& apt-get install -y --no-install-recommends \
7+
build-essential \
8+
ca-certificates \
9+
curl \
10+
git \
11+
jq \
12+
openssh-client \
13+
pkg-config \
14+
python3 \
15+
unzip \
16+
xz-utils \
17+
zip \
18+
&& rm -rf /var/lib/apt/lists/*
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
ARG REGISTRY=ghcr.io/anomalyco
2+
FROM ${REGISTRY}/build/base:24.04
3+
4+
ARG NODE_VERSION=24.4.0
5+
ARG BUN_VERSION=1.2.4
6+
7+
ENV BUN_INSTALL=/opt/bun
8+
ENV PATH=/opt/bun/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
9+
10+
RUN set -euo pipefail; \
11+
arch=$(uname -m); \
12+
node_arch=x64; \
13+
if [ "$arch" = "aarch64" ]; then node_arch=arm64; fi; \
14+
curl -fsSL "https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-${node_arch}.tar.xz" \
15+
| tar -xJf - -C /usr/local --strip-components=1; \
16+
corepack enable
17+
18+
RUN set -euo pipefail; \
19+
curl -fsSL https://bun.sh/install | bash -s -- "bun-v${BUN_VERSION}"; \
20+
bun --version; \
21+
node --version; \
22+
npm --version
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
ARG REGISTRY=ghcr.io/anomalyco
2+
FROM ${REGISTRY}/build/bun-node:24.04
3+
4+
ARG DEBIAN_FRONTEND=noninteractive
5+
6+
RUN apt-get update \
7+
&& apt-get install -y --no-install-recommends \
8+
docker.io \
9+
pacman-package-manager \
10+
&& rm -rf /var/lib/apt/lists/*
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
ARG REGISTRY=ghcr.io/anomalyco
2+
FROM ${REGISTRY}/build/bun-node:24.04
3+
4+
ARG RUST_TOOLCHAIN=stable
5+
6+
ENV CARGO_HOME=/opt/cargo
7+
ENV RUSTUP_HOME=/opt/rustup
8+
ENV PATH=/opt/cargo/bin:/opt/bun/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
9+
10+
RUN set -euo pipefail; \
11+
curl -fsSL https://sh.rustup.rs | sh -s -- -y --profile minimal --default-toolchain "${RUST_TOOLCHAIN}"; \
12+
rustc --version; \
13+
cargo --version
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bun
2+
3+
import { $ } from "bun"
4+
5+
const dir = new URL("..", import.meta.url).pathname
6+
process.chdir(dir)
7+
8+
const reg = process.env.REGISTRY ?? "ghcr.io/anomalyco"
9+
const tag = process.env.TAG ?? "24.04"
10+
const push = process.argv.includes("--push") || process.env.PUSH === "1"
11+
12+
const images = ["base", "bun-node", "rust", "tauri-linux", "publish"]
13+
14+
for (const name of images) {
15+
const image = `${reg}/build/${name}:${tag}`
16+
const file = `packages/containers/${name}/Dockerfile`
17+
const arg = name === "base" ? "" : `--build-arg REGISTRY=${reg}`
18+
const cmd = `docker build -f ${file} -t ${image} ${arg} .`
19+
console.log(cmd)
20+
await $`${cmd}`
21+
22+
if (push) {
23+
await $`docker push ${image}`
24+
}
25+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
ARG REGISTRY=ghcr.io/anomalyco
2+
FROM ${REGISTRY}/build/rust:24.04
3+
4+
ARG DEBIAN_FRONTEND=noninteractive
5+
6+
RUN apt-get update \
7+
&& apt-get install -y --no-install-recommends \
8+
libappindicator3-dev \
9+
libwebkit2gtk-4.1-dev \
10+
librsvg2-dev \
11+
patchelf \
12+
&& rm -rf /var/lib/apt/lists/*

packages/containers/tsconfig.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"$schema": "https://json.schemastore.org/tsconfig",
3+
"extends": "@tsconfig/bun/tsconfig.json",
4+
"compilerOptions": {
5+
"lib": ["ESNext", "DOM", "DOM.Iterable"],
6+
"noUncheckedIndexedAccess": false
7+
}
8+
}

0 commit comments

Comments
 (0)