Skip to content

Commit fad97eb

Browse files
ci: integrate devcontainer into CI and setup GHCR pre-builds (#114)
## Overview This PR integrates our Dev Container into the CI/CD pipeline and sets up automated environment pre-builds. As discussed in #113, reusing the dev container environment would be great for CI. This is my first attempt at implementing this workflow. Reference: <https://github.com/devcontainers/ci> ### Changes - **Dev Container CI**: Integrated `devcontainers/ci` into the main workflow. Tests now run in a 1:1 environment compared to our local setup. - **Pre-build Workflow**: Added a workflow to build and push the devcontainer image to GHCR. This caches our heavy environment to keep CI fast. - *Note:* After merging, the **Pre-build Dev Container** workflow should be manually triggered once on `main` to populate the registry. - **Formatting & Quality**: - Added `cargo fmt --check` as a mandatory CI step to maintain code style. - Applied `cargo fmt` to to fix the existing inconsistencies. - **Automation**: Updated Dependabot to track `cargo` (with PR grouping), `github-actions`, and `docker` updates. ### How to verify 1. **CI Status**: The "Build and Test" workflow should pass (green) as the formatting issues have been fixed in this PR. 2. **Action Logs**: Check the "Run CI in Dev Container" step to see the grouped logs for Fmt, Build, Test, and Clippy. 3. **Pre-build**: Confirm the new workflow is available under the Actions tab for manual dispatch. --- ### Post-merge Configuration Once this PR is merged and the first image is pushed: 1. Go to the **Packages** section on the repository home page. 2. Open the `devcontainer` package settings. 3. Ensure **Package Visibility** is set to **Public** (required for the CI to pull the image in PRs from forks). 4. (Optional) Check the **Packages** box in the "Include in the home page" settings (as shown in the attached screenshot) to make the image visible on the main page. <img width="264" height="149" alt="image" src="https://github.com/user-attachments/assets/6e64234f-124e-4625-9f72-8b8f44ec09ba" />
1 parent 3042206 commit fad97eb

6 files changed

Lines changed: 77 additions & 15 deletions

File tree

.devcontainer/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ ARG BASE_IMAGE=mcr.microsoft.com/devcontainers/base:trixie
22

33
FROM $BASE_IMAGE
44

5+
LABEL org.opencontainers.image.source=https://github.com/coder3101/protols
6+
57
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
68
&& apt-get install -y --no-install-recommends \
79
protobuf-compiler \

.devcontainer/devcontainer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "Rust",
3+
"image": "ghcr.io/coder3101/protols/devcontainer:latest",
34
"build": {
45
"dockerfile": "Dockerfile",
56
"context": ".."

.github/dependabot.yml

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,28 @@
11
version: 2
22
updates:
3-
- package-ecosystem: "devcontainers"
4-
directory: "/"
5-
schedule:
6-
interval: weekly
3+
- package-ecosystem: "cargo"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
7+
groups:
8+
dependencies:
9+
patterns:
10+
- "*"
11+
update-types:
12+
- "minor"
13+
- "patch"
14+
15+
- package-ecosystem: "github-actions"
16+
directory: "/"
17+
schedule:
18+
interval: "weekly"
19+
20+
- package-ecosystem: "devcontainers"
21+
directory: "/"
22+
schedule:
23+
interval: weekly
24+
25+
- package-ecosystem: "docker"
26+
directory: "/.devcontainer"
27+
schedule:
28+
interval: "weekly"

.github/workflows/ci.yml

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,16 @@ jobs:
1515
runs-on: ubuntu-latest
1616

1717
steps:
18-
- uses: actions/checkout@v4
19-
- name: Build
20-
run: cargo build --verbose
21-
- name: Run tests
22-
run: cargo test --verbose
23-
- name: Run lints
24-
run: cargo clippy --all-targets -- -D warnings
18+
- uses: actions/checkout@v6
19+
- name: Run CI in Dev Container
20+
uses: devcontainers/ci@v0.3
21+
with:
22+
imageName: ghcr.io/${{ github.repository }}/devcontainer
23+
cacheFrom: ghcr.io/${{ github.repository }}/devcontainer
24+
push: never
25+
runCmd: |
26+
export CARGO_TERM_COLOR=always &&
27+
echo "::group::Check formatting" && cargo fmt --all -- --check && echo "::endgroup::" &&
28+
echo "::group::Build" && cargo build --verbose && echo "::endgroup::" &&
29+
echo "::group::Run tests" && cargo test --verbose && echo "::endgroup::" &&
30+
echo "::group::Run lints" && cargo clippy --all-targets -- -D warnings
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Pre-build Dev Container
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
paths:
7+
- '.devcontainer/**'
8+
- 'Cargo.lock'
9+
- 'Cargo.toml'
10+
- 'rust-toolchain.toml'
11+
branches: [ "main" ]
12+
13+
permissions:
14+
contents: read
15+
packages: write
16+
17+
jobs:
18+
build:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v6
23+
- name: Pre-build and push
24+
uses: devcontainers/ci@v0.3
25+
with:
26+
imageName: ghcr.io/${{ github.repository }}/devcontainer
27+
cacheFrom: ghcr.io/${{ github.repository }}/devcontainer
28+
cacheTo: ghcr.io/${{ github.repository }}/devcontainer
29+
push: filter
30+
refFilterForPush: refs/heads/main
31+
eventFilterForPush: push, workflow_dispatch

src/log.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,13 @@ impl<S: Subscriber> Layer<S> for ClientLogger {
9292
/// Handle to dynamically reload the log filter at runtime.
9393
pub type LogReloadHandle = reload::Handle<EnvFilter, Registry>;
9494

95-
/// Installs the global tracing subscriber with a reloadable filter, the LSP logger,
95+
/// Installs the global tracing subscriber with a reloadable filter, the LSP logger,
9696
/// and a file-based backup logger.
97-
///
97+
///
9898
/// Returns a tuple containing:
99-
///
99+
///
100100
/// 1. A [`self::LogReloadHandle`] to dynamically update the log level.
101-
/// 2. A [`WorkerGuard`] that must be kept alive in the main function to ensure
101+
/// 2. A [`WorkerGuard`] that must be kept alive in the main function to ensure
102102
/// non-blocking file logging continues.
103103
pub fn install(tx: mpsc::Sender<LogMessageParams>) -> (LogReloadHandle, WorkerGuard) {
104104
let filter = EnvFilter::try_from_default_env().unwrap_or_else(|_| "info".into());

0 commit comments

Comments
 (0)