Skip to content

Commit fd95b4e

Browse files
committed
Container image for AI code reviews with semcode
1 parent fe46610 commit fd95b4e

File tree

5 files changed

+165
-3
lines changed

5 files changed

+165
-3
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Build AI review image
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
workflow_dispatch:
9+
10+
env:
11+
REGISTRY: ghcr.io
12+
IMAGE_NAME: ${{ github.repository }}
13+
14+
jobs:
15+
build:
16+
runs-on:
17+
- format('codebuild-bpf-ci-{0}-{1}', github.run_id, github.run_attempt)
18+
- image:linux-5.0
19+
- instance-size:2xlarge
20+
permissions:
21+
contents: read
22+
packages: write
23+
id-token: write
24+
steps:
25+
26+
- name: Checkout repository
27+
uses: actions/checkout@v6
28+
29+
- name: Setup Docker buildx
30+
uses: docker/setup-buildx-action@v3
31+
32+
- name: Log into registry ${{ env.REGISTRY }}
33+
if: github.event_name != 'pull_request'
34+
uses: docker/login-action@v3
35+
with:
36+
registry: ${{ env.REGISTRY }}
37+
username: ${{ github.actor }}
38+
password: ${{ secrets.GITHUB_TOKEN }}
39+
40+
- name: Build and push Docker image
41+
id: build-and-push
42+
uses: docker/build-push-action@v6
43+
with:
44+
context: .
45+
file: ai-review.Dockerfile
46+
push: ${{ github.event_name != 'pull_request' }}
47+
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:ai-review

ai-review.Dockerfile

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
ARG DEBIAN_FRONTEND=noninteractive
2+
ARG RUNNER_VERSION=2.331.0
3+
4+
FROM debian:latest AS git-builder
5+
RUN apt-get update -y && apt-get install -y --no-install-recommends \
6+
ca-certificates curl sudo
7+
COPY build-git.sh /tmp/build-git.sh
8+
RUN bash /tmp/build-git.sh
9+
10+
FROM debian:latest AS semcode-builder
11+
RUN apt-get update -y && apt-get install -y --no-install-recommends \
12+
ca-certificates curl git sudo wget
13+
COPY build-semcode.sh /tmp/build-semcode.sh
14+
RUN bash /tmp/build-semcode.sh
15+
16+
FROM debian:latest as runtime
17+
18+
# Install pre-requisites for GitHub Actions Runner client app
19+
# https://github.com/actions/runner/blob/main/docs/start/envlinux.md
20+
RUN curl -Lf https://raw.githubusercontent.com/actions/runner/v${RUNNER_VERSION}/src/Misc/layoutbin/installdependencies.sh \
21+
-o /tmp/install-gha-runner-deps.sh
22+
RUN bash /tmp/install-gha-runner-deps.sh
23+
24+
RUN apt-get update -y && apt-get install -y --no-install-recommends \
25+
ca-certificates libcurl3-gnutls
26+
COPY --from=git-builder /opt/git-staging/usr/local /usr/local
27+
28+
ENV MIRRORS_PATH=/ci/mirrors
29+
COPY setup-mirror-repos.sh /tmp/setup-mirror-repos.sh
30+
RUN bash /tmp/setup-mirror-repos.sh
31+
RUN mkdir -p /libbpfci/mirrors && ln -s ${MIRRORS_PATH}/linux /libbpfci/mirrors/linux
32+
33+
COPY --from=semcode-builder /opt/semcode /usr/local/bin/semcode
34+
COPY --from=semcode-builder /opt/semcode-index /usr/local/bin/semcode-index
35+
COPY --from=semcode-builder /opt/semcode-mcp /usr/local/bin/semcode-mcp
36+
COPY --from=semcode-builder /opt/semcode-lsp /usr/local/bin/semcode-lsp
37+
38+
RUN cd ${MIRRORS_PATH}/linux && \
39+
git remote add torvalds https://github.com/torvalds/linux.git && \
40+
git fetch torvalds && \
41+
git checkout origin/bpf-next
42+
RUN cd ${MIRRORS_PATH}/linux && \
43+
semcode-index -d /ci/.semcode.db --git $(git describe --tags --abbrev=0)..HEAD
44+
RUN semcode-index -d /ci/.semcode.db --lore bpf

build-git.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
3+
set -xeuo pipefail
4+
5+
# Build git from source using official kernel.org tarballs
6+
# Usage: ./build-git.sh [version]
7+
# If version is not specified, fetches the latest release
8+
9+
GIT_VERSION=${1:-}
10+
GIT_MIRROR=${GIT_MIRROR:-https://mirrors.edge.kernel.org/pub/software/scm/git}
11+
12+
# Install build dependencies
13+
sudo apt-get update -y
14+
sudo apt-get install -y --no-install-recommends \
15+
build-essential \
16+
ca-certificates \
17+
curl \
18+
gettext \
19+
libcurl4-gnutls-dev \
20+
libexpat1-dev \
21+
libssl-dev \
22+
zlib1g-dev
23+
24+
# Determine version to install
25+
if [ -z "${GIT_VERSION}" ]; then
26+
echo "Fetching latest git version..."
27+
GIT_VERSION=$(curl -fsSL "${GIT_MIRROR}/" | \
28+
grep -oP 'git-\K[0-9]+\.[0-9]+\.[0-9]+(?=\.tar\.gz)' | \
29+
sort -V | tail -1)
30+
fi
31+
32+
echo "Building git version: ${GIT_VERSION}"
33+
34+
WORKDIR=$(mktemp -d)
35+
cd "${WORKDIR}"
36+
37+
curl -fsSL "${GIT_MIRROR}/git-${GIT_VERSION}.tar.gz" | tar xz
38+
cd "git-${GIT_VERSION}"
39+
40+
make prefix=/usr/local -j$(nproc) all
41+
sudo make prefix=/usr/local DESTDIR=/opt/git-staging install
42+
43+
cd /
44+
rm -rf "${WORKDIR}"

build-semcode.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
3+
set -xeuo pipefail
4+
5+
SEMCODE_ORIGIN=${SEMCODE_ORIGIN:-https://github.com/facebookexperimental/semcode.git}
6+
SEMCODE_REVISION=${SEMCODE_REVISION:-main}
7+
8+
sudo apt-get install -y build-essential libclang-dev protobuf-compiler libprotobuf-dev libssl-dev pkg-config
9+
10+
# Install Rust
11+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
12+
13+
cd /tmp
14+
git clone ${SEMCODE_ORIGIN} semcode
15+
cd semcode
16+
git checkout ${SEMCODE_REVISION} -b local
17+
18+
. $HOME/.cargo/env
19+
cargo build --release
20+
21+
cd target/release
22+
cp semcode /opt/semcode
23+
cp semcode-index /opt/semcode-index
24+
cp semcode-mcp /opt/semcode-mcp
25+
cp semcode-lsp /opt/semcode-lsp

setup-mirror-repos.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
set -euo pipefail
44

5-
mkdir -p /libbpfci/mirrors
6-
git clone https://github.com/kernel-patches/bpf.git /libbpfci/mirrors/linux
7-
chmod -R a+rX /libbpfci/mirrors
5+
MIRRORS_PATH=${MIRRORS_PATH:-/libbpfci/mirrors}
6+
7+
mkdir -p "$MIRRORS_PATH"
8+
git clone https://github.com/kernel-patches/bpf.git "$MIRRORS_PATH/linux"
9+
chmod -R a+rX "$MIRRORS_PATH"

0 commit comments

Comments
 (0)