Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 34 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,37 @@ jobs:
run: deno task build
working-directory: lb

api-worker:
if: github.event_name != 'push'
runs-on: ubuntu-22.04
permissions:
contents: read
steps:
- name: Clone repository
uses: actions/checkout@v6

- name: Install Rust
uses: dsherret/rust-toolchain-file@v1

- name: Add wasm target
run: rustup target add wasm32-unknown-unknown

- uses: Swatinem/rust-cache@v2
with:
workspaces: workers-rs

- name: Format
run: cargo fmt --check
working-directory: workers-rs

- name: Lint
run: cargo clippy --target wasm32-unknown-unknown -- -D warnings
working-directory: workers-rs

- name: Build worker (wasm)
run: cargo build --target wasm32-unknown-unknown --release
working-directory: workers-rs

check:
runs-on: ubuntu-22.04
if: github.event_name != 'push'
Expand Down Expand Up @@ -163,7 +194,7 @@ jobs:
if: github.event_name == 'push'
id: check_existing
run: |
if docker manifest inspect ${{ env.API_IMAGE_ID_BASE }}:${{ github.sha }} > /dev/null 2>&1 then
if docker manifest inspect ${{ env.API_IMAGE_ID_BASE }}:${{ github.sha }} > /dev/null 2>&1; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
Expand All @@ -173,16 +204,13 @@ jobs:
if: github.event_name != 'push' || steps.check_existing.outputs.exists != 'true'
uses: docker/setup-buildx-action@v3

- name: Copy Cargo.lock
if: github.event_name != 'push' || steps.check_existing.outputs.exists != 'true'
run: cp Cargo.lock api/Cargo.lock

- name: Build and push api docker image
if: github.event_name != 'push' || steps.check_existing.outputs.exists != 'true'
uses: docker/build-push-action@v5
id: api_push
with:
context: api
context: .
file: api/Dockerfile
push: true
tags: ${{ env.API_IMAGE_ID_BASE }}:${{ github.sha }}
cache-from: type=gha,scope=docker-api
Expand Down
15 changes: 15 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[workspace]
members = ["api", "api/macros"]
members = ["api", "api/macros", "crates/jsr_types"]
resolver = "2"
2 changes: 2 additions & 0 deletions api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ lazy_static = "1.5.0"
tikv-jemallocator = { version = "0.6", features = ["profiling"] }
tikv-jemalloc-ctl = { version = "0.6", features = ["stats"] }
registry_api_macros = { path = "macros" }
jsr_types = { path = "../crates/jsr_types", features = ["sqlx"] }

[build-dependencies]
askalono = "0.5.0"
Expand All @@ -135,3 +136,4 @@ askalono = "0.5.0"
flate2 = "1"
deno_semver = "0.9.1"
pretty_assertions = "1.4.0"
jsr_types = { path = "../crates/jsr_types", features = ["sqlx", "testing"] }
49 changes: 30 additions & 19 deletions api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,45 +1,56 @@
# This Dockerfile is adapted from https://whitfin.io/blog/speeding-up-rust-docker-builds/
#
# The build context is the repository ROOT (not api/), because registry_api is a
# workspace member that depends on the workspace-local `crates/jsr_types` path
# crate. CI builds it with `context: .` and `file: api/Dockerfile`.

FROM rust:bookworm AS build

# create a new empty shell project
RUN USER=root cargo new --bin registry_api
WORKDIR /registry_api
WORKDIR /app

# copy over your manifests and build script
COPY ./Cargo.lock ./Cargo.lock
COPY ./Cargo.toml ./Cargo.toml
COPY ./build.rs ./build.rs
COPY ./license-list-data ./license-list-data
COPY ./macros/Cargo.toml ./macros/Cargo.toml
RUN mkdir -p macros/src && touch macros/src/lib.rs
# Copy the workspace + member manifests first so the dependency build caches
# independently of source changes.
COPY ./Cargo.toml ./Cargo.lock ./
COPY ./api/Cargo.toml ./api/Cargo.toml
COPY ./api/build.rs ./api/build.rs
COPY ./api/license-list-data ./api/license-list-data
COPY ./api/macros/Cargo.toml ./api/macros/Cargo.toml
COPY ./crates/jsr_types/Cargo.toml ./crates/jsr_types/Cargo.toml

# Stub sources so the dependency graph compiles and the dep build is cached.
RUN mkdir -p api/src api/macros/src crates/jsr_types/src \
&& echo 'fn main() {}' > api/src/main.rs \
&& touch api/macros/src/lib.rs crates/jsr_types/src/lib.rs

# Enable jemalloc heap profiling support at compile time.
# prof:true enables the profiler; prof_active:true keeps sampling on so heap
# dumps reflect cumulative allocations (needed to diagnose memory growth).
ENV JEMALLOC_SYS_WITH_MALLOC_CONF=prof:true,prof_active:true

# this build step will cache your dependencies
RUN cargo build --release
RUN rm src/*.rs
RUN cargo build --release -p registry_api
RUN rm -rf api/src api/macros/src crates/jsr_types/src

# copy your source tree
COPY ./src ./src
COPY ./migrations ./migrations
COPY ./macros ./macros
COPY ./.sqlx ./.sqlx
COPY ./api/src ./api/src
COPY ./api/migrations ./api/migrations
COPY ./api/macros ./api/macros
COPY ./api/.sqlx ./api/.sqlx
COPY ./crates/jsr_types/src ./crates/jsr_types/src

# build for release
RUN rm -f ./target/release/deps/registry_api* ./target/release/deps/libregistry_api*
RUN cargo build --release
RUN rm -f ./target/release/deps/registry_api* ./target/release/deps/libregistry_api* \
./target/release/deps/registry_api_macros* ./target/release/deps/libregistry_api_macros* \
./target/release/deps/jsr_types* ./target/release/deps/libjsr_types*
RUN cargo build --release -p registry_api

# our final base
FROM debian:bookworm-20250428-slim

RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/*

# copy the build artifact from the build stage
COPY --from=build /registry_api/target/release/registry_api ./registry_api
COPY --from=build /app/target/release/registry_api ./registry_api

ENV RUST_BACKTRACE=1

Expand Down
Loading
Loading